Sets up the game to run in fabric.

This commit is contained in:
Markil3
2021-03-07 12:17:02 -07:00
parent 6d188f46f7
commit 70ff889711
20 changed files with 501 additions and 409 deletions

View File

@@ -1,165 +1,90 @@
buildscript {
repositories {
maven { url = 'https://files.minecraftforge.net/maven' }
jcenter()
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
}
plugins {
id 'fabric-loom' version '0.5-SNAPSHOT'
id 'maven-publish'
}
apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
repositories {
maven { url "https://maven.shedaniel.me/" }
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
archivesBaseName = project.archives_base_name
version = project.mod_version + "-" + project.minecraft_version + "-forge"
group = project.maven_group // http://maven.apache.org/guides/mini/guide-naming-conventions.html
version = project.mod_version + "-" + project.minecraft_version + "-fabric"
group = project.maven_group
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
minecraft {
// The mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD Snapshot are built nightly.
// stable_# Stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'snapshot', version: project.mappings
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
examplemod {
source sourceSets.main
}
}
}
server {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
examplemod {
source sourceSets.main
}
}
}
data {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
mods {
examplemod {
source sourceSets.main
}
}
}
}
repositories {
maven { url "https://maven.shedaniel.me/" }
maven { url "https://maven.terraformersmc.com/" }
}
// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }
dependencies {
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}"
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
compile(fg.deobf("me.shedaniel.cloth:cloth-config-forge:${project.cloth_version}"))
// You may put jars on which you depend on in ./libs or you may define them like so..
// compile "some.group:artifact:version:classifier"
// compile "some.group:artifact:version"
// Real examples
// compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
// compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
// The 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
// provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// These dependencies get remapped to your current MCP mappings
// deobf 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// For more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modApi "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}"
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
artifacts {
archives sourcesJar
tasks.withType(JavaCompile).configureEach {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
// We'll use that if it's available, but otherwise we'll use the older option.
def targetVersion = 8
if (JavaVersion.current().isJava9Compatible()) {
it.options.release = targetVersion
}
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}
// Example for how to get properties into the manifest for reading by the runtime..
jar {
manifest {
attributes([
"Specification-Title": project.archivesBaseName,
"Specification-Vendor": "Markil 3",
"Specification-Version": project.version,
"Implementation-Title": project.name,
"Implementation-Version": "${version}",
"Implementation-Vendor" :"Markil 3",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
}
}
// Example configuration to allow publishing using the maven-publish task
// This is the preferred method to reobfuscate your jar file
jar.finalizedBy('reobfJar')
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
//publish.dependsOn('reobfJar')
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
artifact jar
}
}
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
maven {
url "file:///${project.projectDir}/mcmodsrepo"
}
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}

View File

@@ -1,14 +1,15 @@
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
org.gradle.jvmargs=-Xmx1G
# Forge Properties
minecraft_version=1.16.4
mappings=20201028-1.16.3
forge_version=35.1.37
minecraft_version=1.16.2
yarn_mappings=1.16.2+build.47
loader_version=0.11.1
fabric_version=0.31.0+1.16
cloth_version=4.11.14
modmenu_version=1.16.8
# Mod Properties
mod_version = 1.0

Binary file not shown.

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip

53
gradlew vendored
View File

@@ -1,5 +1,21 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
@@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
@@ -66,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -109,10 +126,11 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
@@ -138,19 +156,19 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
@@ -159,14 +177,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

43
gradlew.bat vendored
View File

@@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -35,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@@ -45,28 +64,14 @@ echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell

9
settings.gradle Normal file
View File

@@ -0,0 +1,9 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
gradlePluginPortal()
}
}

View File

