From 6d70a76c9587d4eda1f8f79ba37901a0396dd941 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 2 Aug 2012 16:50:30 -0230 Subject: [PATCH] More fixes --- .../cpw/mods/fml/client/FMLClientHandler.java | 22 -------- .../client/registry/RenderingRegistry.java | 12 ++++ fml/client/net/minecraft/src/ModLoader.java | 56 +++++++++++-------- .../minecraft/src/ModTextureAnimation.java | 8 +-- .../net/minecraft/src/ModTextureStatic.java | 26 ++++----- .../cpw/mods/fml/common/FMLCommonHandler.java | 6 ++ .../fml/common/registry/EntityRegistry.java | 53 ++++++++++++++++-- fml/common/fml_at.cfg | 3 +- 8 files changed, 117 insertions(+), 69 deletions(-) diff --git a/fml/client/cpw/mods/fml/client/FMLClientHandler.java b/fml/client/cpw/mods/fml/client/FMLClientHandler.java index b801f4a19..93d72ff5e 100644 --- a/fml/client/cpw/mods/fml/client/FMLClientHandler.java +++ b/fml/client/cpw/mods/fml/client/FMLClientHandler.java @@ -283,18 +283,6 @@ public class FMLClientHandler implements IFMLSidedHandler { return client; } - /** - * @param armor - * @return - */ - public int addNewArmourRendererPrefix(String armor) - { - String[] prefixes = ObfuscationReflectionHelper.getPrivateValue(RenderPlayer.class, null, "field_77110_j", "j", "armorFilenamePrefix"); - String[] newPrefixes = Arrays.copyOf(prefixes, prefixes.length+1); - newPrefixes[prefixes.length] = armor; - ObfuscationReflectionHelper.setPrivateValue(RenderPlayer.class, null, newPrefixes, "field_77110_j", "j", "armorFilenamePrefix" ); - return prefixes.length; - } /** * @param player * @param gui @@ -306,16 +294,6 @@ public class FMLClientHandler implements IFMLSidedHandler } } - /** - * @param mod - * @param keyHandler - * @param allowRepeat - */ - public void registerModLoaderKeyHandler(BaseMod mod, KeyBinding keyHandler, boolean allowRepeat) - { - ModLoaderModContainer mlmc=ModLoaderHelper.registerKeyHelper(mod); - KeyBindingRegistry.registerKeyBinding(new ModLoaderKeyBindingHandler(keyHandler, allowRepeat, mlmc)); - } @Override public void profileStart(String profileLabel) { client.field_71424_I.func_76320_a(profileLabel); diff --git a/fml/client/cpw/mods/fml/client/registry/RenderingRegistry.java b/fml/client/cpw/mods/fml/client/registry/RenderingRegistry.java index c95991879..44c992c6f 100644 --- a/fml/client/cpw/mods/fml/client/registry/RenderingRegistry.java +++ b/fml/client/cpw/mods/fml/client/registry/RenderingRegistry.java @@ -1,6 +1,18 @@ package cpw.mods.fml.client.registry; +import java.util.Arrays; + +import com.google.common.collect.ObjectArrays; + +import net.minecraft.src.RenderPlayer; +import cpw.mods.fml.common.ObfuscationReflectionHelper; + public class RenderingRegistry { + public static int addNewArmourRendererPrefix(String armor) + { + RenderPlayer.field_77110_j = ObjectArrays.concat(RenderPlayer.field_77110_j, armor); + return RenderPlayer.field_77110_j.length-1; + } } diff --git a/fml/client/net/minecraft/src/ModLoader.java b/fml/client/net/minecraft/src/ModLoader.java index dbcf14bd3..a04bf1a01 100644 --- a/fml/client/net/minecraft/src/ModLoader.java +++ b/fml/client/net/minecraft/src/ModLoader.java @@ -21,16 +21,22 @@ import java.util.Map; import java.util.logging.Logger; import net.minecraft.client.Minecraft; +import net.minecraft.server.MinecraftServer; import cpw.mods.fml.client.BlockRenderManager; import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.fml.client.ModLoaderKeyBindingHandler; import cpw.mods.fml.client.SpriteHelper; import cpw.mods.fml.client.TextureFXManager; import cpw.mods.fml.client.registry.ClientRegistry; +import cpw.mods.fml.client.registry.KeyBindingRegistry; +import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.modloader.ModLoaderHelper; import cpw.mods.fml.common.modloader.ModLoaderModContainer; +import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.FMLRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.ObfuscationReflectionHelper; @@ -49,7 +55,7 @@ public class ModLoader */ public static void addAchievementDesc(Achievement achievement, String name, String description) { - String achName=achievement.func_44020_i(); + String achName=achievement.func_75970_i(); addLocalization(achName, name); addLocalization(achName+".desc", description); } @@ -87,7 +93,7 @@ public class ModLoader */ public static int addArmor(String armor) { - return FMLClientHandler.instance().addNewArmourRendererPrefix(armor); + return RenderingRegistry.addNewArmourRendererPrefix(armor); } /** @@ -97,7 +103,7 @@ public class ModLoader */ public static void addBiome(BiomeGenBase biome) { - FMLClientHandler.instance().addBiomeToDefaultWorldGenerator(biome); + GameRegistry.addBiome(biome); } /** @@ -202,7 +208,7 @@ public class ModLoader */ public static void addSmelting(int input, ItemStack output) { - FMLRegistry.addSmelting(input, output); + GameRegistry.addSmelting(input, output, 1.0f); } /** @@ -216,7 +222,7 @@ public class ModLoader */ public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList) { - FMLRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, FMLClientHandler.instance().getDefaultOverworldBiomes()); + EntityRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, WorldType.base12Biomes); } /** @@ -231,7 +237,7 @@ public class ModLoader */ public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { - FMLRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, biomes); + EntityRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, biomes); } /** @@ -245,7 +251,7 @@ public class ModLoader */ public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList) { - FMLRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, FMLClientHandler.instance().getDefaultOverworldBiomes()); + EntityRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, WorldType.base12Biomes); } /** @@ -260,7 +266,7 @@ public class ModLoader */ public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { - FMLRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, biomes); + EntityRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, biomes); } /** @@ -358,7 +364,7 @@ public class ModLoader */ public static Logger getLogger() { - return FMLCommonHandler.instance().getFMLLogger(); + return FMLLog.getLogger(); } public static Minecraft getMinecraftInstance() @@ -372,9 +378,9 @@ public class ModLoader * * @return */ - public static Object getMinecraftServerInstance() + public static MinecraftServer getMinecraftServerInstance() { - return getMinecraftInstance(); + return FMLCommonHandler.instance().getMinecraftServerInstance(); } /** @@ -422,7 +428,7 @@ public class ModLoader */ public static int getUniqueEntityId() { - return FMLCommonHandler.instance().nextUniqueEntityListId(); + return EntityRegistry.findGlobalUniqueEntityId(); } public static int getUniqueSpriteIndex(String path) @@ -529,7 +535,7 @@ public class ModLoader */ public static void registerBlock(Block block) { - FMLRegistry.registerBlock(block); + GameRegistry.registerBlock(block); } /** @@ -540,7 +546,7 @@ public class ModLoader */ public static void registerBlock(Block block, Class itemclass) { - FMLRegistry.registerBlock(block, itemclass); + GameRegistry.registerBlock(block, itemclass); } /** @@ -552,7 +558,7 @@ public class ModLoader */ public static void registerEntityID(Class entityClass, String entityName, int id) { - FMLRegistry.registerEntityID(entityClass, entityName, id); + EntityRegistry.registerEntityID(entityClass, entityName, id); } /** @@ -566,12 +572,13 @@ public class ModLoader */ public static void registerEntityID(Class entityClass, String entityName, int id, int background, int foreground) { - FMLRegistry.registerEntityID(entityClass, entityName, id, background, foreground); + EntityRegistry.registerEntityID(entityClass, entityName, id, background, foreground); } public static void registerKey(BaseMod mod, KeyBinding keyHandler, boolean allowRepeat) { - FMLClientHandler.instance().registerModLoaderKeyHandler(mod, keyHandler, allowRepeat); + ModLoaderModContainer mlmc=ModLoaderHelper.registerKeyHelper(mod); + KeyBindingRegistry.registerKeyBinding(new ModLoaderKeyBindingHandler(keyHandler, allowRepeat, mlmc)); } /** @@ -596,12 +603,12 @@ public class ModLoader */ public static void registerTileEntity(Class tileEntityClass, String id) { - FMLRegistry.registerTileEntity(tileEntityClass, id); + GameRegistry.registerTileEntity(tileEntityClass, id); } public static void registerTileEntity(Class tileEntityClass, String id, TileEntitySpecialRenderer renderer) { - ClientRegistry.instance().registerTileEntity(tileEntityClass, id, renderer); + ClientRegistry.registerTileEntity(tileEntityClass, id, renderer); } /** @@ -611,7 +618,7 @@ public class ModLoader */ public static void removeBiome(BiomeGenBase biome) { - FMLRegistry.removeBiome(biome); + GameRegistry.removeBiome(biome); } /** @@ -622,7 +629,7 @@ public class ModLoader */ public static void removeSpawn(Class entityClass, EnumCreatureType spawnList) { - FMLRegistry.removeSpawn(entityClass, spawnList, FMLClientHandler.instance().getDefaultOverworldBiomes()); + EntityRegistry.removeSpawn(entityClass, spawnList, WorldType.base12Biomes); } /** @@ -634,7 +641,7 @@ public class ModLoader */ public static void removeSpawn(Class entityClass, EnumCreatureType spawnList, BiomeGenBase... biomes) { - FMLRegistry.removeSpawn(entityClass, spawnList, biomes); + EntityRegistry.removeSpawn(entityClass, spawnList, biomes); } /** @@ -645,7 +652,7 @@ public class ModLoader */ public static void removeSpawn(String entityName, EnumCreatureType spawnList) { - FMLRegistry.removeSpawn(entityName, spawnList, FMLClientHandler.instance().getDefaultOverworldBiomes()); + EntityRegistry.removeSpawn(entityName, spawnList, WorldType.base12Biomes); } /** @@ -688,7 +695,8 @@ public class ModLoader } public static void sendPacket(Packet packet) { - FMLClientHandler.instance().sendPacket(packet); + // TODO +// FMLClientHandler.instance().sendPacket(packet); } /** * Send a chat message to the server diff --git a/fml/client/net/minecraft/src/ModTextureAnimation.java b/fml/client/net/minecraft/src/ModTextureAnimation.java index dc10509f3..97aaaa6a9 100644 --- a/fml/client/net/minecraft/src/ModTextureAnimation.java +++ b/fml/client/net/minecraft/src/ModTextureAnimation.java @@ -52,11 +52,11 @@ public class ModTextureAnimation extends FMLTextureFX public ModTextureAnimation(int icon, int size, String target, BufferedImage image, int tickCount) { super(icon); - RenderEngine re = FMLClientHandler.instance().getClient().field_6315_n; + RenderEngine re = FMLClientHandler.instance().getClient().field_71446_o; targetTex = target; - field_1129_e = size; - field_1128_f = re.func_1070_a(target); + field_76849_e = size; + field_76847_f = re.func_78341_b(target); tickRate = tickCount; ticks = tickCount; @@ -121,7 +121,7 @@ public class ModTextureAnimation extends FMLTextureFX index = 0; } - field_1127_a = images[index]; + field_76852_a = images[index]; ticks = 0; } } diff --git a/fml/client/net/minecraft/src/ModTextureStatic.java b/fml/client/net/minecraft/src/ModTextureStatic.java index 30482aa89..acf0255c9 100644 --- a/fml/client/net/minecraft/src/ModTextureStatic.java +++ b/fml/client/net/minecraft/src/ModTextureStatic.java @@ -48,12 +48,12 @@ public class ModTextureStatic extends FMLTextureFX public ModTextureStatic(int icon, int size, String target, BufferedImage image) { super(icon); - RenderEngine re = FMLClientHandler.instance().getClient().field_6315_n; + RenderEngine re = FMLClientHandler.instance().getClient().field_71446_o; targetTex = target; storedSize = size; - field_1129_e = size; - field_1128_f = re.func_1070_a(target); + field_76849_e = size; + field_76847_f = re.func_78341_b(target); overrideData = image; } @@ -83,14 +83,14 @@ public class ModTextureStatic extends FMLTextureFX public void func_783_a() { - if (oldanaglyph != field_1131_c) + if (oldanaglyph != field_76851_c) { update(); } // This makes it so we only apply the texture to the target texture when we need to, //due to the fact that update is called when the Effect is first registered, we actually //need to wait for the next one. - field_1129_e = (needApply == 0 ? 0 : storedSize); + field_76849_e = (needApply == 0 ? 0 : storedSize); if (needApply > 0) { needApply--; @@ -99,7 +99,7 @@ public class ModTextureStatic extends FMLTextureFX public void func_782_a(RenderEngine p_782_1_) { - GL11.glBindTexture(GL_TEXTURE_2D, p_782_1_.func_1070_a(targetTex)); + GL11.glBindTexture(GL_TEXTURE_2D, p_782_1_.func_78341_b(targetTex)); } public void update() @@ -113,18 +113,18 @@ public class ModTextureStatic extends FMLTextureFX int g = pixels[idx] >> 8 & 255; int b = pixels[idx] >> 0 & 255; - if (field_1131_c) + if (field_76851_c) { r = g = b = (r + g + b) / 3; } - field_1127_a[i + 0] = (byte)r; - field_1127_a[i + 1] = (byte)g; - field_1127_a[i + 2] = (byte)b; - field_1127_a[i + 3] = (byte)a; + field_76852_a[i + 0] = (byte)r; + field_76852_a[i + 1] = (byte)g; + field_76852_a[i + 2] = (byte)b; + field_76852_a[i + 3] = (byte)a; } - oldanaglyph = field_1131_c; + oldanaglyph = field_76851_c; } //Implementation of http://scale2x.sourceforge.net/algorithm.html @@ -174,6 +174,6 @@ public class ModTextureStatic extends FMLTextureFX @Override public String toString() { - return String.format("ModTextureStatic %s @ %d", targetTex, field_1126_b); + return String.format("ModTextureStatic %s @ %d", targetTex, field_76850_b); } } diff --git a/fml/common/cpw/mods/fml/common/FMLCommonHandler.java b/fml/common/cpw/mods/fml/common/FMLCommonHandler.java index 7c086b2ba..94e1cce2b 100644 --- a/fml/common/cpw/mods/fml/common/FMLCommonHandler.java +++ b/fml/common/cpw/mods/fml/common/FMLCommonHandler.java @@ -546,4 +546,10 @@ public class FMLCommonHandler { Loader.instance().serverStopping(); } + + public MinecraftServer getMinecraftServerInstance() + { + //TODO + return null; + } } diff --git a/fml/common/cpw/mods/fml/common/registry/EntityRegistry.java b/fml/common/cpw/mods/fml/common/registry/EntityRegistry.java index 47136a790..d889ece70 100644 --- a/fml/common/cpw/mods/fml/common/registry/EntityRegistry.java +++ b/fml/common/cpw/mods/fml/common/registry/EntityRegistry.java @@ -1,8 +1,11 @@ package cpw.mods.fml.common.registry; +import java.util.BitSet; import java.util.Iterator; import java.util.List; +import com.google.common.collect.BiMap; + import net.minecraft.src.BiomeGenBase; import net.minecraft.src.Entity; import net.minecraft.src.EntityList; @@ -13,17 +16,47 @@ import net.minecraft.src.SpawnListEntry; public class EntityRegistry { + private static final EntityRegistry INSTANCE = new EntityRegistry(); + + private BitSet availableIndicies; + + public static EntityRegistry instance() + { + return INSTANCE; + } + + private EntityRegistry() + { + availableIndicies = new BitSet(256); + availableIndicies.set(0,255); + for (Object id : EntityList.field_75623_d.keySet()) + { + availableIndicies.clear((Integer)id); + } + } + public static void registerEntityID(Class entityClass, String entityName, int id) { + instance().validateAndClaimId(id); EntityList.func_75618_a(entityClass, entityName, id); } - public void registerEntityID(Class entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour) + private void validateAndClaimId(int id) { + if (!availableIndicies.get(id)) + { + throw new RuntimeException(String.format("Unable to claim entity id %d", id)); + } + availableIndicies.clear(id); + } + + public static void registerEntityID(Class entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour) + { + instance().validateAndClaimId(id); EntityList.func_75614_a(entityClass, entityName, id, backgroundEggColour, foregroundEggColour); } - public void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) + public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) { for (BiomeGenBase biome : biomes) { @@ -46,7 +79,7 @@ public class EntityRegistry } } - public void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) + public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { Class entityClazz = (Class) EntityList.field_75625_b.get(entityName); @@ -56,7 +89,7 @@ public class EntityRegistry } } - public void removeSpawn(Class entityClass, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) + public static void removeSpawn(Class entityClass, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) { for (BiomeGenBase biome : biomes) { @@ -74,7 +107,7 @@ public class EntityRegistry } } - public void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) + public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) { Class entityClazz = (Class) EntityList.field_75625_b.get(entityName); @@ -84,4 +117,14 @@ public class EntityRegistry } } + public static int findGlobalUniqueEntityId() + { + int res = instance().availableIndicies.nextSetBit(0); + if (res < 0) + { + throw new RuntimeException("No more entity indicies left"); + } + return res; + } + } diff --git a/fml/common/fml_at.cfg b/fml/common/fml_at.cfg index a6efb9826..1466965eb 100644 --- a/fml/common/fml_at.cfg +++ b/fml/common/fml_at.cfg @@ -4,8 +4,9 @@ public ajh.a(Ljava/lang/Class;Ljava/lang/String;)V # EntityList addMappings public jq.a(Ljava/lang/Class;Ljava/lang/String;I)V public jq.a(Ljava/lang/Class;Ljava/lang/String;III)V -# EntityList nameToClassMap +# EntityList nameToClassMap and idToClassMap public jq.b +public jq.d # RenderManager renderers public avx.o # RenderBlocks - everything