diff --git a/build.gradle b/build.gradle index 2f1dfd7..578448e 100644 --- a/build.gradle +++ b/build.gradle @@ -32,8 +32,8 @@ minecraft { // 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') + + accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Default run configurations. // These can be tweaked, removed, or duplicated as needed. diff --git a/gradle.properties b/gradle.properties index 0dd5346..3d2e4a0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,6 +11,6 @@ forge_version=35.1.37 cloth_version=4.11.14 # Mod Properties -mod_version = 0.1-alpha +mod_version = 1.0 maven_group = markil3 archives_base_name = panorama \ No newline at end of file diff --git a/src/main/java/markil3/panorama/EventBus.java b/src/main/java/markil3/panorama/EventBus.java index 463045d..8684025 100644 --- a/src/main/java/markil3/panorama/EventBus.java +++ b/src/main/java/markil3/panorama/EventBus.java @@ -1,10 +1,18 @@ 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; @@ -86,4 +94,26 @@ public class EventBus 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); + } + } + } + } } diff --git a/src/main/java/markil3/panorama/FileTexture.java b/src/main/java/markil3/panorama/FileTexture.java new file mode 100644 index 0000000..f8cd068 --- /dev/null +++ b/src/main/java/markil3/panorama/FileTexture.java @@ -0,0 +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 java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public class FileTexture extends SimpleTexture +{ + private final File file; + + public FileTexture(ResourceLocation p_i1275_1_, File file) + { + super(p_i1275_1_); + this.file = file; + } + + @Override + protected TextureData getTextureData(IResourceManager p_215246_1_) + { + return getTextureData(p_215246_1_, this.file); + } + + public static SimpleTexture.TextureData getTextureData(IResourceManager resourceManagerIn, + File locationIn) + { + NativeImage image; + TextureMetadataSection meta; + try (FileInputStream stream = new FileInputStream(locationIn)) + { + image = + NativeImage.read(stream); + meta = null; + + return new SimpleTexture.TextureData(null, + image); + } + catch (IOException e) + { + return new SimpleTexture.TextureData(e); + } + } +} diff --git a/src/main/java/markil3/panorama/Main.java b/src/main/java/markil3/panorama/Main.java index 9778d08..1f447d7 100644 --- a/src/main/java/markil3/panorama/Main.java +++ b/src/main/java/markil3/panorama/Main.java @@ -8,8 +8,12 @@ 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.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; @@ -37,6 +41,7 @@ public class Main { // Directly reference a log4j logger. private static final Logger LOGGER = LogManager.getLogger(); + static int numPanoramas = 0; public Main() { @@ -56,64 +61,70 @@ public class Main 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) + { + int i = 0; + int j; + TextureManager textureManager = mc.textureManager; + ResourceLocation loc; + File panoramas = new File(mc.gameDir, "panoramas"); + if (panoramas.isDirectory()) + { + for (File panorama : panoramas.listFiles()) + { + if (panorama.isDirectory()) + { + for (j = 0; j < 6; j++) + { + loc = new ResourceLocation( + "panorama:textures/gui/title/background/" + i + "/panorama_" + j + ".png"); + textureManager.loadTexture(loc, + new FileTexture(loc, + new File(panorama, + "panorama_" + j + ".png"))); + } + i++; + } + } + } + numPanoramas = i; + } + private void setup(final FMLCommonSetupEvent event) { - // some preinit code - LOGGER.info("HELLO FROM PREINIT"); - LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName()); } private void doClientStuff(final FMLClientSetupEvent event) { - // do something that can only be done on the client - LOGGER.info("Got game settings {}", - event.getMinecraftSupplier().get().gameSettings); +// loadPanoramas(event.getMinecraftSupplier().get()); } private void enqueueIMC(final InterModEnqueueEvent event) { - // some example code to dispatch IMC to another mod - InterModComms.sendTo("examplemod", "helloworld", () -> { - LOGGER.info("Hello world from the MDK"); - return "Hello world"; - }); } private void processIMC(final InterModProcessEvent event) { - // some example code to receive and process InterModComms from other - // mods - LOGGER.info("Got IMC {}", event.getIMCStream(). - map(m -> m.getMessageSupplier().get()). - collect(Collectors.toList())); } // You can use SubscribeEvent and let the Event Bus discover methods to call @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { - // do something when the server starts - LOGGER.info("HELLO from server starting"); - } - - // You can use EventBusSubscriber to automatically subscribe events on - // the contained class (this is subscribing to the MOD - // Event bus for receiving Registry Events) - @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) - public static class RegistryEvents - { - @SubscribeEvent - public static void onBlocksRegistry(final RegistryEvent.Register blockRegistryEvent) - { - // register a new block here - LOGGER.info("HELLO from Register Block"); - } } static void renderPanorama(Minecraft mc) @@ -138,7 +149,8 @@ public class Main static void saveScreenshot(Minecraft mc, int panoramaNum, int panoramaSide) { - final SimpleDateFormat FORMATTER = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss"); + 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(); diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg new file mode 100644 index 0000000..73ade97 --- /dev/null +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -0,0 +1 @@ +public-f net.minecraft.client.gui.screen.MainMenuScreen field_209101_K #panorama \ No newline at end of file