@@ -1,119 +1,37 @@
package markil3.panorama;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.MainMenuScreen;
import net.minecraft.client.renderer.RenderSkybox;
import net.minecraft.client.renderer.RenderSkyboxCube;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.EntityViewRenderEvent;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.client.event.ScreenshotEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraft.client.render.Camera;
import markil3.panorama.mixins.CameraAccessor;
@Mod.EventBusSubscriber(Dist.CLIENT)
public class EventBus
{
static int screenshotState = 0;
@SubscribeEvent
public static void onScreenshot(ScreenshotEvent event)
public static void onCamera(Camera event)
{
// event.setCanceled(true);
screenshotState = 1;
}
@SubscribeEvent
public static void onRender(TickEvent.RenderTickEvent event)
{
if (event.phase == TickEvent.Phase.START && screenshotState > 0)
if (Main.isRenderingPanorama())
{
Main.renderPanorama(Minecraft.getInstance());
screenshotState = 0;
}
}
@SubscribeEvent
public static void onRenderHand(RenderHandEvent event)
{
if (screenshotState > 0)
{
event.setCanceled(true);
}
}
@SubscribeEvent
public static void onFov(EntityViewRenderEvent.FOVModifier event)
{
if (screenshotState > 0)
{
event.setFOV(90);
}
}
@SubscribeEvent
public static void onCamera(EntityViewRenderEvent.CameraSetup event)
{
if (screenshotState > 0)
{
event.setRoll(0);
switch (screenshotState - 2)
switch (Main.getPanoramaStage() - 2)
{
default:
case 0:
event.setYaw(0F);
event.setPitch(0);
((CameraAccessor) event).setView(0, 0);
break;
case 1:
event.setYaw(90);
event.setPitch(0);
((CameraAccessor) event).setView(90, 0);
break;
case 2:
event.setYaw(180);
event.setPitch(0);
((CameraAccessor) event).setView(180, 0);
break;
case 3:
event.setYaw(270);
event.setPitch(0);
((CameraAccessor) event).setView(270, 0);
break;
case 4:
event.setYaw(0);
event.setPitch(-90);
((CameraAccessor) event).setView(0, -90);
break;
case 5:
event.setYaw(0);
event.setPitch(90);
((CameraAccessor) event).setView(0, 90);
break;
}
screenshotState++;
}
}
@SubscribeEvent
public static void onShowScreen(GuiScreenEvent.InitGuiEvent event)
{
if (event instanceof GuiScreenEvent.InitGuiEvent.Pre)
{
if (Main.numPanoramas > 0)
{
int panorama =
MathHelper.floor(Math.random() * Main.numPanoramas);
MainMenuScreen screen;
if (event.getGui() instanceof MainMenuScreen)
{
// Main.loadPanoramas(Minecraft.getInstance());
screen = (MainMenuScreen) event.getGui();
screen.panorama =
new RenderSkybox(new RenderSkyboxCube(new ResourceLocation(
"panorama:textures/gui/title/background/" + panorama + "/panorama")));
System.out.printf("Displaying panorama %d\n", panorama);
}
}
}
}
}

View File

