From cceeb88c6d6936634f5ac61eafa5b3905aa125ff Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Sat, 14 Apr 2012 23:01:03 -0400 Subject: [PATCH 1/6] Bukkit version --- .../cpw/mods/fml/server/FMLBukkitHandler.java | 487 ++++++++++++++ .../fml/server/ModLoaderModContainer.java | 522 +++++++++++++++ bukkit/net/minecraft/server/BaseMod.java | 325 +++++++++ .../net/minecraft/server/BukkitRegistry.java | 147 +++++ bukkit/net/minecraft/server/MLProp.java | 48 ++ bukkit/net/minecraft/server/ModLoader.java | 617 ++++++++++++++++++ .../cpw/mods/fml/common/IWorldGenerator.java | 2 +- .../{src => server}/CommonRegistry.java | 14 +- .../{src => server}/IMinecraftRegistry.java | 14 +- 9 files changed, 2161 insertions(+), 15 deletions(-) create mode 100644 bukkit/cpw/mods/fml/server/FMLBukkitHandler.java create mode 100644 bukkit/cpw/mods/fml/server/ModLoaderModContainer.java create mode 100644 bukkit/net/minecraft/server/BaseMod.java create mode 100644 bukkit/net/minecraft/server/BukkitRegistry.java create mode 100644 bukkit/net/minecraft/server/MLProp.java create mode 100644 bukkit/net/minecraft/server/ModLoader.java rename common/net/minecraft/{src => server}/CommonRegistry.java (89%) rename common/net/minecraft/{src => server}/IMinecraftRegistry.java (74%) diff --git a/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java b/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java new file mode 100644 index 0000000000..a48abb2297 --- /dev/null +++ b/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java @@ -0,0 +1,487 @@ +/* + * 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.server; + +import java.io.File; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Random; +import java.util.logging.Logger; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.BaseMod; +import net.minecraft.server.BiomeBase; +import net.minecraft.server.CommonRegistry; +import net.minecraft.server.EntityItem; +import net.minecraft.server.EntityHuman; +import net.minecraft.server.EntityPlayer; +import net.minecraft.server.IChunkProvider; +import net.minecraft.server.ICommandListener; +import net.minecraft.server.IInventory; +import net.minecraft.server.ItemStack; +import net.minecraft.server.NetworkManager; +import net.minecraft.server.Packet1Login; +import net.minecraft.server.Packet250CustomPayload; +import net.minecraft.server.Packet3Chat; +import net.minecraft.server.BukkitRegistry; +import net.minecraft.server.World; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.IFMLSidedHandler; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; + +/** + * Handles primary communication from hooked code into the system + * + * The FML entry point is {@link #onPreLoad(MinecraftServer)} called from {@link MinecraftServer} + * + * Obfuscated code should focus on this class and other members of the "server" (or "client") code + * + * The actual mod loading is handled at arms length by {@link Loader} + * + * It is expected that a similar class will exist for each target environment: Bukkit and Client side. + * + * It should not be directly modified. + * + * @author cpw + * + */ +public class FMLBukkitHandler implements IFMLSidedHandler +{ + /** + * The singleton + */ + private static final FMLBukkitHandler INSTANCE = new FMLBukkitHandler(); + + /** + * A reference to the server itself + */ + private MinecraftServer server; + + /** + * A handy list of the default overworld biomes + */ + private BiomeBase[] defaultOverworldBiomes; + + /** + * Called to start the whole game off from {@link MinecraftServer#startServer} + * @param minecraftServer + */ + public void onPreLoad(MinecraftServer minecraftServer) + { + server = minecraftServer; + FMLCommonHandler.instance().registerSidedDelegate(this); + CommonRegistry.registerRegistry(new BukkitRegistry()); + Loader.instance().loadMods(); + } + + /** + * Called a bit later on during server initialization to finish loading mods + */ + public void onLoadComplete() + { + Loader.instance().initializeMods(); + } + + /** + * Every tick just before world and other ticks occur + */ + public void onPreTick() + { + FMLCommonHandler.instance().gameTickStart(); + } + + /** + * Every tick just after world and other ticks occur + */ + public void onPostTick() + { + FMLCommonHandler.instance().gameTickEnd(); + } + + /** + * Get the server instance + * @return + */ + public MinecraftServer getServer() + { + return server; + } + + /** + * Get a handle to the server's logger instance + */ + public Logger getMinecraftLogger() + { + return MinecraftServer.log; + } + + /** + * Called from ChunkProviderServer when a chunk needs to be populated + * + * To avoid polluting the worldgen seed, we generate a new random from the world seed and + * generate a seed from that + * + * @param chunkProvider + * @param chunkX + * @param chunkZ + * @param world + * @param generator + */ + public void onChunkPopulate(IChunkProvider chunkProvider, int chunkX, int chunkZ, World world, IChunkProvider generator) + { + Random fmlRandom = new Random(world.getSeed()); + long xSeed = fmlRandom.nextLong() >> 2 + 1L; + long zSeed = fmlRandom.nextLong() >> 2 + 1L; + fmlRandom.setSeed((xSeed * chunkX + zSeed * chunkZ) ^ world.getSeed()); + + for (ModContainer mod : Loader.getModList()) + { + if (mod.generatesWorld()) + { + mod.getWorldGenerator().generate(fmlRandom, chunkX, chunkZ, world, generator, chunkProvider); + } + } + } + + /** + * Called from the furnace to lookup fuel values + * + * @param itemId + * @param itemDamage + * @return + */ + public int fuelLookup(int itemId, int itemDamage) + { + int fv = 0; + + for (ModContainer mod : Loader.getModList()) + { + fv = Math.max(fv, mod.lookupFuelValue(itemId, itemDamage)); + } + + return fv; + } + + /** + * Is the offered class and instance of BaseMod and therefore a ModLoader mod? + */ + public boolean isModLoaderMod(Class clazz) + { + return BaseMod.class.isAssignableFrom(clazz); + } + + /** + * Load the supplied mod class into a mod container + */ + public ModContainer loadBaseModMod(Class clazz, String canonicalPath) + { + @SuppressWarnings("unchecked") + Class bmClazz = (Class ) clazz; + return new ModLoaderModContainer(bmClazz, canonicalPath); + } + + /** + * Called to notify that an item was picked up from the world + * @param entityItem + * @param entityPlayer + */ + public void notifyItemPickup(EntityItem entityItem, EntityHuman entityPlayer) + { + for (ModContainer mod : Loader.getModList()) + { + if (mod.wantsPickupNotification()) + { + mod.getPickupNotifier().notifyPickup(entityItem, entityPlayer); + } + } + } + + /** + * Raise an exception + * @param exception + * @param message + * @param stopGame + */ + public void raiseException(Throwable exception, String message, boolean stopGame) + { + FMLCommonHandler.instance().getFMLLogger().throwing("FMLHandler", "raiseException", exception); + throw new RuntimeException(exception); + } + + /** + * Attempt to dispense the item as an entity other than just as a the item itself + * + * @param world + * @param x + * @param y + * @param z + * @param xVelocity + * @param zVelocity + * @param item + * @return + */ + public boolean tryDispensingEntity(World world, double x, double y, double z, byte xVelocity, byte zVelocity, ItemStack item) + { + for (ModContainer mod : Loader.getModList()) + { + if (mod.wantsToDispense() && mod.getDispenseHandler().dispense(x, y, z, xVelocity, zVelocity, world, item)) + { + return true; + } + } + + return false; + } + + /** + * @return the instance + */ + public static FMLBukkitHandler instance() + { + return INSTANCE; + } + + /** + * Build a list of default overworld biomes + * @return + */ + public BiomeBase[] getDefaultOverworldBiomes() + { + if (defaultOverworldBiomes == null) + { + ArrayList biomes = new ArrayList(20); + + for (int i = 0; i < 23; i++) + { + if ("Sky".equals(BiomeBase.biomes[i].y) || "Hell".equals(BiomeBase.biomes[i].y)) + { + continue; + } + + biomes.add(BiomeBase.biomes[i]); + } + + defaultOverworldBiomes = new BiomeBase[biomes.size()]; + biomes.toArray(defaultOverworldBiomes); + } + + return defaultOverworldBiomes; + } + + /** + * Called when an item is crafted + * @param player + * @param craftedItem + * @param craftingGrid + */ + public void onItemCrafted(EntityHuman player, ItemStack craftedItem, IInventory craftingGrid) + { + for (ModContainer mod : Loader.getModList()) + { + if (mod.wantsCraftingNotification()) + { + mod.getCraftingHandler().onCrafting(player, craftedItem, craftingGrid); + } + } + } + + /** + * Called when an item is smelted + * + * @param player + * @param smeltedItem + */ + public void onItemSmelted(EntityHuman player, ItemStack smeltedItem) + { + for (ModContainer mod : Loader.getModList()) + { + if (mod.wantsCraftingNotification()) + { + mod.getCraftingHandler().onSmelting(player, smeltedItem); + } + } + } + + /** + * Called when a chat packet is received + * + * @param chat + * @param player + * @return true if you want the packet to stop processing and not echo to the rest of the world + */ + public boolean handleChatPacket(Packet3Chat chat, EntityHuman player) + { + for (ModContainer mod : Loader.getModList()) + { + if (mod.wantsNetworkPackets() && mod.getNetworkHandler().onChat(chat, player)) + { + return true; + } + } + + return false; + } + + /** + * Called when a packet 250 packet is received from the player + * @param packet + * @param player + */ + public void handlePacket250(Packet250CustomPayload packet, EntityHuman player) + { + if ("REGISTER".equals(packet.tag) || "UNREGISTER".equals(packet.tag)) + { + handleClientRegistration(packet, player); + return; + } + + ModContainer mod = FMLCommonHandler.instance().getModForChannel(packet.tag); + + if (mod != null) + { + mod.getNetworkHandler().onPacket250Packet(packet, player); + } + } + + /** + * Handle register requests for packet 250 channels + * @param packet + */ + private void handleClientRegistration(Packet250CustomPayload packet, EntityHuman player) + { + if (packet.data==null) { + return; + } + try + { + for (String channel : new String(packet.data, "UTF8").split("\0")) + { + // Skip it if we don't know it + if (FMLCommonHandler.instance().getModForChannel(channel) == null) + { + continue; + } + + if ("REGISTER".equals(packet.tag)) + { + FMLCommonHandler.instance().activateChannel(player, channel); + } + else + { + FMLCommonHandler.instance().deactivateChannel(player, channel); + } + } + } + catch (UnsupportedEncodingException e) + { + getMinecraftLogger().warning("Received invalid registration packet"); + } + } + + /** + * Handle a login + * @param loginPacket + * @param networkManager + */ + public void handleLogin(Packet1Login loginPacket, NetworkManager networkManager) + { + Packet250CustomPayload packet = new Packet250CustomPayload(); + packet.tag = "REGISTER"; + packet.data = FMLCommonHandler.instance().getPacketRegistry(); + packet.length = packet.data.length; + if (packet.length>0) { + networkManager.queue(packet); + } + } + + public void announceLogin(EntityHuman player) { + for (ModContainer mod : Loader.getModList()) + { + if (mod.wantsPlayerTracking()) + { + mod.getPlayerTracker().onPlayerLogin(player); + } + } + } + /** + * Are we a server? + */ + @Override + public boolean isServer() + { + return true; + } + + /** + * Are we a client? + */ + @Override + public boolean isClient() + { + return false; + } + + @Override + public File getMinecraftRootDirectory() + { + try { + return server.a(".").getCanonicalFile(); + } catch (IOException ioe) { + return new File("."); + } + } + + /** + * @param var2 + * @return + */ + public boolean handleServerCommand(String command, String player, ICommandListener listener) + { + for (ModContainer mod : Loader.getModList()) { + if (mod.wantsConsoleCommands() && mod.getConsoleHandler().handleCommand(command, player, listener)) { + return true; + } + } + return false; + } + + /** + * @param player + */ + public void announceLogout(EntityHuman player) + { + for (ModContainer mod : Loader.getModList()) + { + if (mod.wantsPlayerTracking()) + { + mod.getPlayerTracker().onPlayerLogout(player); + } + } + } + + /** + * @param p_28168_1_ + */ + public void announceDimensionChange(EntityHuman player) + { + for (ModContainer mod : Loader.getModList()) + { + if (mod.wantsPlayerTracking()) + { + mod.getPlayerTracker().onPlayerChangedDimension(player); + } + } + } +} diff --git a/bukkit/cpw/mods/fml/server/ModLoaderModContainer.java b/bukkit/cpw/mods/fml/server/ModLoaderModContainer.java new file mode 100644 index 0000000000..7dc41121f0 --- /dev/null +++ b/bukkit/cpw/mods/fml/server/ModLoaderModContainer.java @@ -0,0 +1,522 @@ +/* + * 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.server; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.StringTokenizer; + +import net.minecraft.server.BaseMod; +import net.minecraft.server.MLProp; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.IConsoleHandler; +import cpw.mods.fml.common.ICraftingHandler; +import cpw.mods.fml.common.IDispenseHandler; +import cpw.mods.fml.common.INetworkHandler; +import cpw.mods.fml.common.IPickupNotifier; +import cpw.mods.fml.common.IPlayerTracker; +import cpw.mods.fml.common.IWorldGenerator; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.LoaderException; +import cpw.mods.fml.common.ModContainer; + +public class ModLoaderModContainer implements ModContainer +{ + private Class modClazz; + private BaseMod mod; + private boolean isTicking; + private String modSource ; + private ArrayList dependencies; + private ArrayList preDependencies; + private ArrayList postDependencies; + public ModLoaderModContainer(Class modClazz, String modSource) + { + this.modClazz = modClazz; + this.modSource = modSource; + } + + @Override + public boolean wantsPreInit() + { + return true; + } + + @Override + public boolean wantsPostInit() + { + return true; + } + + @Override + public void preInit() + { + try + { + configureMod(); + mod = modClazz.newInstance(); + } + catch (Exception e) + { + throw new LoaderException(e); + } + } + + /** + * + */ + private void configureMod() + { + File configDir = Loader.instance().getConfigDir(); + File modConfig = new File(configDir, String.format("%s.cfg", modClazz.getSimpleName())); + Properties props = new Properties(); + + if (modConfig.exists()) + { + try + { + FileReader configReader = new FileReader(modConfig); + props.load(configReader); + configReader.close(); + } + catch (Exception e) + { + Loader.log.severe(String.format("Error occured reading mod configuration file %s", modConfig.getName())); + Loader.log.throwing("ModLoaderModContainer", "configureMod", e); + throw new LoaderException(e); + } + } + + StringBuffer comments = new StringBuffer(); + comments.append("MLProperties: name (type:default) min:max -- information\n"); + + try + { + for (Field f : modClazz.getDeclaredFields()) + { + if (!Modifier.isStatic(f.getModifiers())) + { + continue; + } + + if (!f.isAnnotationPresent(MLProp.class)) + { + continue; + } + + MLProp property = f.getAnnotation(MLProp.class); + String propertyName = property.name().length() > 0 ? property.name() : f.getName(); + String propertyValue = null; + Object defaultValue = null; + + try + { + defaultValue = f.get(null); + propertyValue = props.getProperty(propertyName, extractValue(defaultValue)); + Object currentValue = parseValue(propertyValue, property, f.getType()); + + if (currentValue != null && !currentValue.equals(defaultValue)) + { + f.set(null, currentValue); + } + } + catch (Exception e) + { + Loader.log.severe(String.format("Invalid configuration found for %s in %s", propertyName, modConfig.getName())); + Loader.log.throwing("ModLoaderModContainer", "configureMod", e); + throw new LoaderException(e); + } + finally + { + comments.append(String.format("MLProp : %s (%s:%s", propertyName, f.getType().getName(), defaultValue)); + + if (property.min() != Double.MIN_VALUE) + { + comments.append(",>=").append(String.format("%.1f", property.min())); + } + + if (property.max() != Double.MAX_VALUE) + { + comments.append(",<=").append(String.format("%.1f", property.max())); + } + + comments.append(")"); + + if (property.info().length() > 0) + { + comments.append(" -- ").append(property.info()); + } + + if (propertyValue != null) + { + props.setProperty(propertyName, extractValue(propertyValue)); + } + } + } + } + finally + { + try + { + FileWriter configWriter = new FileWriter(modConfig); + props.store(configWriter, comments.toString()); + configWriter.close(); + } + catch (IOException e) + { + Loader.log.warning(String.format("Error trying to write the config file %s", modConfig.getName())); + Loader.log.throwing("ModLoaderModContainer", "configureMod", e); + throw new LoaderException(e); + } + } + } + + private Object parseValue(String val, MLProp property, Class type) + { + if (type.isAssignableFrom(String.class)) + { + return (String)val; + } + else if (type.isAssignableFrom(Boolean.TYPE) || type.isAssignableFrom(Boolean.class)) + { + return Boolean.parseBoolean(val); + } + else if (Number.class.isAssignableFrom(type)) + { + Number n = null; + + if (Double.class.isAssignableFrom(type)) + { + n = Double.parseDouble(val); + } + if (Float.class.isAssignableFrom(type)) + { + n = Float.parseFloat(val); + } + if (Long.class.isAssignableFrom(type)) + { + n = Long.parseLong(val); + } + if (Integer.class.isAssignableFrom(type)) + { + n = Integer.parseInt(val); + } + if (Short.class.isAssignableFrom(type)) + { + n = Short.parseShort(val); + } + if (Byte.class.isAssignableFrom(type)) + { + n = Byte.parseByte(val); + } + else + { + throw new IllegalArgumentException("MLProp declared on non-standard type"); + } + + if (n.doubleValue() < property.min() || n.doubleValue() > property.max()) + { + return null; + } + else + { + return n; + } + } + + return null; + } + private String extractValue(Object value) + { + if (String.class.isInstance(value)) + { + return (String)value; + } + else if (Number.class.isInstance(value) || Boolean.class.isInstance(value)) + { + return String.valueOf(value); + } + else + { + throw new IllegalArgumentException("MLProp declared on non-standard type"); + } + } + @Override + public void init() + { + mod.load(); + } + + @Override + public void postInit() + { + mod.modsLoaded(); + } + + @Override + public void tickStart() + { + if (isTicking) + { + isTicking = mod.onTickInGame(FMLBukkitHandler.instance().getServer()); + } + } + @Override + public void tickEnd() + { + // NOOP for modloader + } + + @Override + public String getName() + { + return mod != null ? mod.getName() : null; + } + + public static ModContainer findContainerFor(BaseMod mod) + { + for (ModContainer mc : Loader.getModList()) + { + if (mc.matches(mod)) + { + return mc; + } + } + + return null; + } + + @Override + public boolean matches(Object mod) + { + return modClazz.isInstance(mod); + } + + public void setTicking(boolean enable) + { + isTicking = enable; + } + + /** + * Find all the BaseMods in the system + * @return + */ + public static List findAll() + { + ArrayList modList = new ArrayList(); + + for (ModContainer mc : Loader.getModList()) + { + if (mc instanceof ModLoaderModContainer) + { + modList.add(((ModLoaderModContainer)mc).mod); + } + } + + return modList; + } + + @Override + public String getSource() + { + return modSource; + } + + @Override + public Object getMod() + { + return mod; + } + + @Override + public boolean generatesWorld() + { + return true; + } + + @Override + public IWorldGenerator getWorldGenerator() + { + return mod; + } + + @Override + public int lookupFuelValue(int itemId, int itemDamage) + { + return mod.addFuel(itemId, itemDamage); + } + + @Override + public boolean wantsPickupNotification() + { + return true; + } + + @Override + public IPickupNotifier getPickupNotifier() + { + return mod; + } + + @Override + public boolean wantsToDispense() + { + return true; + } + + @Override + public IDispenseHandler getDispenseHandler() + { + return mod; + } + + @Override + public boolean wantsCraftingNotification() + { + return true; + } + + @Override + public ICraftingHandler getCraftingHandler() + { + return mod; + } + + private void computeDependencies() + { + dependencies = new ArrayList(); + preDependencies = new ArrayList(); + postDependencies = new ArrayList(); + + if (mod.getPriorities() == null || mod.getPriorities().length() == 0) + { + return; + } + + 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]); + } + + if ("required-before".equals(depparts[0]) || "before".equals(depparts[0])) + { + postDependencies.add(depparts[1]); + } + + if ("required-after".equals(depparts[0]) || "after".equals(depparts[0])) + { + preDependencies.add(depparts[1]); + } + + } + } + + @Override + public List getDependencies() + { + if (dependencies == null) + { + computeDependencies(); + } + + return dependencies; + } + + @Override + public List getPostDepends() + { + if (dependencies == null) + { + computeDependencies(); + } + + return postDependencies; + } + + @Override + public List getPreDepends() + { + if (dependencies == null) + { + computeDependencies(); + } + return preDependencies; + } + + + public String toString() + { + return modSource; + } + + @Override + public boolean wantsNetworkPackets() + { + return true; + } + + @Override + public INetworkHandler getNetworkHandler() + { + return mod; + } + + @Override + public boolean ownsNetworkChannel(String channel) + { + return FMLCommonHandler.instance().getChannelListFor(this).contains(channel); + } + + @Override + public boolean wantsConsoleCommands() + { + return true; + } + + @Override + public IConsoleHandler getConsoleHandler() + { + return mod; + } + + @Override + public boolean wantsPlayerTracking() + { + return true; + } + + @Override + public IPlayerTracker getPlayerTracker() + { + return mod; + } +} diff --git a/bukkit/net/minecraft/server/BaseMod.java b/bukkit/net/minecraft/server/BaseMod.java new file mode 100644 index 0000000000..c05136f758 --- /dev/null +++ b/bukkit/net/minecraft/server/BaseMod.java @@ -0,0 +1,325 @@ +/* + * 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 net.minecraft.server; + +import java.util.Random; + +import cpw.mods.fml.common.IConsoleHandler; +import cpw.mods.fml.common.ICraftingHandler; +import cpw.mods.fml.common.IDispenseHandler; +import cpw.mods.fml.common.INetworkHandler; +import cpw.mods.fml.common.IPickupNotifier; +import cpw.mods.fml.common.IPlayerTracker; +import cpw.mods.fml.common.IWorldGenerator; + +public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler, INetworkHandler, IConsoleHandler, IPlayerTracker +{ + // CALLBACK MECHANISMS + @Override + public final void onCrafting(Object... craftingParameters) + { + takenFromCrafting((EntityPlayer)craftingParameters[0], (ItemStack)craftingParameters[1], (IInventory)craftingParameters[2]); + } + + @Override + public final void onSmelting(Object... smeltingParameters) + { + takenFromFurnace((EntityPlayer)smeltingParameters[0], (ItemStack)smeltingParameters[1]); + } + @Override + public final 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]); + } + + @Override + public final boolean onChat(Object... data) + { + return onChatMessageReceived((EntityPlayer)data[1], (Packet3Chat)data[0]); + } + @Override + public final void onPlayerLogin(Object player) + { + onClientLogin((EntityPlayer) player); + } + + @Override + public void onPlayerLogout(Object player) + { + onClientLogout((EntityPlayer)player); + } + + @Override + public void onPlayerChangedDimension(Object player) + { + onClientDimensionChanged((EntityPlayer)player); + } + + @Override + public final void onPacket250Packet(Object... data) + { + onPacket250Received((EntityPlayer)data[1], (Packet250CustomPayload)data[0]); + } + + @Override + public final void notifyPickup(Object... pickupData) + { + EntityItem item = (EntityItem) pickupData[0]; + EntityPlayer player = (EntityPlayer) pickupData[1]; + onItemPickup(player, item.itemStack); + } + + @Override + public final void generate(Random random, int chunkX, int chunkZ, Object... additionalData) + { + World w = (World) additionalData[0]; + IChunkProvider cp = (IChunkProvider) additionalData[1]; + + if (cp instanceof ChunkProviderGenerate) + { + generateSurface(w, random, chunkX << 4, chunkZ << 4); + } + else if (cp instanceof ChunkProviderHell) + { + generateNether(w, random, chunkX << 4, chunkZ << 4); + } + } + + @Override + public final boolean handleCommand(String command, Object... data) + { + return onServerCommand(command, (String)data[0], (ICommandListener)data[1]); + } + // 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) + { + } + + /** + * Ticked every game tick if you have subscribed to tick events through {@link ModLoader#setInGameHook(BaseMod, boolean, boolean)} + * @param minecraftServer the server + * @return true to continue receiving ticks + */ + public boolean onTickInGame(MinecraftServer minecraftServer) + { + return false; + } + + /** + * Not implemented because on the server you don't know who it's from + * {@link #onChatMessageReceived(EntityPlayer, Packet3Chat)} + * @param text + */ + @Deprecated + public void receiveChatPacket(String text) + { + } + + /** + * Not implemented because on the server you don't know who it's from + * {@link #onPacket250Received(EntityPlayer, Packet250CustomPayload)} + * @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(); + } + + /** + * Called when a 250 packet is received on a channel registered to this mod + * + * @param source + * @param payload + */ + public void onPacket250Received(EntityPlayer source, Packet250CustomPayload payload) + { + } + + /** + * Called when a chat message is received. Return true to stop further processing + * @param source + * @param chat + * @return true if you want to consume the message so it is not available for further processing + */ + public boolean onChatMessageReceived(EntityPlayer source, Packet3Chat chat) + { + return false; + } + /** + * Called when a server command is received + * @param command + * @return true if you want to consume the message so it is not available for further processing + */ + public boolean onServerCommand(String command, String sender, ICommandListener listener) + { + return false; + } + + /** + * Called when a new client logs in. + * + * @param player + */ + public void onClientLogin(EntityPlayer player) + { + } + + /** + * Called when a client logs out of the server. + * + * @param player + */ + public void onClientLogout(EntityPlayer player) + { + + } + + /** + * + * Called when a client changes dimensions on the server. + * + * @param player + */ + public void onClientDimensionChanged(EntityPlayer player) + { + + } + + // 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); +} diff --git a/bukkit/net/minecraft/server/BukkitRegistry.java b/bukkit/net/minecraft/server/BukkitRegistry.java new file mode 100644 index 0000000000..541fe66dfd --- /dev/null +++ b/bukkit/net/minecraft/server/BukkitRegistry.java @@ -0,0 +1,147 @@ +package net.minecraft.server; + +import java.util.Collections; +import java.util.List; + +public class BukkitRegistry implements IMinecraftRegistry +{ + + @Override + public void addRecipe(ItemStack output, Object... params) + { + CraftingManager.getInstance().registerShapedRecipe(output, params); + } + + @Override + public void addShapelessRecipe(ItemStack output, Object... params) + { + CraftingManager.getInstance().registerShapelessRecipe(output, params); + } + + @Override + public void addSmelting(int input, ItemStack output) + { + FurnaceRecipes.getInstance().registerRecipe(input, output); + } + + @Override + public void registerBlock(Block block) + { + registerBlock(block, ItemBlock.class); + } + + @Override + public 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.id - 256; + itemclass.getConstructor(int.class).newInstance(blockItemId); + } + catch (Exception e) + { + //HMMM + } + } + + @Override + public void registerEntityID(Class entityClass, String entityName, int id) + { + EntityTypes.addNewEntityListMapping(entityClass, entityName, id); + } + + @Override + public void registerEntityID(Class entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour) + { + EntityTypes.addNewEntityListMapping(entityClass, entityName, id, backgroundEggColour, foregroundEggColour); + } + + @Override + public void registerTileEntity(Class tileEntityClass, String id) + { + TileEntity.addNewTileEntityMapping(tileEntityClass, id); + } + + @Override + public void addBiome(Object 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, Object... biomes) + { + BiomeBase[] realBiomes=(BiomeBase[]) biomes; + for (BiomeBase biome : realBiomes) + { + @SuppressWarnings("unchecked") + List spawns = biome.getMobs(typeOfCreature); + + for (BiomeMeta entry : spawns) + { + //Adjusting an existing spawn entry + if (entry.a == entityClass) + { + entry.d = weightedProb; + entry.b = min; + entry.c = max; + break; + } + } + + spawns.add(new BiomeMeta(entityClass, weightedProb, min, max)); + } + } + + @Override + @SuppressWarnings("unchecked") + public void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, Object... biomes) + { + Class entityClazz = EntityTypes.getEntityToClassMapping().get(entityName); + + if (EntityLiving.class.isAssignableFrom(entityClazz)) + { + addSpawn((Class ) entityClazz, weightedProb, min, max, spawnList, biomes); + } + } + + @Override + public void removeBiome(Object biome) + { + // NOOP because broken + } + + @Override + public void removeSpawn(Class entityClass, EnumCreatureType typeOfCreature, Object... biomesO) + { + BiomeBase[] biomes=(BiomeBase[]) biomesO; + for (BiomeBase biome : biomes) + { + @SuppressWarnings("unchecked") + List spawns = biome.getMobs(typeOfCreature); + + for (BiomeMeta entry : Collections.unmodifiableList(spawns)) + { + if (entry.a == entityClass) + { + spawns.remove(entry); + } + } + } + } + + @Override + @SuppressWarnings("unchecked") + public void removeSpawn(String entityName, EnumCreatureType spawnList, Object... biomes) + { + Class entityClazz = EntityTypes.getEntityToClassMapping().get(entityName); + + if (EntityLiving.class.isAssignableFrom(entityClazz)) + { + removeSpawn((Class ) entityClazz, spawnList, biomes); + } + } + +} diff --git a/bukkit/net/minecraft/server/MLProp.java b/bukkit/net/minecraft/server/MLProp.java new file mode 100644 index 0000000000..25a20cbbd2 --- /dev/null +++ b/bukkit/net/minecraft/server/MLProp.java @@ -0,0 +1,48 @@ +/* + * 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 net.minecraft.server; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import static java.lang.annotation.RetentionPolicy.*; +import static java.lang.annotation.ElementType.*; + +/** + * @author cpw + * + */ +@Retention(value = RUNTIME) +@Target(value = FIELD) +public @interface MLProp +{ + /** + * Adds additional help to top of configuration file. + */ +String info() default ""; + + /** + * Maximum value allowed if field is a number. + */ +double max() default 1D; + + /** + * Minimum value allowed if field is a number. + */ +double min() default -1D; + + /** + * Overrides the field name for property key. + */ +String name() default ""; + +} diff --git a/bukkit/net/minecraft/server/ModLoader.java b/bukkit/net/minecraft/server/ModLoader.java new file mode 100644 index 0000000000..aca6346a71 --- /dev/null +++ b/bukkit/net/minecraft/server/ModLoader.java @@ -0,0 +1,617 @@ +/* + * 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 net.minecraft.server; + +import java.util.List; +import java.util.logging.Logger; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ReflectionHelper; +import cpw.mods.fml.server.FMLBukkitHandler; +import cpw.mods.fml.server.ModLoaderModContainer; + +public class ModLoader +{ + /** + * Not used on the server. + * + * @param achievement + * @param name + * @param description + */ + public static void addAchievementDesc(Achievement achievement, String name, String description) + { + } + + /** + * This method is a call in hook from modified external code. Implemented elsewhere. + * + * {@link FMLBukkitHandler#fuelLookup(int, int)} + * @param id + * @param metadata + * @return + */ + @Deprecated + public static int addAllFuel(int id, int metadata) + { + return 0; + } + + /** + * This method is unimplemented in server versions to date. + * + * @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. Using this method will likely corrupt worlds. + * + * @param biome + */ + @Deprecated + public static void addBiome(BiomeBase 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, FMLBukkitHandler.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, BiomeBase... 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, FMLBukkitHandler.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, BiomeBase... biomes) + { + CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, biomes); + } + + /** + * This method is a call in hook from modified external code. Implemented elsewhere. + * {@link FMLBukkitHandler#tryDispensingEntity(World, double, double, double, byte, byte, ItemStack)} + * @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; + } + + /** + * Remove a container and drop all the items in it on the ground around + * @param world + * @param x + * @param y + * @param z + */ + public static void genericContainerRemoval(World world, int x, int y, int z) + { + TileEntity te = world.getTileEntity(x, y, z); + + if (!(te instanceof IInventory)) + { + return; + } + + IInventory inv = (IInventory)te; + + for (int l = 0; l < inv.getSize(); l++) + { + ItemStack itemstack = inv.getItem(l); + + if (itemstack == null) + { + continue; + } + + float f = world.random.nextFloat() * 0.8F + 0.1F; + float f1 = world.random.nextFloat() * 0.8F + 0.1F; + float f2 = world.random.nextFloat() * 0.8F + 0.1F; + + while (itemstack.count > 0) + { + int i1 = world.random.nextInt(21) + 10; + + if (i1 > itemstack.count) + { + i1 = itemstack.count ; + } + + itemstack.count -= i1; + EntityItem entityitem = new EntityItem(world, (float)te.x + f, (float)te.y + f1, (float)te.z + f2, new ItemStack(itemstack.id, i1, itemstack.getData())); + float f3 = 0.05F; + entityitem.motX = (float)world.random.nextGaussian() * f3; + entityitem.motY = (float)world.random.nextGaussian() * f3 + 0.2F; + entityitem.motZ = (float)world.random.nextGaussian() * f3; + + if (itemstack.hasTag()) + { + entityitem.itemStack.setTag((NBTTagCompound)itemstack.getTag().clone()); + } + + world.addEntity(entityitem); + } + } + } + + /** + * Get a list of all BaseMod loaded into the system + * {@link ModLoaderModContainer#findAll} + * @return + */ + public static List getLoadedMods() + { + return ModLoaderModContainer.findAll(); + } + + /** + * Get a logger instance + * {@link FMLBukkitHandler#getFMLLogger()} + * @return + */ + public static Logger getLogger() + { + return FMLCommonHandler.instance().getFMLLogger(); + } + + /** + * Get a value from a field using reflection + * {@link ReflectionHelper#getPrivateValue(Class, Object, int)} + * @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 + * {@link ReflectionHelper#getPrivateValue(Class, Object, String)} + * @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 + * {@link Entity#getNextId()} + * @return + */ + public static int getUniqueEntityId() + { + return Entity.getNextId(); + } + + /** + * Is the named mod loaded? + * {@link Loader#isModLoaded(String)} + * @param modname + * @return + */ + public static boolean isModLoaded(String modname) + { + return Loader.isModLoaded(modname); + } + + /** + * This method is a call in hook from modified external code. Implemented elsewhere. + * {@link FMLBukkitHandler#handlePacket250(Packet250CustomPayload, EntityPlayer)} + * @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); + } + + /** + * Register the mod for packets on this channel. This only registers the channel with Forge Mod Loader, not + * with clients connecting- use BaseMod.onClientLogin to tell them about your custom channel + * {@link FMLCommonHandler#registerChannel(cpw.mods.fml.common.ModContainer, String)} + * @param mod + * @param channel + */ + public static void registerPacketChannel(BaseMod mod, String channel) + { + FMLCommonHandler.instance().registerChannel(ModLoaderModContainer.findContainerFor(mod), 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 and will likely corrupt worlds. + * @param biome + */ + @Deprecated + public static void removeBiome(BiomeBase biome) + { + CommonRegistry.removeBiome(biome); + } + + /** + * Remove a spawn + * @param entityClass + * @param spawnList + */ + public static void removeSpawn(Class entityClass, EnumCreatureType spawnList) + { + CommonRegistry.removeSpawn(entityClass, spawnList, FMLBukkitHandler.instance().getDefaultOverworldBiomes()); + } + + /** + * Remove a spawn + * @param entityClass + * @param spawnList + * @param biomes + */ + public static void removeSpawn(Class entityClass, EnumCreatureType spawnList, BiomeBase... 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, FMLBukkitHandler.instance().getDefaultOverworldBiomes()); + } + + /** + * Remove a spawn + * @param entityName + * @param spawnList + * @param biomes + */ + public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeBase... biomes) + { + CommonRegistry.removeSpawn(entityName, spawnList, biomes); + } + + /** + * Configuration is handled elsewhere + * {@link ModLoaderModContainer} + */ + @Deprecated + public static void saveConfig() + { + } + + /** + * This method is unimplemented on the server: it is meant for clients to send chat to the server + * {@link FMLBukkitHandler#handleChatPacket(Packet3Chat, EntityPlayer)} + * @param text + */ + @Deprecated + public static void serverChat(String text) + { + } + + /** + * Indicate that you want to receive ticks + * + * @param mod + * receiving the events + * @param enable + * indicates whether you want to recieve them or not + * @param useClock + * Not used in server side: all ticks are sent on the server side (no render subticks) + */ + public static void setInGameHook(BaseMod mod, boolean enable, boolean useClock) + { + ModLoaderModContainer mlmc = (ModLoaderModContainer) ModLoaderModContainer.findContainerFor(mod); + mlmc.setTicking(enable); + } + + /** + * Set a private field to a value using reflection + * {@link ReflectionHelper#setPrivateValue(Class, Object, int, Object)} + * @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 + * {@link ReflectionHelper#setPrivateValue(Class, Object, String, Object)} + * @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. + * {@link FMLBukkitHandler#onItemCrafted(EntityPlayer, ItemStack, IInventory)} + * @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. + * {@link FMLBukkitHandler#onItemSmelted(EntityPlayer, ItemStack)} + * @param player + * @param item + */ + @Deprecated + public static void takenFromFurnace(EntityPlayer player, ItemStack item) + { + } + + /** + * Throw the offered exception. Likely will stop the game. + * {@link FMLBukkitHandler#raiseException(Throwable, String, boolean)} + * @param message + * @param e + */ + public static void throwException(String message, Throwable e) + { + FMLBukkitHandler.instance().raiseException(e, message, true); + } + + /** + * Get the minecraft server instance + * {@link FMLBukkitHandler#getServer()} + * @return + */ + public static MinecraftServer getMinecraftServerInstance() + { + return FMLBukkitHandler.instance().getServer(); + } + + /** + * To properly implement packet 250 protocol you should always check your channel + * is active prior to sending the packet + * + * @param player + * @param channel + * @return + */ + public static boolean isChannelActive(EntityPlayer player, String channel) + { + return FMLCommonHandler.instance().isChannelActive(channel, player); + } + + /** + * Stubbed method on the server to return a unique model id + * + */ + @Deprecated + public static int getUniqueBlockModelID(BaseMod mod, boolean flag) { + return 0; + } +} \ No newline at end of file diff --git a/common/cpw/mods/fml/common/IWorldGenerator.java b/common/cpw/mods/fml/common/IWorldGenerator.java index f8ae4de224..37f6141dc7 100644 --- a/common/cpw/mods/fml/common/IWorldGenerator.java +++ b/common/cpw/mods/fml/common/IWorldGenerator.java @@ -27,7 +27,7 @@ public interface IWorldGenerator /** * Generate some world * - * @param random the chunk specific {@link Random} as built in {@link FMLServerHandler#onChunkPopulate(net.minecraft.src.IChunkProvider, int, int, net.minecraft.src.World, net.minecraft.src.IChunkProvider)}. + * @param random the chunk specific {@link Random} as built in {@link FMLBukkitHandler#onChunkPopulate(net.minecraft.src.IChunkProvider, int, int, net.minecraft.src.World, net.minecraft.src.IChunkProvider)}. * @param chunkX the block X coordinate of this chunk. * @param chunkZ the block Z coordinate of this chunk. * @param world : additionalData[0] The minecraft {@link net.minecraft.src.World} we're generating for. diff --git a/common/net/minecraft/src/CommonRegistry.java b/common/net/minecraft/server/CommonRegistry.java similarity index 89% rename from common/net/minecraft/src/CommonRegistry.java rename to common/net/minecraft/server/CommonRegistry.java index de29cfa1d5..ab132f57d8 100644 --- a/common/net/minecraft/src/CommonRegistry.java +++ b/common/net/minecraft/server/CommonRegistry.java @@ -11,7 +11,7 @@ * 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 net.minecraft.src; +package net.minecraft.server; public class CommonRegistry @@ -67,34 +67,34 @@ public class CommonRegistry instance.registerTileEntity(tileEntityClass, id); } - public static void addBiome(BiomeGenBase biome) + public static void addBiome(Object biome) { instance.addBiome(biome); } - public static 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, Object... biomes) { 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) + public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, Object... biomes) { instance.addSpawn(entityName, weightedProb, min, max, spawnList, biomes); } - public static void removeBiome(BiomeGenBase biome) + public static void removeBiome(Object biome) { instance.removeBiome(biome); } - public static void removeSpawn(Class entityClass, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) + public static void removeSpawn(Class entityClass, EnumCreatureType typeOfCreature, Object... biomes) { instance.removeSpawn(entityClass, typeOfCreature, biomes); } @SuppressWarnings("unchecked") - public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) + public static void removeSpawn(String entityName, EnumCreatureType spawnList, Object... biomes) { instance.removeSpawn(entityName, spawnList, biomes); } diff --git a/common/net/minecraft/src/IMinecraftRegistry.java b/common/net/minecraft/server/IMinecraftRegistry.java similarity index 74% rename from common/net/minecraft/src/IMinecraftRegistry.java rename to common/net/minecraft/server/IMinecraftRegistry.java index cc17c0465e..f7cf8122d9 100644 --- a/common/net/minecraft/src/IMinecraftRegistry.java +++ b/common/net/minecraft/server/IMinecraftRegistry.java @@ -1,19 +1,19 @@ -package net.minecraft.src; +package net.minecraft.server; public interface IMinecraftRegistry { - public abstract void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes); + public abstract void removeSpawn(String entityName, EnumCreatureType spawnList, Object... biomes); - public abstract void removeSpawn(Class entityClass, EnumCreatureType typeOfCreature, BiomeGenBase... biomes); + public abstract void removeSpawn(Class entityClass, EnumCreatureType typeOfCreature, Object... biomes); - public abstract void removeBiome(BiomeGenBase biome); + public abstract void removeBiome(Object biome); - public abstract void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes); + public abstract void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, Object... biomes); - public abstract void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, BiomeGenBase... biomes); + public abstract void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, Object... biomes); - public abstract void addBiome(BiomeGenBase biome); + public abstract void addBiome(Object biome); public abstract void registerTileEntity(Class tileEntityClass, String id); From aedb80c2516caeffd6e7dde5a474234fd661a298 Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Sun, 15 Apr 2012 22:42:06 -0400 Subject: [PATCH 2/6] Fix chunk generators for bukkit --- bukkit/net/minecraft/server/BaseMod.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bukkit/net/minecraft/server/BaseMod.java b/bukkit/net/minecraft/server/BaseMod.java index c05136f758..272512388d 100644 --- a/bukkit/net/minecraft/server/BaseMod.java +++ b/bukkit/net/minecraft/server/BaseMod.java @@ -14,6 +14,9 @@ package net.minecraft.server; import java.util.Random; +import org.bukkit.craftbukkit.generator.NetherChunkGenerator; +import org.bukkit.craftbukkit.generator.NormalChunkGenerator; + import cpw.mods.fml.common.IConsoleHandler; import cpw.mods.fml.common.ICraftingHandler; import cpw.mods.fml.common.IDispenseHandler; @@ -85,14 +88,14 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp World w = (World) additionalData[0]; IChunkProvider cp = (IChunkProvider) additionalData[1]; - if (cp instanceof ChunkProviderGenerate) - { - generateSurface(w, random, chunkX << 4, chunkZ << 4); - } - else if (cp instanceof ChunkProviderHell) + if (cp instanceof ChunkProviderHell || cp instanceof NetherChunkGenerator) { generateNether(w, random, chunkX << 4, chunkZ << 4); } + else if (cp instanceof ChunkProviderGenerate || cp instanceof NormalChunkGenerator) + { + generateSurface(w, random, chunkX << 4, chunkZ << 4); + } } @Override From 8f14c7321bfc54c5d9ccf8e2b985f1ffc78b63c4 Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Mon, 16 Apr 2012 01:00:06 -0400 Subject: [PATCH 3/6] Damn you bukkit with your same names for different classes!!!! EntityPlayer->EntityHuman --- .../cpw/mods/fml/server/FMLBukkitHandler.java | 1 - bukkit/net/minecraft/server/BaseMod.java | 36 +++++++++---------- bukkit/net/minecraft/server/ModLoader.java | 14 ++++---- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java b/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java index a48abb2297..4660707cc2 100644 --- a/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java +++ b/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java @@ -25,7 +25,6 @@ import net.minecraft.server.BiomeBase; import net.minecraft.server.CommonRegistry; import net.minecraft.server.EntityItem; import net.minecraft.server.EntityHuman; -import net.minecraft.server.EntityPlayer; import net.minecraft.server.IChunkProvider; import net.minecraft.server.ICommandListener; import net.minecraft.server.IInventory; diff --git a/bukkit/net/minecraft/server/BaseMod.java b/bukkit/net/minecraft/server/BaseMod.java index 272512388d..47c8641e56 100644 --- a/bukkit/net/minecraft/server/BaseMod.java +++ b/bukkit/net/minecraft/server/BaseMod.java @@ -31,13 +31,13 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp @Override public final void onCrafting(Object... craftingParameters) { - takenFromCrafting((EntityPlayer)craftingParameters[0], (ItemStack)craftingParameters[1], (IInventory)craftingParameters[2]); + takenFromCrafting((EntityHuman)craftingParameters[0], (ItemStack)craftingParameters[1], (IInventory)craftingParameters[2]); } @Override public final void onSmelting(Object... smeltingParameters) { - takenFromFurnace((EntityPlayer)smeltingParameters[0], (ItemStack)smeltingParameters[1]); + takenFromFurnace((EntityHuman)smeltingParameters[0], (ItemStack)smeltingParameters[1]); } @Override public final boolean dispense(double x, double y, double z, byte xVelocity, byte zVelocity, Object... data) @@ -48,37 +48,37 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp @Override public final boolean onChat(Object... data) { - return onChatMessageReceived((EntityPlayer)data[1], (Packet3Chat)data[0]); + return onChatMessageReceived((EntityHuman)data[1], (Packet3Chat)data[0]); } @Override public final void onPlayerLogin(Object player) { - onClientLogin((EntityPlayer) player); + onClientLogin((EntityHuman) player); } @Override public void onPlayerLogout(Object player) { - onClientLogout((EntityPlayer)player); + onClientLogout((EntityHuman)player); } @Override public void onPlayerChangedDimension(Object player) { - onClientDimensionChanged((EntityPlayer)player); + onClientDimensionChanged((EntityHuman)player); } @Override public final void onPacket250Packet(Object... data) { - onPacket250Received((EntityPlayer)data[1], (Packet250CustomPayload)data[0]); + onPacket250Received((EntityHuman)data[1], (Packet250CustomPayload)data[0]); } @Override public final void notifyPickup(Object... pickupData) { EntityItem item = (EntityItem) pickupData[0]; - EntityPlayer player = (EntityPlayer) pickupData[1]; + EntityHuman player = (EntityHuman) pickupData[1]; onItemPickup(player, item.itemStack); } @@ -194,7 +194,7 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp * @param player * @param item */ - public void onItemPickup(EntityPlayer player, ItemStack item) + public void onItemPickup(EntityHuman player, ItemStack item) { } @@ -210,7 +210,7 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp /** * Not implemented because on the server you don't know who it's from - * {@link #onChatMessageReceived(EntityPlayer, Packet3Chat)} + * {@link #onChatMessageReceived(EntityHuman, Packet3Chat)} * @param text */ @Deprecated @@ -220,7 +220,7 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp /** * Not implemented because on the server you don't know who it's from - * {@link #onPacket250Received(EntityPlayer, Packet250CustomPayload)} + * {@link #onPacket250Received(EntityHuman, Packet250CustomPayload)} * @param packet */ @Deprecated @@ -234,7 +234,7 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp * @param item * @param matrix */ - public void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix) + public void takenFromCrafting(EntityHuman player, ItemStack item, IInventory matrix) { } @@ -244,7 +244,7 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp * @param player * @param item */ - public void takenFromFurnace(EntityPlayer player, ItemStack item) + public void takenFromFurnace(EntityHuman player, ItemStack item) { } @@ -263,7 +263,7 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp * @param source * @param payload */ - public void onPacket250Received(EntityPlayer source, Packet250CustomPayload payload) + public void onPacket250Received(EntityHuman source, Packet250CustomPayload payload) { } @@ -273,7 +273,7 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp * @param chat * @return true if you want to consume the message so it is not available for further processing */ - public boolean onChatMessageReceived(EntityPlayer source, Packet3Chat chat) + public boolean onChatMessageReceived(EntityHuman source, Packet3Chat chat) { return false; } @@ -292,7 +292,7 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp * * @param player */ - public void onClientLogin(EntityPlayer player) + public void onClientLogin(EntityHuman player) { } @@ -301,7 +301,7 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp * * @param player */ - public void onClientLogout(EntityPlayer player) + public void onClientLogout(EntityHuman player) { } @@ -312,7 +312,7 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp * * @param player */ - public void onClientDimensionChanged(EntityPlayer player) + public void onClientDimensionChanged(EntityHuman player) { } diff --git a/bukkit/net/minecraft/server/ModLoader.java b/bukkit/net/minecraft/server/ModLoader.java index aca6346a71..13c69810ce 100644 --- a/bukkit/net/minecraft/server/ModLoader.java +++ b/bukkit/net/minecraft/server/ModLoader.java @@ -363,7 +363,7 @@ public class ModLoader /** * This method is a call in hook from modified external code. Implemented elsewhere. - * {@link FMLBukkitHandler#handlePacket250(Packet250CustomPayload, EntityPlayer)} + * {@link FMLBukkitHandler#handlePacket250(Packet250CustomPayload, EntityHuman)} * @param packet */ @Deprecated @@ -499,7 +499,7 @@ public class ModLoader /** * This method is unimplemented on the server: it is meant for clients to send chat to the server - * {@link FMLBukkitHandler#handleChatPacket(Packet3Chat, EntityPlayer)} + * {@link FMLBukkitHandler#handleChatPacket(Packet3Chat, EntityHuman)} * @param text */ @Deprecated @@ -551,24 +551,24 @@ public class ModLoader /** * This method is a call in hook from modified external code. Implemented elsewhere. - * {@link FMLBukkitHandler#onItemCrafted(EntityPlayer, ItemStack, IInventory)} + * {@link FMLBukkitHandler#onItemCrafted(EntityHuman, ItemStack, IInventory)} * @param player * @param item * @param matrix */ @Deprecated - public static void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix) + public static void takenFromCrafting(EntityHuman player, ItemStack item, IInventory matrix) { } /** * This method is a call in hook from modified external code. Implemented elsewhere. - * {@link FMLBukkitHandler#onItemSmelted(EntityPlayer, ItemStack)} + * {@link FMLBukkitHandler#onItemSmelted(EntityHuman, ItemStack)} * @param player * @param item */ @Deprecated - public static void takenFromFurnace(EntityPlayer player, ItemStack item) + public static void takenFromFurnace(EntityHuman player, ItemStack item) { } @@ -601,7 +601,7 @@ public class ModLoader * @param channel * @return */ - public static boolean isChannelActive(EntityPlayer player, String channel) + public static boolean isChannelActive(EntityHuman player, String channel) { return FMLCommonHandler.instance().isChannelActive(channel, player); } From 2eb77acf739a827604e13e46f4e3f458d8855480 Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Wed, 18 Apr 2012 14:06:54 -0400 Subject: [PATCH 4/6] Update bukkit with new mod fixes --- bukkit/cpw/mods/fml/server/FMLBukkitHandler.java | 4 ++-- bukkit/cpw/mods/fml/server/ModLoaderModContainer.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java b/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java index 4660707cc2..0dbc5377cd 100644 --- a/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java +++ b/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java @@ -184,11 +184,11 @@ public class FMLBukkitHandler implements IFMLSidedHandler /** * Load the supplied mod class into a mod container */ - public ModContainer loadBaseModMod(Class clazz, String canonicalPath) + public ModContainer loadBaseModMod(Class clazz, File canonicalFile) { @SuppressWarnings("unchecked") Class bmClazz = (Class ) clazz; - return new ModLoaderModContainer(bmClazz, canonicalPath); + return new ModLoaderModContainer(bmClazz, canonicalFile); } /** diff --git a/bukkit/cpw/mods/fml/server/ModLoaderModContainer.java b/bukkit/cpw/mods/fml/server/ModLoaderModContainer.java index 7dc41121f0..54f72e9ab0 100644 --- a/bukkit/cpw/mods/fml/server/ModLoaderModContainer.java +++ b/bukkit/cpw/mods/fml/server/ModLoaderModContainer.java @@ -43,11 +43,11 @@ public class ModLoaderModContainer implements ModContainer private Class modClazz; private BaseMod mod; private boolean isTicking; - private String modSource ; + private File modSource ; private ArrayList dependencies; private ArrayList preDependencies; private ArrayList postDependencies; - public ModLoaderModContainer(Class modClazz, String modSource) + public ModLoaderModContainer(Class modClazz, File modSource) { this.modClazz = modClazz; this.modSource = modSource; @@ -334,7 +334,7 @@ public class ModLoaderModContainer implements ModContainer } @Override - public String getSource() + public File getSource() { return modSource; } @@ -475,7 +475,7 @@ public class ModLoaderModContainer implements ModContainer public String toString() { - return modSource; + return modSource.getName(); } @Override From 28992c6f137c2eabc716235cde6cb82b2aa66a86 Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Sat, 28 Apr 2012 16:40:25 -0400 Subject: [PATCH 5/6] Update FML with recent mainline changes --- .../cpw/mods/fml/server/FMLBukkitHandler.java | 28 +++++++++++++++++ .../fml/server/ModLoaderModContainer.java | 31 ++++++++++++------- bukkit/net/minecraft/server/MLProp.java | 4 +-- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java b/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java index 0dbc5377cd..f552501cdc 100644 --- a/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java +++ b/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java @@ -79,6 +79,34 @@ public class FMLBukkitHandler implements IFMLSidedHandler */ public void onPreLoad(MinecraftServer minecraftServer) { + try + { + Class.forName("BaseModMp", false, getClass().getClassLoader()); + MinecraftServer.field_6038_a.severe("" + + "Forge Mod Loader has detected that this server has an ModLoaderMP installed alongside Forge Mod Loader.\n" + + "This will cause a serious problem with compatibility. To protect your worlds, this minecraft server will now shutdown.\n" + + "You should follow the installation instructions of either Minecraft Forge of Forge Mod Loader and NOT install ModLoaderMP \n" + + "into the minecraft_server.jar file " + + "before this server will be allowed to start up.\n\nFailure to do so will simply result in more startup failures.\n\n" + + "The authors of Minecraft Forge and Forge Mod Loader strongly suggest you talk to your mod's authors and get them to\nupdate their " + + "requirements. ModLoaderMP is not compatible with Minecraft Forge on the server and they will need to update their mod\n" + + "for Minecraft Forge and other server compatibility, unless they are Minecraft Forge mods, in which case they already\n" + + "don't need ModLoaderMP and the mod author simply has failed to update his requirements and should be informed appropriately.\n\n" + + "The authors of Forge Mod Loader would like to be compatible with ModLoaderMP but it is closed source and owned by SDK.\n" + + "SDK, the author of ModLoaderMP, has a standing invitation to submit compatibility patches \n" + + "to the open source community project that is Forge Mod Loader so that this incompatibility doesn't last. \n" + + "Users who wish to enjoy mods of both types are " + + "encouraged to request of SDK that he submit a\ncompatibility patch to the Forge Mod Loader project at \n" + + "http://github.com/cpw/FML.\nPosting on the minecraft forums at\nhttp://www.minecraftforum.net/topic/86765- (the MLMP thread)\n" + + "may encourage him in this effort. However, I ask that your requests be polite.\n" + + "Now, the server has to shutdown so you can reinstall your minecraft_server.jar\nproperly, until such time as we can work together."); + throw new RuntimeException( + "This FML based server has detected an installation of ModLoaderMP alongside. This will cause serious compatibility issues, so the server will now shut down."); + } + catch (ClassNotFoundException e) + { + // We're safe. continue + } server = minecraftServer; FMLCommonHandler.instance().registerSidedDelegate(this); CommonRegistry.registerRegistry(new BukkitRegistry()); diff --git a/bukkit/cpw/mods/fml/server/ModLoaderModContainer.java b/bukkit/cpw/mods/fml/server/ModLoaderModContainer.java index 54f72e9ab0..58491887a1 100644 --- a/bukkit/cpw/mods/fml/server/ModLoaderModContainer.java +++ b/bukkit/cpw/mods/fml/server/ModLoaderModContainer.java @@ -85,13 +85,15 @@ public class ModLoaderModContainer implements ModContainer private void configureMod() { File configDir = Loader.instance().getConfigDir(); - File modConfig = new File(configDir, String.format("%s.cfg", modClazz.getSimpleName())); + String modConfigName = modClazz.getSimpleName(); + File modConfig = new File(configDir, String.format("%s.cfg", modConfigName)); Properties props = new Properties(); if (modConfig.exists()) { try { + Loader.log.fine(String.format("Reading existing configuration file for %s : %s", modConfigName, modConfig.getName())); FileReader configReader = new FileReader(modConfig); props.load(configReader); configReader.close(); @@ -130,10 +132,12 @@ public class ModLoaderModContainer implements ModContainer { defaultValue = f.get(null); propertyValue = props.getProperty(propertyName, extractValue(defaultValue)); - Object currentValue = parseValue(propertyValue, property, f.getType()); + Object currentValue = parseValue(propertyValue, property, f.getType(), propertyName, modConfigName); + Loader.log.finest(String.format("Configuration for %s.%s found values default: %s, configured: %s, interpreted: %s", modConfigName, propertyName, defaultValue, propertyValue, currentValue)); if (currentValue != null && !currentValue.equals(defaultValue)) { + Loader.log.finest(String.format("Configuration for %s.%s value set to: %s", modConfigName, propertyName, currentValue)); f.set(null, currentValue); } } @@ -168,6 +172,7 @@ public class ModLoaderModContainer implements ModContainer { props.setProperty(propertyName, extractValue(propertyValue)); } + comments.append("\n"); } } } @@ -178,6 +183,7 @@ public class ModLoaderModContainer implements ModContainer FileWriter configWriter = new FileWriter(modConfig); props.store(configWriter, comments.toString()); configWriter.close(); + Loader.log.fine(String.format("Configuration for %s written to %s", modConfigName, modConfig.getName())); } catch (IOException e) { @@ -188,7 +194,7 @@ public class ModLoaderModContainer implements ModContainer } } - private Object parseValue(String val, MLProp property, Class type) + private Object parseValue(String val, MLProp property, Class type, String propertyName, String modConfigName) { if (type.isAssignableFrom(String.class)) { @@ -198,41 +204,42 @@ public class ModLoaderModContainer implements ModContainer { return Boolean.parseBoolean(val); } - else if (Number.class.isAssignableFrom(type)) + else if (Number.class.isAssignableFrom(type) || type.isPrimitive()) { Number n = null; - if (Double.class.isAssignableFrom(type)) + if (type.isAssignableFrom(Double.TYPE) || Double.class.isAssignableFrom(type)) { n = Double.parseDouble(val); } - if (Float.class.isAssignableFrom(type)) + else if (type.isAssignableFrom(Float.TYPE) || Float.class.isAssignableFrom(type)) { n = Float.parseFloat(val); } - if (Long.class.isAssignableFrom(type)) + else if (type.isAssignableFrom(Long.TYPE) || Long.class.isAssignableFrom(type)) { n = Long.parseLong(val); } - if (Integer.class.isAssignableFrom(type)) + else if (type.isAssignableFrom(Integer.TYPE) || Integer.class.isAssignableFrom(type)) { n = Integer.parseInt(val); } - if (Short.class.isAssignableFrom(type)) + else if (type.isAssignableFrom(Short.TYPE) || Short.class.isAssignableFrom(type)) { n = Short.parseShort(val); } - if (Byte.class.isAssignableFrom(type)) + else if (type.isAssignableFrom(Byte.TYPE) || Byte.class.isAssignableFrom(type)) { n = Byte.parseByte(val); } else { - throw new IllegalArgumentException("MLProp declared on non-standard type"); + throw new IllegalArgumentException(String.format("MLProp declared on %s of type %s, an unsupported type",propertyName, type.getName())); } if (n.doubleValue() < property.min() || n.doubleValue() > property.max()) { + Loader.log.warning(String.format("Configuration for %s.%s found value %s outside acceptable range %s,%s", modConfigName,propertyName, n, property.min(), property.max())); return null; } else @@ -241,7 +248,7 @@ public class ModLoaderModContainer implements ModContainer } } - return null; + throw new IllegalArgumentException(String.format("MLProp declared on %s of type %s, an unsupported type",propertyName, type.getName())); } private String extractValue(Object value) { diff --git a/bukkit/net/minecraft/server/MLProp.java b/bukkit/net/minecraft/server/MLProp.java index 25a20cbbd2..e17928d3d0 100644 --- a/bukkit/net/minecraft/server/MLProp.java +++ b/bukkit/net/minecraft/server/MLProp.java @@ -33,12 +33,12 @@ String info() default ""; /** * Maximum value allowed if field is a number. */ -double max() default 1D; + double max() default Double.MAX_VALUE; /** * Minimum value allowed if field is a number. */ -double min() default -1D; + double min() default Double.MIN_VALUE; /** * Overrides the field name for property key. From 6b286543d40b890a1ccb333c54a967a3a711f446 Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Sat, 28 Apr 2012 16:47:04 -0400 Subject: [PATCH 6/6] Fix copied code. Derpbag. --- bukkit/cpw/mods/fml/server/FMLBukkitHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java b/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java index f552501cdc..5e0286bb5d 100644 --- a/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java +++ b/bukkit/cpw/mods/fml/server/FMLBukkitHandler.java @@ -82,7 +82,7 @@ public class FMLBukkitHandler implements IFMLSidedHandler try { Class.forName("BaseModMp", false, getClass().getClassLoader()); - MinecraftServer.field_6038_a.severe("" + MinecraftServer.log.severe("" + "Forge Mod Loader has detected that this server has an ModLoaderMP installed alongside Forge Mod Loader.\n" + "This will cause a serious problem with compatibility. To protect your worlds, this minecraft server will now shutdown.\n" + "You should follow the installation instructions of either Minecraft Forge of Forge Mod Loader and NOT install ModLoaderMP \n"