diff --git a/common/cpw/mods/fml/common/FMLHooks.java b/common/cpw/mods/fml/common/FMLHooks.java index b5f1331af2..1bb71e8888 100644 --- a/common/cpw/mods/fml/common/FMLHooks.java +++ b/common/cpw/mods/fml/common/FMLHooks.java @@ -15,17 +15,24 @@ package cpw.mods.fml.common; -public enum FMLHooks { - INSTANCE; - public void serverTickStart() { +public class FMLHooks { + private static final FMLHooks INSTANCE=new FMLHooks(); + public void gameTickStart() { for (ModContainer mod : Loader.getModList()) { mod.tickStart(); } } - public void serverTickEnd() { + public void gameTickEnd() { for (ModContainer mod : Loader.getModList()) { mod.tickEnd(); } } + + /** + * @return the instance + */ + public static FMLHooks instance() { + return INSTANCE; + } } diff --git a/common/cpw/mods/fml/common/FMLModContainer.java b/common/cpw/mods/fml/common/FMLModContainer.java index f1b90f6dad..77184e7a48 100644 --- a/common/cpw/mods/fml/common/FMLModContainer.java +++ b/common/cpw/mods/fml/common/FMLModContainer.java @@ -12,6 +12,9 @@ */ package cpw.mods.fml.common; +import java.util.ArrayList; +import java.util.List; + public class FMLModContainer implements ModContainer { private Mod modDescriptor; private Object modInstance; @@ -141,4 +144,49 @@ public class FMLModContainer implements ModContainer { return null; } + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#wantsCraftingNotification() + */ + @Override + public boolean wantsCraftingNotification() { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getCraftingHandler() + */ + @Override + public ICraftingHandler getCraftingHandler() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getDependencies() + */ + @Override + public List getDependencies() { + // TODO Auto-generated method stub + return new ArrayList(0); + } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getPreDepends() + */ + @Override + public List getPreDepends() { + // TODO Auto-generated method stub + return new ArrayList(0); + } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getPostDepends() + */ + @Override + public List getPostDepends() { + // TODO Auto-generated method stub + return new ArrayList(0); + } + } diff --git a/common/cpw/mods/fml/common/ICraftingHandler.java b/common/cpw/mods/fml/common/ICraftingHandler.java new file mode 100644 index 0000000000..44d0cce07a --- /dev/null +++ b/common/cpw/mods/fml/common/ICraftingHandler.java @@ -0,0 +1,34 @@ +/* + * The FML Forge Mod Loader suite. + * Copyright (C) 2012 cpw + * + * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +package cpw.mods.fml.common; + +/** + * @author cpw + * + */ +public interface ICraftingHandler { + + /** + * @param player + * @param craftedItem + * @param craftingGrid + */ + void onCrafting(Object... craftingParameters); + + /** + * @param player + * @param smeltedItem + */ + void onSmelting(Object... smeltingParameters); +} diff --git a/common/cpw/mods/fml/common/Loader.java b/common/cpw/mods/fml/common/Loader.java index b0c9562f19..8ca6b7cbe7 100644 --- a/common/cpw/mods/fml/common/Loader.java +++ b/common/cpw/mods/fml/common/Loader.java @@ -78,7 +78,14 @@ public class Loader { } private void sortModList() { - // NOOP for a minute + for (ModContainer mod : mods) { + if (!namedMods.keySet().containsAll(mod.getDependencies())) { + log.severe(String.format("The mod %s requires mods %s to be available, one or more are not", mod.getName(),mod.getDependencies())); + LoaderException le=new LoaderException(); + log.throwing("Loader", "sortModList", le); + throw new LoaderException(); + } + } } private void preModInit() { @@ -207,9 +214,9 @@ public class Loader { if (clazz.isAnnotationPresent(Mod.class)) { // an FML mod mods.add(FMLModContainer.buildFor(clazz)); - } else if (FMLHandler.INSTANCE.isModLoaderMod(clazz)) { + } else if (FMLHandler.instance().isModLoaderMod(clazz)) { log.fine(String.format("ModLoader BaseMod class %s found, loading", clazzName)); - ModContainer mc=FMLHandler.INSTANCE.loadBaseModMod(clazz,classSource.getCanonicalPath()); + ModContainer mc=FMLHandler.instance().loadBaseModMod(clazz,classSource.getCanonicalPath()); mods.add(mc); log.fine(String.format("ModLoader BaseMod class %s loaded", clazzName)); } else { @@ -267,10 +274,10 @@ public class Loader { mods = new ArrayList(); namedMods = new HashMap(); load(); + preModInit(); sortModList(); // Make mod list immutable mods=Collections.unmodifiableList(mods); - preModInit(); } public void initializeMods() { diff --git a/common/cpw/mods/fml/common/ModContainer.java b/common/cpw/mods/fml/common/ModContainer.java index 29fc16a704..19d70f1008 100644 --- a/common/cpw/mods/fml/common/ModContainer.java +++ b/common/cpw/mods/fml/common/ModContainer.java @@ -13,6 +13,8 @@ */ package cpw.mods.fml.common; +import java.util.List; + public interface ModContainer { @@ -34,4 +36,9 @@ public interface ModContainer { IPickupNotifier getPickupNotifier(); boolean wantsToDispense(); IDispenseHandler getDispenseHandler(); + boolean wantsCraftingNotification(); + ICraftingHandler getCraftingHandler(); + List getDependencies(); + List getPreDepends(); + List getPostDepends(); } diff --git a/server/cpw/mods/fml/server/ReflectionHelper.java b/common/cpw/mods/fml/common/ReflectionHelper.java similarity index 97% rename from server/cpw/mods/fml/server/ReflectionHelper.java rename to common/cpw/mods/fml/common/ReflectionHelper.java index 83feaa4e96..5635706d4b 100644 --- a/server/cpw/mods/fml/server/ReflectionHelper.java +++ b/common/cpw/mods/fml/common/ReflectionHelper.java @@ -10,10 +10,12 @@ * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -package cpw.mods.fml.server; +package cpw.mods.fml.common; import java.lang.reflect.Field; +import cpw.mods.fml.server.FMLHandler; + public class ReflectionHelper { @SuppressWarnings("unchecked") public static T getPrivateValue(Class classToAccess, E instance, int fieldIndex) { diff --git a/common/net/minecraft/src/CommonRegistry.java b/common/net/minecraft/src/CommonRegistry.java index c036debf02..77d78422b0 100644 --- a/common/net/minecraft/src/CommonRegistry.java +++ b/common/net/minecraft/src/CommonRegistry.java @@ -13,6 +13,8 @@ */ package net.minecraft.src; +import java.util.Collections; +import java.util.List; public class CommonRegistry { public static void addRecipe(ItemStack output, Object... params) { @@ -55,33 +57,56 @@ public class CommonRegistry { } public static void addBiome(BiomeGenBase biome) { + //NOOP because the implementation idea is broken. Creating a BiomeGenBase adds the biome already. } - public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList) { - } - - public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { - } - - public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList) { + 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)); + } } + @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); + } } public static void removeBiome(BiomeGenBase biome) { + // NOOP because broken } - public static void removeSpawn(Class entityClass, EnumCreatureType spawnList) { - } - - public static void removeSpawn(Class entityClass, EnumCreatureType spawnList, BiomeGenBase... biomes) { - } - - public static void removeSpawn(String entityName, EnumCreatureType spawnList) { + 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); + } + } + } } + @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); + } } } diff --git a/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch b/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch index f09b946f30..8cd4b2a4f8 100644 --- a/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch +++ b/patches/minecraft_server/net/minecraft/server/MinecraftServer.java.patch @@ -13,7 +13,7 @@ var1.start(); ConsoleLogManager.func_641_a(); field_6038_a.info("Starting minecraft server version 1.2.5"); -+ FMLHandler.INSTANCE.onPreLoad(this); ++ FMLHandler.instance().onPreLoad(this); if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L) { @@ -21,7 +21,7 @@ field_6038_a.warning("To change this, set \"online-mode\" to \"true\" in the server.settings file."); } -+ FMLHandler.INSTANCE.onLoadComplete(); ++ FMLHandler.instance().onLoadComplete(); this.field_6033_f = new ServerConfigurationManager(this); this.field_6028_k[0] = new EntityTracker(this, 0); this.field_6028_k[1] = new EntityTracker(this, -1); @@ -29,7 +29,7 @@ var7 = 0L; } -+ FMLHandler.INSTANCE.onPreTick(); ++ FMLHandler.instance().onPreTick(); var3 += var7; var1 = var5; @@ -37,7 +37,7 @@ this.func_6018_h(); } } -+ FMLHandler.INSTANCE.onPostTick(); ++ FMLHandler.instance().onPostTick(); } } else diff --git a/patches/minecraft_server/net/minecraft/src/BlockDispenser.java.patch b/patches/minecraft_server/net/minecraft/src/BlockDispenser.java.patch index 1d21ff9861..7487bf86b0 100644 --- a/patches/minecraft_server/net/minecraft/src/BlockDispenser.java.patch +++ b/patches/minecraft_server/net/minecraft/src/BlockDispenser.java.patch @@ -14,7 +14,7 @@ else { - if (var12.field_855_c == Item.field_4148_j.field_234_aS) -+ if (FMLHandler.INSTANCE.tryDispensingEntity(p_21036_1_, var13, var15, var17, var9, var10, var12)) { ++ if (FMLHandler.instance().tryDispensingEntity(p_21036_1_, var13, var15, var17, var9, var10, var12)) { + ; + } + else if (var12.field_855_c == Item.field_4148_j.field_234_aS) diff --git a/patches/minecraft_server/net/minecraft/src/ChunkProviderServer.java.patch b/patches/minecraft_server/net/minecraft/src/ChunkProviderServer.java.patch index e5a1c322ba..d8b6ccbf34 100644 --- a/patches/minecraft_server/net/minecraft/src/ChunkProviderServer.java.patch +++ b/patches/minecraft_server/net/minecraft/src/ChunkProviderServer.java.patch @@ -13,7 +13,7 @@ if (this.field_730_c != null) { this.field_730_c.func_4055_a(p_4055_1_, p_4055_2_, p_4055_3_); -+ FMLHandler.INSTANCE.onChunkPopulate(p_4055_1_, p_4055_2_, p_4055_3_, this.field_726_g, this.field_730_c); ++ FMLHandler.instance().onChunkPopulate(p_4055_1_, p_4055_2_, p_4055_3_, this.field_726_g, this.field_730_c); var4.func_336_e(); } } diff --git a/patches/minecraft_server/net/minecraft/src/Entity.java.patch b/patches/minecraft_server/net/minecraft/src/Entity.java.patch new file mode 100644 index 0000000000..96164c5906 --- /dev/null +++ b/patches/minecraft_server/net/minecraft/src/Entity.java.patch @@ -0,0 +1,11 @@ +--- src-reference/minecraft_server/net/minecraft/src/Entity.java 0000-00-00 00:00:00.000000000 -0000 ++++ src-work/minecraft_server/net/minecraft/src/Entity.java 0000-00-00 00:00:00.000000000 -0000 +@@ -1463,4 +1463,8 @@ + { + return true; + } ++ ++ public static int getNextId() { ++ return field_384_a++; ++ } + } diff --git a/patches/minecraft_server/net/minecraft/src/EntityItem.java.patch b/patches/minecraft_server/net/minecraft/src/EntityItem.java.patch index 52706f573c..0ff53c4be8 100644 --- a/patches/minecraft_server/net/minecraft/src/EntityItem.java.patch +++ b/patches/minecraft_server/net/minecraft/src/EntityItem.java.patch @@ -12,7 +12,7 @@ if (this.field_433_ad == 0 && p_6093_1_.field_416_aj.func_201_a(this.field_429_a)) { -+ FMLHandler.INSTANCE.notifyItemPickup(this,p_6093_1_); ++ FMLHandler.instance().notifyItemPickup(this,p_6093_1_); if (this.field_429_a.field_855_c == Block.field_582_K.field_573_bc) { p_6093_1_.func_27017_a(AchievementList.field_25131_c); diff --git a/patches/minecraft_server/net/minecraft/src/EntityList.java.patch b/patches/minecraft_server/net/minecraft/src/EntityList.java.patch index bd1bd9a496..6672ee6eb6 100644 --- a/patches/minecraft_server/net/minecraft/src/EntityList.java.patch +++ b/patches/minecraft_server/net/minecraft/src/EntityList.java.patch @@ -1,6 +1,6 @@ --- src-reference/minecraft_server/net/minecraft/src/EntityList.java 0000-00-00 00:00:00.000000000 -0000 +++ src-work/minecraft_server/net/minecraft/src/EntityList.java 0000-00-00 00:00:00.000000000 -0000 -@@ -166,4 +166,12 @@ +@@ -166,4 +166,17 @@ func_46122_a(EntityVillager.class, "Villager", 120, 5651507, 12422002); func_563_a(EntityEnderCrystal.class, "EnderCrystal", 200); } @@ -11,5 +11,10 @@ + + public static void addNewEntityListMapping(Class entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour) { + func_46122_a(entityClass,entityName,id,backgroundEggColour,foregroundEggColour); ++ } ++ ++ @SuppressWarnings("unchecked") ++ public static Map> getEntityToClassMapping() { ++ return field_849_a; + } } diff --git a/patches/minecraft_server/net/minecraft/src/TileEntityFurnace.java.patch b/patches/minecraft_server/net/minecraft/src/TileEntityFurnace.java.patch index 34c5597518..bd91835307 100644 --- a/patches/minecraft_server/net/minecraft/src/TileEntityFurnace.java.patch +++ b/patches/minecraft_server/net/minecraft/src/TileEntityFurnace.java.patch @@ -13,7 +13,7 @@ { int var1 = p_194_1_.func_569_a().field_234_aS; - return var1 < 256 && Block.field_542_n[var1].field_553_bn == Material.field_524_c ? 300 : (var1 == Item.field_209_B.field_234_aS ? 100 : (var1 == Item.field_168_k.field_234_aS ? 1600 : (var1 == Item.field_201_aw.field_234_aS ? 20000 : (var1 == Block.field_6047_y.field_573_bc ? 100 : (var1 == Item.field_40239_bm.field_234_aS ? 2400 : 0))))); -+ return var1 < 256 && Block.field_542_n[var1].field_553_bn == Material.field_524_c ? 300 : (var1 == Item.field_209_B.field_234_aS ? 100 : (var1 == Item.field_168_k.field_234_aS ? 1600 : (var1 == Item.field_201_aw.field_234_aS ? 20000 : (var1 == Block.field_6047_y.field_573_bc ? 100 : (var1 == Item.field_40239_bm.field_234_aS ? 2400 : FMLHandler.INSTANCE.fuelLookup(var1, p_194_1_.func_21125_h())))))); ++ return var1 < 256 && Block.field_542_n[var1].field_553_bn == Material.field_524_c ? 300 : (var1 == Item.field_209_B.field_234_aS ? 100 : (var1 == Item.field_168_k.field_234_aS ? 1600 : (var1 == Item.field_201_aw.field_234_aS ? 20000 : (var1 == Block.field_6047_y.field_573_bc ? 100 : (var1 == Item.field_40239_bm.field_234_aS ? 2400 : FMLHandler.instance().fuelLookup(var1, p_194_1_.func_21125_h())))))); } } diff --git a/server/cpw/mods/fml/server/FMLHandler.java b/server/cpw/mods/fml/server/FMLHandler.java index 18fc13cdb0..cc5ed5785b 100644 --- a/server/cpw/mods/fml/server/FMLHandler.java +++ b/server/cpw/mods/fml/server/FMLHandler.java @@ -12,6 +12,7 @@ */ package cpw.mods.fml.server; +import java.util.ArrayList; import java.util.Random; import java.util.logging.Logger; @@ -21,18 +22,23 @@ import cpw.mods.fml.common.ModContainer; import net.minecraft.server.MinecraftServer; import net.minecraft.src.BaseMod; +import net.minecraft.src.BiomeGenBase; import net.minecraft.src.EntityItem; import net.minecraft.src.EntityPlayer; import net.minecraft.src.IChunkProvider; +import net.minecraft.src.IInventory; import net.minecraft.src.ItemStack; import net.minecraft.src.World; -public enum FMLHandler { - INSTANCE; +public class FMLHandler { + private static final FMLHandler INSTANCE=new FMLHandler(); + private MinecraftServer server; + private BiomeGenBase[] defaultOverworldBiomes; + public void onPreLoad(MinecraftServer minecraftServer) { - INSTANCE.server = minecraftServer; + server = minecraftServer; Loader.instance().loadMods(); } @@ -41,11 +47,11 @@ public enum FMLHandler { } public void onPreTick() { - FMLHooks.INSTANCE.serverTickStart(); + FMLHooks.instance().gameTickStart(); } public void onPostTick() { - FMLHooks.INSTANCE.serverTickEnd(); + FMLHooks.instance().gameTickEnd(); } public MinecraftServer getServer() { @@ -123,4 +129,45 @@ public enum FMLHandler { } return false; } + + /** + * @return the instance + */ + public static FMLHandler instance() { + return INSTANCE; + } + + /** + * @return + */ + public BiomeGenBase[] getDefaultOverworldBiomes() { + if (defaultOverworldBiomes==null) { + ArrayList biomes=new ArrayList(20); + for (int i=0; i<23; i++) { + if ("Sky".equals(BiomeGenBase.field_35521_a[i].field_6163_m) || "Hell".equals(BiomeGenBase.field_35521_a[i].field_6163_m)) { + continue; + } + biomes.add(BiomeGenBase.field_35521_a[i]); + } + defaultOverworldBiomes=new BiomeGenBase[biomes.size()]; + biomes.toArray(defaultOverworldBiomes); + } + return defaultOverworldBiomes; + } + + public void onItemCrafted(EntityPlayer player, ItemStack craftedItem, IInventory craftingGrid) { + for (ModContainer mod : Loader.getModList()) { + if (mod.wantsCraftingNotification()) { + mod.getCraftingHandler().onCrafting(player,craftedItem,craftingGrid); + } + } + } + + public void onItemSmelted(EntityPlayer player, ItemStack smeltedItem) { + for (ModContainer mod : Loader.getModList()) { + if (mod.wantsCraftingNotification()) { + mod.getCraftingHandler().onSmelting(player,smeltedItem); + } + } + } } diff --git a/server/cpw/mods/fml/server/ModLoaderModContainer.java b/server/cpw/mods/fml/server/ModLoaderModContainer.java index a5710b6763..8c57058564 100644 --- a/server/cpw/mods/fml/server/ModLoaderModContainer.java +++ b/server/cpw/mods/fml/server/ModLoaderModContainer.java @@ -14,9 +14,12 @@ package cpw.mods.fml.server; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.StringTokenizer; import net.minecraft.src.BaseMod; +import cpw.mods.fml.common.ICraftingHandler; import cpw.mods.fml.common.IDispenseHandler; import cpw.mods.fml.common.IPickupNotifier; import cpw.mods.fml.common.IWorldGenerator; @@ -64,7 +67,7 @@ public class ModLoaderModContainer implements ModContainer { @Override public void tickStart() { if (isTicking) { - isTicking=mod.onTickInGame(FMLHandler.INSTANCE.getServer()); + isTicking=mod.onTickInGame(FMLHandler.instance().getServer()); } } @Override @@ -155,4 +158,55 @@ public class ModLoaderModContainer implements ModContainer { public IDispenseHandler getDispenseHandler() { return mod; } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#wantsCraftingNotification() + */ + @Override + public boolean wantsCraftingNotification() { + return true; + } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getCraftingHandler() + */ + @Override + public ICraftingHandler getCraftingHandler() { + return mod; + } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getDependencies() + */ + @Override + public List getDependencies() { + ArrayList dependencies=new ArrayList(10); + if (mod.getPriorities()==null || mod.getPriorities().length()==0) { + return dependencies; + } + StringTokenizer st=new StringTokenizer(mod.getPriorities(),";"); + for (; st.hasMoreTokens(); ) { + String dep=st.nextToken(); + String[] depparts=dep.split(":"); + if (depparts.length<2) { + throw new LoaderException(); + } + if ("required-before".equals(depparts[0]) || "required-after".equals(depparts[0])) { + dependencies.add(depparts[1]); + } + } + return dependencies; + } + + @Override + public List getPreDepends() { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getPostDepends() { + // TODO Auto-generated method stub + return null; + } } diff --git a/server/net/minecraft/src/BaseMod.java b/server/net/minecraft/src/BaseMod.java index a413d7c376..899ba2aaf0 100644 --- a/server/net/minecraft/src/BaseMod.java +++ b/server/net/minecraft/src/BaseMod.java @@ -15,23 +15,26 @@ package net.minecraft.src; import java.util.Random; import net.minecraft.server.MinecraftServer; +import cpw.mods.fml.common.ICraftingHandler; import cpw.mods.fml.common.IDispenseHandler; import cpw.mods.fml.common.IPickupNotifier; import cpw.mods.fml.common.IWorldGenerator; -public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler { - public int addFuel(int id, int metadata) { - return 0; +public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler { + // CALLBACK MECHANISMS + @Override + public void onCrafting(Object... craftingParameters) { + takenFromCrafting((EntityPlayer)craftingParameters[0], (ItemStack)craftingParameters[1], (IInventory)craftingParameters[2]); } + @Override + public void onSmelting(Object... smeltingParameters) { + takenFromFurnace((EntityPlayer)smeltingParameters[0], (ItemStack)smeltingParameters[1]); + } @Override public boolean dispense(double x, double y, double z, byte xVelocity, byte zVelocity, Object... data) { return dispenseEntity((World)data[0], x, y, z, xVelocity, zVelocity, (ItemStack)data[1]); } - - public boolean dispenseEntity(World world, double x, double y, double z, int xVel, int zVel, ItemStack item) { - return false; - } @Override public void notifyPickup(Object... pickupData) { @@ -52,27 +55,90 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp } } + // BASEMOD API + /** + * Override if you wish to provide a fuel item for the furnace and return the fuel value of the item + * @param id + * @param metadata + * @return + */ + public int addFuel(int id, int metadata) { + return 0; + } + + /** + * Override if you wish to perform some action other than just dispensing the item from the dispenser + * @param world + * @param x + * @param y + * @param z + * @param xVel + * @param zVel + * @param item + * @return + */ + public boolean dispenseEntity(World world, double x, double y, double z, int xVel, int zVel, ItemStack item) { + return false; + } + + /** + * Override if you wish to generate Nether (Hell biome) blocks + * @param world + * @param random + * @param chunkX + * @param chunkZ + */ public void generateNether(World world, Random random, int chunkX, int chunkZ) { } + /** + * Override if you wish to generate Overworld (not hell or the end) blocks + * @param world + * @param random + * @param chunkX + * @param chunkZ + */ public void generateSurface(World world, Random random, int chunkX, int chunkZ) { } + /** + * Return the name of your mod. Defaults to the class name + * @return + */ public String getName() { return getClass().getSimpleName(); } + /** + * Get your mod priorities + * @return + */ public String getPriorities() { return null; } + /** + * Return the version of your mod + * @return + */ public abstract String getVersion(); + /** + * Load your mod + */ public abstract void load(); + /** + * Finish loading your mod + */ public void modsLoaded() { } + /** + * Handle item pickup + * @param player + * @param item + */ public void onItemPickup(EntityPlayer player, ItemStack item) { } @@ -85,28 +151,55 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp return false; } + /** + * Not implemented because on the server you don't know who it's from + * @param text + */ + @Deprecated public void receiveChatPacket(String text) { } + /** + * Not implemented because on the server you don't know who it's from + * @param packet + */ + @Deprecated public void receiveCustomPacket(Packet250CustomPayload packet) { } + /** + * Called when someone crafts an item from a crafting table + * @param player + * @param item + * @param matrix + */ public void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix) { } + /** + * Called when someone takes a smelted item from a furnace + * + * @param player + * @param item + */ public void takenFromFurnace(EntityPlayer player, ItemStack item) { } + /** + * The identifier string for the mod- used in client<->server negotiation + */ + @Override + public String toString() { + return getName()+" "+getVersion(); + } + + // Spare client junk + // ------- // void addRenderer(Map, Render> renderers); // void registerAnimation(Minecraft game); // void renderInvBlock(RenderBlocks renderer, Block block, int metadata, int modelID); // boolean renderWorldBlock(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, Block block, int modelID); // boolean onTickInGUI(float tick, Minecraft game, GuiScreen gui); // void keyboardEvent(KeyBinding event); - - @Override - public String toString() { - return getName()+" "+getVersion(); - } } diff --git a/server/net/minecraft/src/ModLoader.java b/server/net/minecraft/src/ModLoader.java index 0f6fc325dd..df16c573e2 100644 --- a/server/net/minecraft/src/ModLoader.java +++ b/server/net/minecraft/src/ModLoader.java @@ -16,9 +16,9 @@ import java.util.List; import java.util.logging.Logger; import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ReflectionHelper; import cpw.mods.fml.server.FMLHandler; import cpw.mods.fml.server.ModLoaderModContainer; -import cpw.mods.fml.server.ReflectionHelper; import net.minecraft.server.MinecraftServer; @@ -38,147 +38,386 @@ import net.minecraft.src.TileEntity; import net.minecraft.src.World; public class ModLoader { + /** + * + * @param achievement + * @param name + * @param description + */ public static void addAchievementDesc(Achievement achievement, String name, String description) { + // NOOP on the server?? } + /** + * This method is a call in hook from modified external code. Implemented elsewhere. + * @param id + * @param metadata + * @return + */ + @Deprecated public static int addAllFuel(int id, int metadata) { return 0; } + /** + * This method has been unimplemented in server implementations for some time. + * + * @param armor + * @return + */ + @Deprecated public static int addArmor(String armor) { return 0; } + /** + * This method does not work. Creation of a BiomeGenBase is sufficient to populate this array + * + * @param biome + */ + @Deprecated public static void addBiome(BiomeGenBase biome) { } + /** + * Unimplemented on the server as it does not generate names + * @param key + * @param value + */ + @Deprecated public static void addLocalization(String key, String value) { } + /** + * Unimplemented on the server as it does not generate names + * @param key + * @param lang + * @param value + */ + @Deprecated public static void addLocalization(String key, String lang, String value) { } + /** + * Unimplemented on the server as it does not generate names + * @param instance + * @param name + */ + @Deprecated public static void addName(Object instance, String name) { } + /** + * Unimplemented on the server as it does not generate names + * @param instance + * @param lang + * @param name + */ + @Deprecated public static void addName(Object instance, String lang, String name) { } + /** + * Unimplemented on the server as it does not render textures + * @param fileToOverride + * @param fileToAdd + * @return + */ + @Deprecated public static int addOverride(String fileToOverride, String fileToAdd) { return 0; } + /** + * Unimplemented on the server as it does not render textures + * @param path + * @param overlayPath + * @param index + */ + @Deprecated public static void addOverride(String path, String overlayPath, int index) { } + /** + * Add a Shaped Recipe + * @param output + * @param params + */ public static void addRecipe(ItemStack output, Object... params) { CommonRegistry.addRecipe(output, params); } + /** + * Add a shapeless recipe + * @param output + * @param params + */ public static void addShapelessRecipe(ItemStack output, Object... params) { CommonRegistry.addShapelessRecipe(output, params); } + /** + * Add a new product to be smelted + * @param input + * @param output + */ public static void addSmelting(int input, ItemStack output) { CommonRegistry.addSmelting(input, output); } + /** + * Add a mob to the spawn list + * @param entityClass + * @param weightedProb + * @param min + * @param max + * @param spawnList + */ public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList) { - CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList); + CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, FMLHandler.instance().getDefaultOverworldBiomes()); } + /** + * Add a mob to the spawn list + * @param entityClass + * @param weightedProb + * @param min + * @param max + * @param spawnList + * @param biomes + */ public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, biomes); } + /** + * Add a mob to the spawn list + * @param entityName + * @param weightedProb + * @param min + * @param max + * @param spawnList + */ public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList) { - CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList); + CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, FMLHandler.instance().getDefaultOverworldBiomes()); } + /** + * Add a mob to the spawn list + * @param entityName + * @param weightedProb + * @param min + * @param max + * @param spawnList + * @param biomes + */ public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, biomes); } + /** + * This method is a call in hook from modified external code. Implemented elsewhere. + * @param world + * @param x + * @param y + * @param z + * @param xVel + * @param zVel + * @param item + * @return + */ + @Deprecated public static boolean dispenseEntity(World world, double x, double y, double z, int xVel, int zVel, ItemStack item) { return false; } + /** + * Currently unimplemented + * @param world + * @param x + * @param y + * @param z + */ public static void genericContainerRemoval(World world, int x, int y, int z) { } + /** + * Get a list of all BaseMod loaded into the system + * @return + */ public static List getLoadedMods() { return ModLoaderModContainer.findAll(); } + /** + * Get a logger instance + * @return + */ public static Logger getLogger() { return FMLHandler.getFMLLogger(); } + /** + * Get a value from a field using reflection + * @param instanceclass + * @param instance + * @param fieldindex + * @return + */ public static T getPrivateValue(Class instanceclass, E instance, int fieldindex) { return ReflectionHelper.getPrivateValue(instanceclass, instance, fieldindex); } + /** + * Get a value from a field using reflection + * @param instanceclass + * @param instance + * @param field + * @return + */ public static T getPrivateValue(Class instanceclass, E instance, String field) { return ReflectionHelper.getPrivateValue(instanceclass, instance, field); } + /** + * Get a new unique entity id + * @return + */ public static int getUniqueEntityId() { - return 0; + return Entity.getNextId(); } + /** + * Is the named mod loaded? + * @param modname + * @return + */ public static boolean isModLoaded(String modname) { return Loader.isModLoaded(modname); } + /** + * Unimplemented on the server. New code that didn't exist prior to this implementation + * @param packet + */ + @Deprecated public static void receivePacket(Packet250CustomPayload packet) { } + /** + * Register a new block + * @param block + */ public static void registerBlock(Block block) { CommonRegistry.registerBlock(block); } + /** + * Register a new block + * @param block + * @param itemclass + */ public static void registerBlock(Block block, Class itemclass) { CommonRegistry.registerBlock(block, itemclass); } + /** + * Register a new entity ID + * @param entityClass + * @param entityName + * @param id + */ public static void registerEntityID(Class entityClass, String entityName, int id) { CommonRegistry.registerEntityID(entityClass, entityName, id); } + /** + * Register a new entity ID + * @param entityClass + * @param entityName + * @param id + * @param background + * @param foreground + */ public static void registerEntityID(Class entityClass, String entityName, int id, int background, int foreground) { CommonRegistry.registerEntityID(entityClass, entityName, id, background, foreground); } + /** + * Unimplemented at present + * @param mod + * @param channel + */ public static void registerPacketChannel(BaseMod mod, String channel) { } + /** + * Register a new tile entity class + * @param tileEntityClass + * @param id + */ public static void registerTileEntity(Class tileEntityClass, String id) { CommonRegistry.registerTileEntity(tileEntityClass, id); } + /** + * Remove a biome. This code will probably not work correctly. + * @param biome + */ + @Deprecated public static void removeBiome(BiomeGenBase biome) { CommonRegistry.removeBiome(biome); } + /** + * Remove a spawn + * @param entityClass + * @param spawnList + */ public static void removeSpawn(Class entityClass, EnumCreatureType spawnList) { - CommonRegistry.removeSpawn(entityClass, spawnList); + CommonRegistry.removeSpawn(entityClass, spawnList, FMLHandler.instance().getDefaultOverworldBiomes()); } + /** + * Remove a spawn + * @param entityClass + * @param spawnList + * @param biomes + */ public static void removeSpawn(Class entityClass, EnumCreatureType spawnList, BiomeGenBase... biomes) { CommonRegistry.removeSpawn(entityClass, spawnList, biomes); } + /** + * Remove a spawn + * @param entityName + * @param spawnList + */ public static void removeSpawn(String entityName, EnumCreatureType spawnList) { - CommonRegistry.removeSpawn(entityName, spawnList); + CommonRegistry.removeSpawn(entityName, spawnList, FMLHandler.instance().getDefaultOverworldBiomes()); } + /** + * Remove a spawn + * @param entityName + * @param spawnList + * @param biomes + */ public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) { CommonRegistry.removeSpawn(entityName, spawnList, biomes); } + /** + * This implementation of the modloader API does not have "configuration" to save. + */ public static void saveConfig() { } + /** + * This method is unimplemented on the server: it is meant for clients to send chat to the server + * @param text + */ + @Deprecated public static void serverChat(String text) { } @@ -197,25 +436,61 @@ public class ModLoader { mlmc.setTicking(enable); } + /** + * Set a private field to a value using reflection + * @param instanceclass + * @param instance + * @param fieldindex + * @param value + */ public static void setPrivateValue(Class instanceclass, T instance, int fieldindex, E value) { ReflectionHelper.setPrivateValue(instanceclass, instance, fieldindex, value); } - + + /** + * Set a private field to a value using reflection + * @param instanceclass + * @param instance + * @param field + * @param value + */ public static void setPrivateValue(Class instanceclass, T instance, String field, E value) { ReflectionHelper.setPrivateValue(instanceclass, instance, field, value); } + /** + * This method is a call in hook from modified external code. Implemented elsewhere. + * @param player + * @param item + * @param matrix + */ + @Deprecated public static void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix) { } + /** + * This method is a call in hook from modified external code. Implemented elsewhere. + * @param player + * @param item + */ + @Deprecated public static void takenFromFurnace(EntityPlayer player, ItemStack item) { } + /** + * Throw the offered exception. Likely will stop the game. + * @param message + * @param e + */ public static void throwException(String message, Throwable e) { - FMLHandler.INSTANCE.raiseException(e, message, true); + FMLHandler.instance().raiseException(e, message, true); } + /** + * Get the minecraft server instance + * @return + */ public static MinecraftServer getMinecraftServerInstance() { - return FMLHandler.INSTANCE.getServer(); + return FMLHandler.instance().getServer(); } } \ No newline at end of file