@@ -1,48 +1,48 @@
package markil3.panorama;
import net.minecraft.client.renderer.texture.NativeImage;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.resources.data.TextureMetadataSection;
import net.minecraft.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.client.resource.metadata.TextureResourceMetadata;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.ResourceTexture;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class FileTexture extends SimpleTexture
public class FileTexture extends ResourceTexture
{
private final File file;
public FileTexture(ResourceLocation p_i1275_1_, File file)
public FileTexture(Identifier p_i1275_1_, File file)
{
super(p_i1275_1_);
this.file = file;
}
@Override
protected TextureData getTextureData(IResourceManager p_215246_1_)
protected ResourceTexture.TextureData loadTextureData(ResourceManager p_215246_1_)
{
return getTextureData(p_215246_1_, this.file);
}
public static SimpleTexture.TextureData getTextureData(IResourceManager resourceManagerIn,
public static ResourceTexture.TextureData getTextureData(ResourceManager resourceManagerIn,
File locationIn)
{
NativeImage image;
TextureMetadataSection meta;
TextureResourceMetadata meta;
try (FileInputStream stream = new FileInputStream(locationIn))
{
image =
NativeImage.read(stream);
meta = null;
return new SimpleTexture.TextureData(null,
return new ResourceTexture.TextureData(null,
image);
}
catch (IOException e)
{
return new SimpleTexture.TextureData(e);
return new ResourceTexture.TextureData(e);
}
}
}

View File

@@ -1,30 +1,23 @@
package markil3.panorama;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.client.renderer.texture.NativeImage;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.ScreenShotHelper;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.CubeMapRenderer;
import net.minecraft.client.gui.RotatingCubeMapRenderer;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.client.util.ScreenshotUtils;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.profiler.Profiler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -33,55 +26,37 @@ import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.stream.Collectors;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
// The value here should match an entry in the META-INF/mods.toml file
@Mod("panorama")
public class Main
public class Main implements ModInitializer, IdentifiableResourceReloadListener
{
// Directly reference a log4j logger.
private static final Logger LOGGER = LogManager.getLogger();
static int numPanoramas = 0;
private static int screenshotState = 0;
@Override
public void onInitialize()
{
// ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES)
// .registerReloadListener(this);
}
public Main()
{
// Register the setup method for modloading
FMLJavaModLoadingContext.get()
.getModEventBus()
.addListener(this::setup);
// Register the enqueueIMC method for modloading
FMLJavaModLoadingContext.get()
.getModEventBus()
.addListener(this::enqueueIMC);
// Register the processIMC method for modloading
FMLJavaModLoadingContext.get()
.getModEventBus()
.addListener(this::processIMC);
// Register the doClientStuff method for modloading
FMLJavaModLoadingContext.get()
.getModEventBus()
.addListener(this::doClientStuff);
FMLJavaModLoadingContext.get()
.getModEventBus()
.addListener(this::onStitch);
// Register ourselves for server and other game events we are
// interested in
MinecraftForge.EVENT_BUS.register(this);
}
public void onStitch(ModelBakeEvent event)
{
Main.loadPanoramas(Minecraft.getInstance());
}
static void loadPanoramas(Minecraft mc)
static void loadPanoramas(MinecraftClient mc,
ResourceManager manager,
Executor prepareExecutor,
Executor applyExecutor)
{
int i = 0;
int j;
TextureManager textureManager = mc.textureManager;
ResourceLocation loc;
File panoramas = new File(mc.gameDir, "panoramas");
TextureManager textureManager = mc.getTextureManager();
File panoramas = new File(mc.runDirectory, "panoramas");
if (panoramas.isDirectory())
{
for (File panorama : panoramas.listFiles())
@@ -90,12 +65,17 @@ public class Main
{
for (j = 0; j < 6; j++)
{
loc = new ResourceLocation(
"panorama:textures/gui/title/background/" + i + "/panorama_" + j + ".png");
textureManager.loadTexture(loc,
int finalI = i;
int finalJ = j;
Identifier loc = new Identifier(
"panorama:textures/gui/title" +
"/background/" + finalI +
"/panorama_" + finalJ + ".png");
textureManager.registerTexture(loc,
new FileTexture(loc,
new File(panorama,
"panorama_" + j + ".png")));
"panorama_" + finalJ +
".png")));
}
i++;
}
@@ -104,61 +84,79 @@ public class Main
numPanoramas = i;
}
private void setup(final FMLCommonSetupEvent event)
public static boolean isRenderingPanorama()
{
return screenshotState > 0;
}
private void doClientStuff(final FMLClientSetupEvent event)
public static int getPanoramaStage()
{
// loadPanoramas(event.getMinecraftSupplier().get());
return screenshotState;
}
private void enqueueIMC(final InterModEnqueueEvent event)
public static int nextStage()
{
return ++screenshotState;
}
private void processIMC(final InterModProcessEvent event)
public static void startRenderingPanorama()
{
screenshotState = 1;
}
// You can use SubscribeEvent and let the Event Bus discover methods to call
@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event)
public static void finishRenderingPanorama()
{
screenshotState = 0;
}
static void renderPanorama(Minecraft mc)
public static RotatingCubeMapRenderer getPanorama()
{
if (numPanoramas > 0)
{
int panorama =
MathHelper.floor(Math.random() * Main.numPanoramas);
return new RotatingCubeMapRenderer(new CubeMapRenderer(new Identifier(
"panorama:textures/gui/title/background/" + panorama +
"/panorama")));
}
return null;
}
public static void renderPanorama(MinecraftClient mc)
{
final SimpleDateFormat FORMATTER =
new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss");
final int SCREENSHOT_WIDTH = 2048;
final int SCREENSHOT_HEIGHT = 2048;
String name;
RenderSystem.viewport(0, 0, SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT);
if (mc.world != null)
{
name = FORMATTER.format(new Date());
// We need to render an extra frame at the beginning, or
// otherwise it won't render correctly.
for (int i = -1; i < 6; i++)
{
mc.gameRenderer.renderWorld(mc.getRenderPartialTicks(),
Util.nanoTime(), new MatrixStack());
saveScreenshot(mc, 0, i);
mc.gameRenderer.renderWorld(mc.getTickDelta(),
Util.getMeasuringTimeNano(), new MatrixStack());
saveScreenshot(mc, name, i);
nextStage();
}
finishRenderingPanorama();
}
}
static void saveScreenshot(Minecraft mc, int panoramaNum, int panoramaSide)
static void saveScreenshot(MinecraftClient mc,
String panoramaNum,
int panoramaSide)
{
final SimpleDateFormat FORMATTER =
new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss");
final int FRAMEBUFFER_WIDTH = mc.getMainWindow().getFramebufferWidth();
final int FRAMEBUFFER_HEIGHT =
mc.getMainWindow().getFramebufferHeight();
final int SCREENSHOT_WIDTH = 2048;
final int SCREENSHOT_HEIGHT = 2048;
File file = new File(mc.gameDir,
"panoramas/" + FORMATTER.format(new Date()) + "/panorama_" + panoramaSide +
File file = new File(mc.runDirectory,
"panoramas/" + panoramaNum + "/panorama_" + panoramaSide +
".png");
file.getParentFile().mkdirs();
try
@@ -169,11 +167,11 @@ public class Main
{
e.printStackTrace();
}
NativeImage nativeimage = ScreenShotHelper.createScreenshot(
NativeImage nativeimage = ScreenshotUtils.takeScreenshot(
SCREENSHOT_WIDTH,
SCREENSHOT_HEIGHT,
mc.getFramebuffer());
Util.getRenderingService().execute(() -> {
Util.getIoWorkerExecutor().execute(() -> {
int i = nativeimage.getWidth();
int j = nativeimage.getHeight();
int k = 0;
@@ -194,7 +192,7 @@ public class Main
false))
{
nativeimage.resizeSubRectTo(k, l, i, j, nativeimage1);
nativeimage1.write(file);
nativeimage1.writeFile(file);
}
catch (IOException ioexception)
{
@@ -208,4 +206,25 @@ public class Main
});
}
@Override
public Identifier getFabricId()
{
return new Identifier("panorama", "backgrounds");
}
@Override
public CompletableFuture<Void> reload(Synchronizer synchronizer,
ResourceManager manager,
Profiler prepareProfiler,
Profiler applyProfiler,
Executor prepareExecutor,
Executor applyExecutor)
{
loadPanoramas(MinecraftClient.getInstance(),
manager,
prepareExecutor,
applyExecutor);
return CompletableFuture.completedFuture(null);
}
}

View File

@@ -0,0 +1,13 @@
package markil3.panorama.mixins;
import net.minecraft.client.render.Camera;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(Camera.class)
public interface CameraAccessor
{
@Invoker("setRotation")
public void setView(float yaw, float pitch);
}

View File

@@ -0,0 +1,14 @@
package markil3.panorama.mixins;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.GameRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(GameRenderer.class)
public interface GameRenderAccessor
{
@Accessor("renderingPanorama")
public void setPanoramic(boolean panoramic);
}

View File

@@ -0,0 +1,67 @@
package markil3.panorama.mixins;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import markil3.panorama.EventBus;
import markil3.panorama.Main;
@Mixin(GameRenderer.class)
public class GameRenderHook
{
@Inject(method = "render", at = @At(value = "HEAD"))
public void startPanora(float tickDelta, long startTime, boolean tick,
CallbackInfo callbackInfo)
{
if (Main.isRenderingPanorama())
{
Main.renderPanorama(MinecraftClient.getInstance());
}
}
@Inject(method = "renderWorld", at = @At(value = "HEAD"))
public void startPanora(float tickDelta,
long limitTime,
MatrixStack matrix,
CallbackInfo callbackInfo)
{
if (Main.isRenderingPanorama())
{
((GameRenderAccessor) MinecraftClient.getInstance().gameRenderer).setPanoramic(
true);
}
}
@Inject(method = "renderWorld", at = @At(value = "TAIL"))
public void finishPanora(float tickDelta,
long limitTime,
MatrixStack matrix,
CallbackInfo callbackInfo)
{
if (Main.isRenderingPanorama())
{
((GameRenderAccessor) MinecraftClient.getInstance().gameRenderer).setPanoramic(
false);
}
}
@Inject(method = "renderWorld", at = @At(value = "INVOKE", target = "Lnet" +
"/minecraft/client/render/Camera;update" +
"(Lnet/minecraft/world/BlockView;Lnet/minecraft/entity/Entity;" +
"ZZF)V", shift = At.Shift.AFTER))
public void adjustCamera(float tickDelta,
long limitTime,
MatrixStack matrix,
CallbackInfo callbackInfo)
{
if (Main.isRenderingPanorama())
{
EventBus.onCamera(MinecraftClient.getInstance().gameRenderer.getCamera());
}
}
}

View File

@@ -0,0 +1,31 @@
package markil3.panorama.mixins;
import net.minecraft.client.Keyboard;
import net.minecraft.client.gl.Framebuffer;
import net.minecraft.client.util.ScreenshotUtils;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.io.File;
import java.util.function.Consumer;
import markil3.panorama.Main;
@Mixin(ScreenshotUtils.class)
public class ScreenshotHook
{
@Inject(method = "saveScreenshot", at = @At(value = "HEAD"))
private static void takeScreenshot(File gameDirectory,
int framebufferWidth,
int framebufferHeight,
Framebuffer framebuffer,
Consumer<Text> messageReceiver,
CallbackInfo callbackInfo)
{
Main.startRenderingPanorama();
}
}

View File

@@ -0,0 +1,14 @@
package markil3.panorama.mixins;
import net.minecraft.client.gui.RotatingCubeMapRenderer;
import net.minecraft.client.gui.screen.TitleScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(TitleScreen.class)
public interface TitleAccessor
{
@Accessor("backgroundRenderer")
public void setPanoramic(RotatingCubeMapRenderer panoramic);
}

View File

@@ -0,0 +1,33 @@
package markil3.panorama.mixins;
import net.minecraft.client.gui.RotatingCubeMapRenderer;
import net.minecraft.client.gui.screen.TitleScreen;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import markil3.panorama.Main;
@Mixin(TitleScreen.class)
public class TitleHook
{
@Redirect(method = "<init>(Z)V", at = @At(value = "FIELD", target = "Lnet" +
"/minecraft/client/gui/screen/TitleScreen;" +
"backgroundRenderer:Lnet/minecraft/client/gui" +
"/RotatingCubeMapRenderer;", opcode = Opcodes.PUTFIELD))
private void injected(TitleScreen screen,
RotatingCubeMapRenderer defaultPan)
{
RotatingCubeMapRenderer pan = Main.getPanorama();
if (pan != null)
{
((TitleAccessor) screen).setPanoramic(pan);
}
else
{
((TitleAccessor) screen).setPanoramic(defaultPan);
}
}
}

View File

@@ -1 +0,0 @@
public-f net.minecraft.client.gui.screen.MainMenuScreen field_209101_K #panorama

View File

@@ -1,29 +0,0 @@
modLoader="javafml"
loaderVersion="[34,)"
license="GPL-3.0-only"
issueTrackerURL="https://github.com/Markil3/MinecraftPanorama/issues"
[[mods]]
modId="panorama"
version="${file.jarVersion}"
displayName="Panorama Mod"
updateJSONURL="https://raw.githubusercontent.com/Markil3/MinecraftPanorama/master/update-forge.json"
displayURL="https://markil3.github.io/MinecraftPanorama"
#logoFile="examplemod.png"
credits="Mojang Studios for the original screenshot code."
# A text field displayed in the mod UI
authors="Markil 3"
description='''
This Minecraft mod provides the ability to take panoramic screenshots at any time with the Screenshot key (default to F2 on most Minecraft installations). On top of that, these screenshots will occupy the main menu background, allowing you to relive your adventures every time you boot up the game.
'''
[[dependencies.panorama]]
modId="forge"
mandatory=true
versionRange="[34,)"
ordering="NONE"
side="CLIENT"
[[dependencies.panorama]]
modId="minecraft"
mandatory=true
versionRange="[1.16.3]"
ordering="NONE"
side="CLIENT"

View File

@@ -0,0 +1,41 @@
{
"schemaVersion": 1,
"id": "panorama",
"version": "${version}",
"name": "Panorama Mod",
"description": "This Minecraft mod provides the ability to take panoramic screenshots at any time with the Screenshot key (default to F2 on most Minecraft installations). On top of that, these screenshots will occupy the main menu background, allowing you to relive your adventures every time you boot up the game.",
"authors": [
"Markil 3"
],
"contact": {
"homepage": "https://www.planetminecraft.com/mod/panorama/",
"sources": "https://github.com/Markil3/MinecraftPanorama",
"issues": "https://github.com/Markil3/MinecraftPanorama/issues"
},
"license": "GPL-3.0-only",
"icon": "assets/panorama/icon.png",
"environment": "client",
"entrypoints": {
"main": [
"markil3.panorama.Main"
]
},
"mixins": [
{
"config": "modid.mixins.json",
"environment": "client"
}
],
"depends": {
"fabricloader": ">=0.7.4",
"minecraft": "1.16.x"
},
"suggests": {
"modmenu": "*",
"cloth-config2": "*"
}
}

View File

@@ -0,0 +1,19 @@
{
"required": true,
"minVersion": "0.8",
"package": "markil3.panorama.mixins",
"compatibilityLevel": "JAVA_8",
"mixins": [
],
"client": [
"ScreenshotHook",
"GameRenderHook",
"TitleHook",
"GameRenderAccessor",
"TitleAccessor",
"CameraAccessor"
],
"injectors": {
"defaultRequire": 1
}
}