diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/CubeMap.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/CubeMap.java index ecfd9e02..ab0a5bae 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/gui/CubeMap.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/CubeMap.java @@ -60,14 +60,11 @@ public class CubeMap { } public void setSource(String source) { - cubemapTextures = new ResourceLocation[] { - new ResourceLocation(String.format(source, 0)), - new ResourceLocation(String.format(source, 1)), - new ResourceLocation(String.format(source, 2)), - new ResourceLocation(String.format(source, 3)), - new ResourceLocation(String.format(source, 4)), - new ResourceLocation(String.format(source, 5)) - }; + setSource(CubeMapRegistry.generatePanoramaResources(source)); + } + + public void setSource(ResourceLocation[] source) { + cubemapTextures = source; } public void init() { @@ -242,5 +239,4 @@ public class CubeMap { vb.pos(0, 0, zLevel).tex(0.5F + uSample, 0.5F + vSample).endVertex(); tessellator.draw(); } - } diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/CubeMapRegistry.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/CubeMapRegistry.java new file mode 100644 index 00000000..2fc0a364 --- /dev/null +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/CubeMapRegistry.java @@ -0,0 +1,51 @@ +package com.voxelmodpack.hdskins.gui; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.util.ResourceLocation; + +public final class CubeMapRegistry { + + private static final List RAW_SOURCES = new ArrayList(); + private static final List SOURCES = new ArrayList<>(); + + public static ResourceLocation[] generatePanoramaResources(String source) { + return new ResourceLocation[] { + new ResourceLocation(String.format(source, 0)), + new ResourceLocation(String.format(source, 1)), + new ResourceLocation(String.format(source, 2)), + new ResourceLocation(String.format(source, 3)), + new ResourceLocation(String.format(source, 4)), + new ResourceLocation(String.format(source, 5)) + }; + } + + public static void addSource(String source) { + if (!RAW_SOURCES.contains(source)) { + SOURCES.add(generatePanoramaResources(source)); + } + } + + public static int getRandomResourceIndex(boolean includeVanilla) { + int count = SOURCES.size(); + + if (includeVanilla) count++; + + count = (int)Math.floor(Math.random() * count); + + if (count >= SOURCES.size()) { + return -1; + } + + return count; + } + + public static ResourceLocation[] pickResource() { + return getResource(getRandomResourceIndex(false)); + } + + public static ResourceLocation[] getResource(int index) { + return SOURCES.get(index % SOURCES.size()); + } +} diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinGuiMainMenu.java b/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinGuiMainMenu.java index 2f0c0436..846b8dbf 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinGuiMainMenu.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinGuiMainMenu.java @@ -1,22 +1,39 @@ package com.voxelmodpack.hdskins.mixin; import com.voxelmodpack.hdskins.HDSkinManager; +import com.voxelmodpack.hdskins.gui.CubeMapRegistry; import com.voxelmodpack.hdskins.gui.GuiItemStackButton; + import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiMainMenu; import net.minecraft.client.gui.GuiScreen; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(GuiMainMenu.class) public class MixinGuiMainMenu extends GuiScreen { + @Shadow @Final + private static ResourceLocation[] TITLE_PANORAMA_PATHS; + + private int cubemapRandomResourceIndex = -2; + private static final int SKINS = 5000; + @Inject(method = "()V", at = @At("RETURN")) + private void init(CallbackInfo info) { + cubemapRandomResourceIndex = CubeMapRegistry.getRandomResourceIndex(true); + } + @Inject(method = "initGui()V", at = @At("RETURN")) private void onInit(CallbackInfo ci) { ItemStack itemStack = new ItemStack(Items.LEATHER_LEGGINGS); @@ -30,4 +47,10 @@ public class MixinGuiMainMenu extends GuiScreen { this.mc.displayGuiScreen(HDSkinManager.INSTANCE.createSkinsGui()); } } + + @Redirect(method = "drawPanorama(IIF)V", + at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/GuiMainMenu;TITLE_PANORAMA_PATHS:[Lnet/minecraft/util/ResourceLocation;")) + private ResourceLocation[] getPanoramaArray() { + return cubemapRandomResourceIndex < 0 ? TITLE_PANORAMA_PATHS : CubeMapRegistry.getResource(cubemapRandomResourceIndex); + } } diff --git a/src/main/java/com/minelittlepony/MineLittlePony.java b/src/main/java/com/minelittlepony/MineLittlePony.java index f7d84a6d..0e2cc604 100644 --- a/src/main/java/com/minelittlepony/MineLittlePony.java +++ b/src/main/java/com/minelittlepony/MineLittlePony.java @@ -7,6 +7,7 @@ import com.minelittlepony.pony.data.PonyDataSerialzier; import com.minelittlepony.render.PonySkullRenderer; import com.mumfrey.liteloader.core.LiteLoader; import com.voxelmodpack.hdskins.HDSkinManager; +import com.voxelmodpack.hdskins.gui.CubeMapRegistry; import com.voxelmodpack.hdskins.skins.SkinServer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.entity.RenderManager; @@ -49,6 +50,7 @@ public class MineLittlePony { renderManager = new PonyRenderManager(); LiteLoader.getInstance().registerExposable(config, null); + LiteLoader.getInstance().writeConfig(config); IReloadableResourceManager irrm = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(); irrm.registerReloadListener(ponyManager); @@ -58,6 +60,10 @@ public class MineLittlePony { // This also makes it the default gateway server. SkinServer.defaultServers.add(MINELP_LEGACY_SERVER); + + for (String resource : config.panoramas) { + CubeMapRegistry.addSource(resource); + } } /** diff --git a/src/main/java/com/minelittlepony/PonyConfig.java b/src/main/java/com/minelittlepony/PonyConfig.java index 1cd5a732..4d348587 100644 --- a/src/main/java/com/minelittlepony/PonyConfig.java +++ b/src/main/java/com/minelittlepony/PonyConfig.java @@ -39,6 +39,11 @@ public class PonyConfig extends SensibleConfig implements Exposable { @Expose public boolean illagers = true; @Expose public boolean guardians = true; + @Expose public String[] panoramas = new String[] { + "minelp:textures/cubemap/sugarcubecorner_%d.png", + "minelp:textures/cubemap/quillsandsofas_%d.png" + }; + /** * Gets the current PonyLevel. That is the level of ponies you would like to see. * @param ignorePony true to ignore whatever value the setting has. diff --git a/src/main/java/com/minelittlepony/hdskins/gui/GuiSkinsMineLP.java b/src/main/java/com/minelittlepony/hdskins/gui/GuiSkinsMineLP.java index cd146086..120fd919 100644 --- a/src/main/java/com/minelittlepony/hdskins/gui/GuiSkinsMineLP.java +++ b/src/main/java/com/minelittlepony/hdskins/gui/GuiSkinsMineLP.java @@ -5,6 +5,7 @@ import com.minelittlepony.PonyManager; import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; +import com.voxelmodpack.hdskins.gui.CubeMapRegistry; import com.voxelmodpack.hdskins.gui.EntityPlayerModel; import com.voxelmodpack.hdskins.gui.GuiItemStackButton; import com.voxelmodpack.hdskins.gui.GuiSkins; @@ -27,12 +28,6 @@ public class GuiSkinsMineLP extends GuiSkins { private boolean isWet = false; - - private static final String[] panoramas = new String[] { - "minelp:textures/cubemap/sugurcubecorner_%d.png", - "minelp:textures/cubemap/quillsandsofas_%d.png" - }; - @Override protected EntityPlayerModel getModel(GameProfile profile) { return new EntityPonyModel(profile); @@ -51,9 +46,7 @@ public class GuiSkinsMineLP extends GuiSkins { @Override protected void initPanorama() { - int i = (int)Math.floor(Math.random() * panoramas.length); - - panorama.setSource(panoramas[i]); + panorama.setSource(CubeMapRegistry.pickResource()); } @@ -103,7 +96,7 @@ public class GuiSkinsMineLP extends GuiSkins { @Override protected void onSetRemoteSkin(Type type, ResourceLocation resource, MinecraftProfileTexture profileTexture) { MineLittlePony.logger.debug("Invalidating old remote skin, checking updated remote skin"); - if (type == Type.SKIN) { + if (ponyManager != null && resource != null && type == Type.SKIN) { ponyManager.removePony(resource); } } diff --git a/src/main/resources/assets/minelp/textures/cubemap/sugurcubecorner_0.png b/src/main/resources/assets/minelp/textures/cubemap/sugarcubecorner_0.png similarity index 100% rename from src/main/resources/assets/minelp/textures/cubemap/sugurcubecorner_0.png rename to src/main/resources/assets/minelp/textures/cubemap/sugarcubecorner_0.png diff --git a/src/main/resources/assets/minelp/textures/cubemap/sugurcubecorner_1.png b/src/main/resources/assets/minelp/textures/cubemap/sugarcubecorner_1.png similarity index 100% rename from src/main/resources/assets/minelp/textures/cubemap/sugurcubecorner_1.png rename to src/main/resources/assets/minelp/textures/cubemap/sugarcubecorner_1.png diff --git a/src/main/resources/assets/minelp/textures/cubemap/sugurcubecorner_2.png b/src/main/resources/assets/minelp/textures/cubemap/sugarcubecorner_2.png similarity index 100% rename from src/main/resources/assets/minelp/textures/cubemap/sugurcubecorner_2.png rename to src/main/resources/assets/minelp/textures/cubemap/sugarcubecorner_2.png diff --git a/src/main/resources/assets/minelp/textures/cubemap/sugurcubecorner_3.png b/src/main/resources/assets/minelp/textures/cubemap/sugarcubecorner_3.png similarity index 100% rename from src/main/resources/assets/minelp/textures/cubemap/sugurcubecorner_3.png rename to src/main/resources/assets/minelp/textures/cubemap/sugarcubecorner_3.png diff --git a/src/main/resources/assets/minelp/textures/cubemap/sugurcubecorner_4.png b/src/main/resources/assets/minelp/textures/cubemap/sugarcubecorner_4.png similarity index 100% rename from src/main/resources/assets/minelp/textures/cubemap/sugurcubecorner_4.png rename to src/main/resources/assets/minelp/textures/cubemap/sugarcubecorner_4.png diff --git a/src/main/resources/assets/minelp/textures/cubemap/sugurcubecorner_5.png b/src/main/resources/assets/minelp/textures/cubemap/sugarcubecorner_5.png similarity index 100% rename from src/main/resources/assets/minelp/textures/cubemap/sugurcubecorner_5.png rename to src/main/resources/assets/minelp/textures/cubemap/sugarcubecorner_5.png