From 8b1f984c533947a50231791df0dd1324673ee3b2 Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Thu, 5 Apr 2012 12:36:54 -0400 Subject: [PATCH] Handle the minecraft object registry better- now the client compiles too Also a quickie astyle run over the code.. --- .../cpw/mods/fml/common/FMLCommonHandler.java | 30 ++-- .../net/minecraft/src/CommonRegistry.java | 91 +++-------- .../net/minecraft/src/IMinecraftRegistry.java | 34 ++++ .../.plugins/org.eclipse.core.resources/.snap | Bin 647916 -> 651374 bytes .../cpw/mods/fml/server/FMLServerHandler.java | 4 + .../net/minecraft/src/ServerRegistry.java | 145 ++++++++++++++++++ 6 files changed, 220 insertions(+), 84 deletions(-) create mode 100644 fml/common/net/minecraft/src/IMinecraftRegistry.java create mode 100644 fml/server/net/minecraft/src/ServerRegistry.java diff --git a/fml/common/cpw/mods/fml/common/FMLCommonHandler.java b/fml/common/cpw/mods/fml/common/FMLCommonHandler.java index eedb829bb..ed56e1bf6 100644 --- a/fml/common/cpw/mods/fml/common/FMLCommonHandler.java +++ b/fml/common/cpw/mods/fml/common/FMLCommonHandler.java @@ -31,21 +31,13 @@ public class FMLCommonHandler private Map modChannels = new HashMap(); private Map> activeChannels = new HashMap>(); private IFMLSidedHandler sidedDelegate; - - private FMLCommonHandler() { - try { - Class.forName("net.minecraft.client.Minecraft"); - sidedDelegate=(IFMLSidedHandler) Class.forName("cpw.mods.fml.client.FMLClientHandler").newInstance(); - } catch (Exception ex) { - try { - sidedDelegate=(IFMLSidedHandler) Class.forName("cpw.mods.fml.server.FMLServerHandler").newInstance(); - } catch (Exception ex2) { - Loader.log.severe("A severe installation issue has occured with FML, we cannot continue"); - throw new LoaderException(ex2); - } - } + + + public void registerSidedDelegate(IFMLSidedHandler handler) + { + sidedDelegate = handler; } - + public void gameTickStart() { for (ModContainer mod : Loader.getModList()) @@ -167,12 +159,14 @@ public class FMLCommonHandler { return activeChannels.get(player).contains(channel); } - - public Logger getFMLLogger() { + + public Logger getFMLLogger() + { return Loader.log; } - - public Logger getMinecraftLogger() { + + public Logger getMinecraftLogger() + { return sidedDelegate.getMinecraftLogger(); } diff --git a/fml/common/net/minecraft/src/CommonRegistry.java b/fml/common/net/minecraft/src/CommonRegistry.java index 652a85583..de29cfa1d 100644 --- a/fml/common/net/minecraft/src/CommonRegistry.java +++ b/fml/common/net/minecraft/src/CommonRegistry.java @@ -13,131 +13,90 @@ */ package net.minecraft.src; -import java.util.Collections; -import java.util.List; public class CommonRegistry { + private static IMinecraftRegistry instance; + + public static void registerRegistry(IMinecraftRegistry registry) + { + if (instance != null) + { + throw new RuntimeException("Illegal attempt to replace FML registry"); + } + + instance = registry; + } public static void addRecipe(ItemStack output, Object... params) { - CraftingManager.func_20151_a().func_20153_a(output, params); + instance.addRecipe(output, params); } public static void addShapelessRecipe(ItemStack output, Object... params) { - CraftingManager.func_20151_a().func_21146_b(output, params); + instance.addShapelessRecipe(output, params); } public static void addSmelting(int input, ItemStack output) { - FurnaceRecipes.func_21162_a().func_21160_a(input, output); + instance.addSmelting(input, output); } public static void registerBlock(Block block) { - registerBlock(block, ItemBlock.class); + instance.registerBlock(block); } public static void registerBlock(Block block, Class itemclass) { - try - { - assert block != null : "registerBlock: block cannot be null"; - assert itemclass != null : "registerBlock: itemclass cannot be null"; - int blockItemId = block.field_573_bc - 256; - itemclass.getConstructor(int.class).newInstance(blockItemId); - } - catch (Exception e) - { - //HMMM - } + instance.registerBlock(block, itemclass); } public static void registerEntityID(Class entityClass, String entityName, int id) { - EntityList.addNewEntityListMapping(entityClass, entityName, id); + instance.registerEntityID(entityClass, entityName, id); } public static void registerEntityID(Class entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour) { - EntityList.addNewEntityListMapping(entityClass, entityName, id, backgroundEggColour, foregroundEggColour); + instance.registerEntityID(entityClass, entityName, id, backgroundEggColour, foregroundEggColour); } public static void registerTileEntity(Class tileEntityClass, String id) { - TileEntity.addNewTileEntityMapping(tileEntityClass, id); + instance.registerTileEntity(tileEntityClass, id); } public static void addBiome(BiomeGenBase biome) { - //NOOP because the implementation idea is broken. Creating a BiomeGenBase adds the biome already. + instance.addBiome(biome); } public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) { - for (BiomeGenBase biome : biomes) - { - @SuppressWarnings("unchecked") - List spawns = biome.func_25055_a(typeOfCreature); - - for (SpawnListEntry entry : spawns) - { - //Adjusting an existing spawn entry - if (entry.field_25145_a == entityClass) - { - entry.field_35483_d = weightedProb; - entry.field_35484_b = min; - entry.field_35485_c = max; - break; - } - } - - spawns.add(new SpawnListEntry(entityClass, weightedProb, min, max)); - } + instance.addSpawn(entityClass, weightedProb, min, max, typeOfCreature, biomes); } @SuppressWarnings("unchecked") public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { - Class entityClazz = EntityList.getEntityToClassMapping().get(entityName); - - if (EntityLiving.class.isAssignableFrom(entityClazz)) - { - addSpawn((Class ) entityClazz, weightedProb, min, max, spawnList, biomes); - } + instance.addSpawn(entityName, weightedProb, min, max, spawnList, biomes); } public static void removeBiome(BiomeGenBase biome) { - // NOOP because broken + instance.removeBiome(biome); } public static void removeSpawn(Class entityClass, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) { - for (BiomeGenBase biome : biomes) - { - @SuppressWarnings("unchecked") - List spawns = biome.func_25055_a(typeOfCreature); - - for (SpawnListEntry entry : Collections.unmodifiableList(spawns)) - { - if (entry.field_25145_a == entityClass) - { - spawns.remove(entry); - } - } - } + instance.removeSpawn(entityClass, typeOfCreature, biomes); } @SuppressWarnings("unchecked") public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) { - Class entityClazz = EntityList.getEntityToClassMapping().get(entityName); - - if (EntityLiving.class.isAssignableFrom(entityClazz)) - { - removeSpawn((Class ) entityClazz, spawnList, biomes); - } + instance.removeSpawn(entityName, spawnList, biomes); } } diff --git a/fml/common/net/minecraft/src/IMinecraftRegistry.java b/fml/common/net/minecraft/src/IMinecraftRegistry.java new file mode 100644 index 000000000..cc17c0465 --- /dev/null +++ b/fml/common/net/minecraft/src/IMinecraftRegistry.java @@ -0,0 +1,34 @@ +package net.minecraft.src; + +public interface IMinecraftRegistry +{ + + public abstract void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes); + + public abstract void removeSpawn(Class entityClass, EnumCreatureType typeOfCreature, BiomeGenBase... biomes); + + public abstract void removeBiome(BiomeGenBase biome); + + public abstract void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes); + + public abstract void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, BiomeGenBase... biomes); + + public abstract void addBiome(BiomeGenBase biome); + + public abstract void registerTileEntity(Class tileEntityClass, String id); + + public abstract void registerEntityID(Class entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour); + + public abstract void registerEntityID(Class entityClass, String entityName, int id); + + public abstract void registerBlock(Block block, Class itemclass); + + public abstract void registerBlock(Block block); + + public abstract void addSmelting(int input, ItemStack output); + + public abstract void addShapelessRecipe(ItemStack output, Object... params); + + public abstract void addRecipe(ItemStack output, Object... params); + +} \ No newline at end of file diff --git a/fml/eclipse/.metadata/.plugins/org.eclipse.core.resources/.snap b/fml/eclipse/.metadata/.plugins/org.eclipse.core.resources/.snap index e3ccec7a447fbb3dfddcc7373add7e0fc1100548..528faa982d89769049c17fb4353598a74cb9f054 100644 GIT binary patch delta 2228 zcmbtW%S%*I7{4#?cr-zs(W{f@ObXt{5?Z8-iin^n6s=%Th+wd(v{afA%Zy%LrH7@K zb$VE%|3J*5g^&vijDi+n*}}Bfs)e+XAZXKf?mg$8>pUv(Eao2XeBU|W@Av(F-?%hW z`QuCFMME?sLpBs6!%z*Ek@*xYeZ%n*v^H-@Sg|rTK2d@MR{w^jzAu^+5!~Ht-*9 zll_oTU>&O-;#e-EZJUzRHUrXS>j*tX+gQti1eVJogH&yDoIR{@XeCt>WgjF`pmGHO zjan++F^9bP%_0i$cBxemO53H5;rJ`5Dqp_`?;K0bCwBDXnV6E7?6TmIUskMs8=fw@ zf4H)j<9@Z+7u?DGNLCIbscnvMKpU*JS0msMhBC=y}9@}uRsh6fe5j}^T%`5>G ztpc2>7dn3wa9V0`hi6d$zgvX=0GdD2Uutu3QC#YzjSKBbbpjOoFVRdl{a!Ag5f{8^@bM47N!>F7M2#)7Pc1l7LF~PZyo^vrV itemclass) + { + try + { + assert block != null : "registerBlock: block cannot be null"; + assert itemclass != null : "registerBlock: itemclass cannot be null"; + int blockItemId = block.field_573_bc - 256; + itemclass.getConstructor(int.class).newInstance(blockItemId); + } + catch (Exception e) + { + //HMMM + } + } + + @Override + public void registerEntityID(Class entityClass, String entityName, int id) + { + EntityList.addNewEntityListMapping(entityClass, entityName, id); + } + + @Override + public void registerEntityID(Class entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour) + { + EntityList.addNewEntityListMapping(entityClass, entityName, id, backgroundEggColour, foregroundEggColour); + } + + @Override + public void registerTileEntity(Class tileEntityClass, String id) + { + TileEntity.addNewTileEntityMapping(tileEntityClass, id); + } + + @Override + public void addBiome(BiomeGenBase biome) + { + //NOOP because the implementation idea is broken. Creating a BiomeGenBase adds the biome already. + } + + @Override + public void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) + { + for (BiomeGenBase biome : biomes) + { + @SuppressWarnings("unchecked") + List spawns = biome.func_25055_a(typeOfCreature); + + for (SpawnListEntry entry : spawns) + { + //Adjusting an existing spawn entry + if (entry.field_25145_a == entityClass) + { + entry.field_35483_d = weightedProb; + entry.field_35484_b = min; + entry.field_35485_c = max; + break; + } + } + + spawns.add(new SpawnListEntry(entityClass, weightedProb, min, max)); + } + } + + @Override + @SuppressWarnings("unchecked") + public void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) + { + Class entityClazz = EntityList.getEntityToClassMapping().get(entityName); + + if (EntityLiving.class.isAssignableFrom(entityClazz)) + { + addSpawn((Class ) entityClazz, weightedProb, min, max, spawnList, biomes); + } + } + + @Override + public void removeBiome(BiomeGenBase biome) + { + // NOOP because broken + } + + @Override + public void removeSpawn(Class entityClass, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) + { + for (BiomeGenBase biome : biomes) + { + @SuppressWarnings("unchecked") + List spawns = biome.func_25055_a(typeOfCreature); + + for (SpawnListEntry entry : Collections.unmodifiableList(spawns)) + { + if (entry.field_25145_a == entityClass) + { + spawns.remove(entry); + } + } + } + } + + @Override + @SuppressWarnings("unchecked") + public void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) + { + Class entityClazz = EntityList.getEntityToClassMapping().get(entityName); + + if (EntityLiving.class.isAssignableFrom(entityClazz)) + { + removeSpawn((Class ) entityClazz, spawnList, biomes); + } + } + +}