Lets the main menu use user-created panoramas.

This commit is contained in:
Markil3
2021-03-07 00:50:13 -07:00
parent be52b2b025
commit 6d188f46f7
6 changed files with 127 additions and 36 deletions

View File

@@ -32,8 +32,8 @@ minecraft {
// Simply re-run your setup task after changing the mappings to update your workspace. // Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'snapshot', version: project.mappings mappings channel: 'snapshot', version: project.mappings
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. // 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. // Default run configurations.
// These can be tweaked, removed, or duplicated as needed. // These can be tweaked, removed, or duplicated as needed.

View File

@@ -11,6 +11,6 @@ forge_version=35.1.37
cloth_version=4.11.14 cloth_version=4.11.14
# Mod Properties # Mod Properties
mod_version = 0.1-alpha mod_version = 1.0
maven_group = markil3 maven_group = markil3
archives_base_name = panorama archives_base_name = panorama

View File

@@ -1,10 +1,18 @@
package markil3.panorama; package markil3.panorama;
import net.minecraft.client.Minecraft; 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.api.distmarker.Dist;
import net.minecraftforge.client.event.EntityViewRenderEvent; 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.RenderHandEvent;
import net.minecraftforge.client.event.ScreenshotEvent; import net.minecraftforge.client.event.ScreenshotEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
@@ -86,4 +94,26 @@ public class EventBus
screenshotState++; 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

@@ -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);
}
}
}

View File

@@ -8,8 +8,12 @@ import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.FogRenderer; import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.client.renderer.texture.NativeImage; 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.ScreenShotHelper;
import net.minecraft.util.Util; 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.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@@ -37,6 +41,7 @@ public class Main
{ {
// Directly reference a log4j logger. // Directly reference a log4j logger.
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
static int numPanoramas = 0;
public Main() public Main()
{ {
@@ -56,64 +61,70 @@ public class Main
FMLJavaModLoadingContext.get() FMLJavaModLoadingContext.get()
.getModEventBus() .getModEventBus()
.addListener(this::doClientStuff); .addListener(this::doClientStuff);
FMLJavaModLoadingContext.get()
.getModEventBus()
.addListener(this::onStitch);
// Register ourselves for server and other game events we are // Register ourselves for server and other game events we are
// interested in // interested in
MinecraftForge.EVENT_BUS.register(this); 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) 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) private void doClientStuff(final FMLClientSetupEvent event)
{ {
// do something that can only be done on the client // loadPanoramas(event.getMinecraftSupplier().get());
LOGGER.info("Got game settings {}",
event.getMinecraftSupplier().get().gameSettings);
} }
private void enqueueIMC(final InterModEnqueueEvent event) 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) 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 // You can use SubscribeEvent and let the Event Bus discover methods to call
@SubscribeEvent @SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) 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<Block> blockRegistryEvent)
{
// register a new block here
LOGGER.info("HELLO from Register Block");
}
} }
static void renderPanorama(Minecraft mc) static void renderPanorama(Minecraft mc)
@@ -138,7 +149,8 @@ public class Main
static void saveScreenshot(Minecraft mc, int panoramaNum, int panoramaSide) 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_WIDTH = mc.getMainWindow().getFramebufferWidth();
final int FRAMEBUFFER_HEIGHT = final int FRAMEBUFFER_HEIGHT =
mc.getMainWindow().getFramebufferHeight(); mc.getMainWindow().getFramebufferHeight();

View File

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