diff --git a/api/buildcraft/api/robots/AIRobot.java b/api/buildcraft/api/robots/AIRobot.java index 47428c84..f03b6ad3 100755 --- a/api/buildcraft/api/robots/AIRobot.java +++ b/api/buildcraft/api/robots/AIRobot.java @@ -148,7 +148,7 @@ public class AIRobot { } public final void writeToNBT(NBTTagCompound nbt) { - nbt.setString("class", getClass().getCanonicalName()); + nbt.setString("aiName", AIRobotManager.getAIRobotName(getClass())); NBTTagCompound data = new NBTTagCompound(); writeSelfToNBT(data); @@ -169,7 +169,14 @@ public class AIRobot { NBTTagCompound sub = nbt.getCompoundTag("delegateAI"); try { - delegateAI = (AIRobot) Class.forName(sub.getString("class")).getConstructor(EntityRobotBase.class) + Class aiRobotClass = null; + if (sub.hasKey("class")) { + // Migration support for 6.4.x + aiRobotClass = AIRobotManager.getAIRobotByLegacyClassName(sub.getString("class")); + } else { + aiRobotClass = AIRobotManager.getAIRobotByName(sub.getString("aiName")); + } + delegateAI = (AIRobot) aiRobotClass.getConstructor(EntityRobotBase.class) .newInstance(robot); if (delegateAI.canLoadFromNBT()) { @@ -186,7 +193,14 @@ public class AIRobot { AIRobot ai = null; try { - ai = (AIRobot) Class.forName(nbt.getString("class")).getConstructor(EntityRobotBase.class) + Class aiRobotClass = null; + if (nbt.hasKey("class")) { + // Migration support for 6.4.x + aiRobotClass = AIRobotManager.getAIRobotByLegacyClassName(nbt.getString("class")); + } else { + aiRobotClass = AIRobotManager.getAIRobotByName(nbt.getString("aiName")); + } + ai = (AIRobot) aiRobotClass.getConstructor(EntityRobotBase.class) .newInstance(robot); ai.loadFromNBT(nbt); } catch (Throwable e) { diff --git a/api/buildcraft/api/robots/AIRobotManager.java b/api/buildcraft/api/robots/AIRobotManager.java new file mode 100644 index 00000000..927313c8 --- /dev/null +++ b/api/buildcraft/api/robots/AIRobotManager.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.api.robots; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public abstract class AIRobotManager { + + public static ArrayList> aiRobots = new ArrayList>(); + private static Map, String> aiRobotsNames = + new HashMap, String>(); + private static Map> aiRobotsByNames = + new HashMap>(); + private static Map> aiRobotsByLegacyClassNames = + new HashMap>(); + + public static void registerAIRobot(Class aiRobot, String name) { + registerAIRobot(aiRobot, name, null); + } + + public static void registerAIRobot(Class pluggable, String name, String legacyClassName) { + aiRobots.add(pluggable); + aiRobotsByNames.put(name, pluggable); + aiRobotsNames.put(pluggable, name); + if(legacyClassName != null) { + aiRobotsByLegacyClassNames.put(legacyClassName, pluggable); + } + } + + public static Class getAIRobotByName(String pluggableName) { + return aiRobotsByNames.get(pluggableName); + } + + public static String getAIRobotName(Class aClass) { + return aiRobotsNames.get(aClass); + } + + public static Class getAIRobotByLegacyClassName(String string) { + return aiRobotsByLegacyClassNames.get(string); + } +} diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index 002311c6..e4c21fd3 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -65,6 +65,7 @@ import buildcraft.api.core.IWorldProperty; import buildcraft.api.core.JavaTools; import buildcraft.api.fuels.BuildcraftFuelRegistry; import buildcraft.api.recipes.BuildcraftRecipeRegistry; +import buildcraft.api.robots.AIRobotManager; import buildcraft.api.statements.IActionExternal; import buildcraft.api.statements.IActionInternal; import buildcraft.api.statements.IStatement; @@ -97,7 +98,6 @@ import buildcraft.core.recipes.AssemblyRecipeManager; import buildcraft.core.recipes.IntegrationRecipeManager; import buildcraft.core.recipes.RefineryRecipeManager; import buildcraft.core.render.BlockHighlightHandler; -import buildcraft.robots.EntityRobot; import buildcraft.core.statements.ActionMachineControl; import buildcraft.core.statements.ActionRedstoneOutput; import buildcraft.core.statements.DefaultActionProvider; @@ -124,6 +124,62 @@ import buildcraft.core.utils.WorldPropertyIsSoft; import buildcraft.core.utils.WorldPropertyIsWood; import buildcraft.energy.fuels.CoolantManager; import buildcraft.energy.fuels.FuelManager; +import buildcraft.robots.EntityRobot; +import buildcraft.robots.ai.AIRobotAttack; +import buildcraft.robots.ai.AIRobotBreak; +import buildcraft.robots.ai.AIRobotCraftAssemblyTable; +import buildcraft.robots.ai.AIRobotCraftFurnace; +import buildcraft.robots.ai.AIRobotCraftWorkbench; +import buildcraft.robots.ai.AIRobotDeliverRequested; +import buildcraft.robots.ai.AIRobotDisposeItems; +import buildcraft.robots.ai.AIRobotFetchAndEquipItemStack; +import buildcraft.robots.ai.AIRobotFetchItem; +import buildcraft.robots.ai.AIRobotGoAndLinkToDock; +import buildcraft.robots.ai.AIRobotGoto; +import buildcraft.robots.ai.AIRobotGotoBlock; +import buildcraft.robots.ai.AIRobotGotoRandomGroundBlock; +import buildcraft.robots.ai.AIRobotGotoSleep; +import buildcraft.robots.ai.AIRobotGotoStation; +import buildcraft.robots.ai.AIRobotGotoStationAndLoad; +import buildcraft.robots.ai.AIRobotGotoStationAndLoadFluids; +import buildcraft.robots.ai.AIRobotGotoStationAndUnload; +import buildcraft.robots.ai.AIRobotGotoStationToLoad; +import buildcraft.robots.ai.AIRobotGotoStationToLoadFluids; +import buildcraft.robots.ai.AIRobotGotoStationToUnload; +import buildcraft.robots.ai.AIRobotGotoStationToUnloadFluids; +import buildcraft.robots.ai.AIRobotLoad; +import buildcraft.robots.ai.AIRobotLoadFluids; +import buildcraft.robots.ai.AIRobotMain; +import buildcraft.robots.ai.AIRobotPumpBlock; +import buildcraft.robots.ai.AIRobotRecharge; +import buildcraft.robots.ai.AIRobotSearchAndGotoStation; +import buildcraft.robots.ai.AIRobotSearchBlock; +import buildcraft.robots.ai.AIRobotSearchEntity; +import buildcraft.robots.ai.AIRobotSearchRandomGroundBlock; +import buildcraft.robots.ai.AIRobotSearchStackRequest; +import buildcraft.robots.ai.AIRobotSearchStation; +import buildcraft.robots.ai.AIRobotSleep; +import buildcraft.robots.ai.AIRobotStraightMoveTo; +import buildcraft.robots.ai.AIRobotUnload; +import buildcraft.robots.ai.AIRobotUnloadFluids; +import buildcraft.robots.ai.AIRobotUseToolOnBlock; +import buildcraft.robots.boards.BoardRobotBomber; +import buildcraft.robots.boards.BoardRobotBuilder; +import buildcraft.robots.boards.BoardRobotButcher; +import buildcraft.robots.boards.BoardRobotCarrier; +import buildcraft.robots.boards.BoardRobotCrafter; +import buildcraft.robots.boards.BoardRobotDelivery; +import buildcraft.robots.boards.BoardRobotFarmer; +import buildcraft.robots.boards.BoardRobotFluidCarrier; +import buildcraft.robots.boards.BoardRobotHarvester; +import buildcraft.robots.boards.BoardRobotKnight; +import buildcraft.robots.boards.BoardRobotLeaveCutter; +import buildcraft.robots.boards.BoardRobotLumberjack; +import buildcraft.robots.boards.BoardRobotMiner; +import buildcraft.robots.boards.BoardRobotPicker; +import buildcraft.robots.boards.BoardRobotPlanter; +import buildcraft.robots.boards.BoardRobotPump; +import buildcraft.robots.boards.BoardRobotShovelman; @Mod(name = "BuildCraft", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Core", acceptedMinecraftVersions = "[1.7.10,1.8)", dependencies = "required-after:Forge@[10.13.0.1207,)") public class BuildCraftCore extends BuildCraftMod { @@ -355,6 +411,62 @@ public class BuildCraftCore extends BuildCraftMod { StatementManager.registerTriggerProvider(new DefaultTriggerProvider()); StatementManager.registerActionProvider(new DefaultActionProvider()); + AIRobotManager.registerAIRobot(AIRobotMain.class, "aiRobotMain","buildcraft.core.robots.AIRobotMain"); + AIRobotManager.registerAIRobot(BoardRobotBomber.class, "boardRobotBomber", "buildcraft.core.robots.boards.BoardRobotBomber"); + AIRobotManager.registerAIRobot(BoardRobotBuilder.class, "boardRobotBuilder", "buildcraft.core.robots.boards.BoardRobotBuilder"); + AIRobotManager.registerAIRobot(BoardRobotButcher.class, "boardRobotButcher", "buildcraft.core.robots.boards.BoardRobotButcher"); + AIRobotManager.registerAIRobot(BoardRobotCarrier.class, "boardRobotCarrier", "buildcraft.core.robots.boards.BoardRobotCarrier"); + AIRobotManager.registerAIRobot(BoardRobotCrafter.class, "boardRobotCrafter", "buildcraft.core.robots.boards.BoardRobotCrafter"); + AIRobotManager.registerAIRobot(BoardRobotDelivery.class, "boardRobotDelivery", "buildcraft.core.robots.boards.BoardRobotDelivery"); + AIRobotManager.registerAIRobot(BoardRobotFarmer.class, "boardRobotFarmer", "buildcraft.core.robots.boards.BoardRobotFarmer"); + AIRobotManager.registerAIRobot(BoardRobotFluidCarrier.class, "boardRobotFluidCarrier", "buildcraft.core.robots.boards.BoardRobotFluidCarrier"); + AIRobotManager.registerAIRobot(BoardRobotHarvester.class, "boardRobotHarvester", "buildcraft.core.robots.boards.BoardRobotHarvester"); + AIRobotManager.registerAIRobot(BoardRobotKnight.class, "boardRobotKnight", "buildcraft.core.robots.boards.BoardRobotKnight"); + AIRobotManager.registerAIRobot(BoardRobotLeaveCutter.class, "boardRobotLeaveCutter", "buildcraft.core.robots.boards.BoardRobotLeaveCutter"); + AIRobotManager.registerAIRobot(BoardRobotLumberjack.class, "boardRobotLumberjack", "buildcraft.core.robots.boards.BoardRobotLumberjack"); + AIRobotManager.registerAIRobot(BoardRobotMiner.class, "boardRobotMiner", "buildcraft.core.robots.boards.BoardRobotMiner"); + AIRobotManager.registerAIRobot(BoardRobotPicker.class, "boardRobotPicker", "buildcraft.core.robots.boards.BoardRobotPicker"); + AIRobotManager.registerAIRobot(BoardRobotPlanter.class, "boardRobotPlanter", "buildcraft.core.robots.boards.BoardRobotPlanter"); + AIRobotManager.registerAIRobot(BoardRobotPump.class, "boardRobotPump", "buildcraft.core.robots.boards.BoardRobotPump"); + AIRobotManager.registerAIRobot(BoardRobotShovelman.class, "boardRobotShovelman", "buildcraft.core.robots.boards.BoardRobotShovelman"); + AIRobotManager.registerAIRobot(AIRobotAttack.class, "aiRobotAttack", "buildcraft.core.robots.AIRobotAttack"); + AIRobotManager.registerAIRobot(AIRobotBreak.class, "aiRobotBreak", "buildcraft.core.robots.AIRobotBreak"); + AIRobotManager.registerAIRobot(AIRobotCraftAssemblyTable.class, "aiRobotCraftAssemblyTable", "buildcraft.core.robots.AIRobotCraftAssemblyTable"); + AIRobotManager.registerAIRobot(AIRobotCraftFurnace.class, "aiRobotCraftFurnace", "buildcraft.core.robots.AIRobotCraftFurnace"); + AIRobotManager.registerAIRobot(AIRobotCraftWorkbench.class, "aiRobotCraftWorkbench", "buildcraft.core.robots.AIRobotCraftWorkbench"); + AIRobotManager.registerAIRobot(AIRobotDeliverRequested.class, "aiRobotDeliverRequested", "buildcraft.core.robots.AIRobotDeliverRequested"); + AIRobotManager.registerAIRobot(AIRobotDisposeItems.class, "aiRobotDisposeItems", "buildcraft.core.robots.AIRobotDisposeItems"); + AIRobotManager.registerAIRobot(AIRobotFetchAndEquipItemStack.class, "aiRobotFetchAndEquipItemStack", "buildcraft.core.robots.AIRobotFetchAndEquipItemStack"); + AIRobotManager.registerAIRobot(AIRobotFetchItem.class, "aiRobotFetchItem", "buildcraft.core.robots.AIRobotFetchItem"); + AIRobotManager.registerAIRobot(AIRobotGoAndLinkToDock.class, "aiRobotGoAndLinkToDock", "buildcraft.core.robots.AIRobotGoAndLinkToDock"); + AIRobotManager.registerAIRobot(AIRobotGoto.class, "aiRobotGoto", "buildcraft.core.robots.AIRobotGoto"); + AIRobotManager.registerAIRobot(AIRobotGotoBlock.class, "aiRobotGotoBlock", "buildcraft.core.robots.AIRobotGotoBlock"); + AIRobotManager.registerAIRobot(AIRobotGotoRandomGroundBlock.class, "aiRobotGotoRandomGroundBlock", "buildcraft.core.robots.AIRobotGotoRandomGroundBlock"); + AIRobotManager.registerAIRobot(AIRobotGotoSleep.class, "aiRobotGotoSleep", "buildcraft.core.robots.AIRobotGotoSleep"); + AIRobotManager.registerAIRobot(AIRobotGotoStation.class, "aiRobotGotoStation", "buildcraft.core.robots.AIRobotGotoStation"); + AIRobotManager.registerAIRobot(AIRobotGotoStationAndLoad.class, "aiRobotGotoStationAndLoad", "buildcraft.core.robots.AIRobotGotoStationAndLoad"); + AIRobotManager.registerAIRobot(AIRobotGotoStationAndLoadFluids.class, "aiRobotGotoStationAndLoadFluids", "buildcraft.core.robots.AIRobotGotoStationAndLoadFluids"); + AIRobotManager.registerAIRobot(AIRobotGotoStationAndUnload.class, "aiRobotGotoStationAndUnload", "buildcraft.core.robots.AIRobotGotoStationAndUnload"); + AIRobotManager.registerAIRobot(AIRobotGotoStationToLoad.class, "aiRobotGotoStationToLoad", "buildcraft.core.robots.AIRobotGotoStationToLoad"); + AIRobotManager.registerAIRobot(AIRobotGotoStationToLoadFluids.class, "aiRobotGotoStationToLoadFluids", "buildcraft.core.robots.AIRobotGotoStationToLoadFluids"); + AIRobotManager.registerAIRobot(AIRobotGotoStationToUnload.class, "aiRobotGotoStationToUnload", "buildcraft.core.robots.AIRobotGotoStationToUnload"); + AIRobotManager.registerAIRobot(AIRobotGotoStationToUnloadFluids.class, "aiRobotGotoStationToUnloadFluids", "buildcraft.core.robots.AIRobotGotoStationToUnloadFluids"); + AIRobotManager.registerAIRobot(AIRobotLoad.class, "aiRobotLoad", "buildcraft.core.robots.AIRobotLoad"); + AIRobotManager.registerAIRobot(AIRobotLoadFluids.class, "aiRobotLoadFluids", "buildcraft.core.robots.AIRobotLoadFluids"); + AIRobotManager.registerAIRobot(AIRobotPumpBlock.class, "aiRobotPumpBlock", "buildcraft.core.robots.AIRobotPumpBlock"); + AIRobotManager.registerAIRobot(AIRobotRecharge.class, "aiRobotRecharge", "buildcraft.core.robots.AIRobotRecharge"); + AIRobotManager.registerAIRobot(AIRobotSearchAndGotoStation.class, "aiRobotSearchAndGotoStation", "buildcraft.core.robots.AIRobotSearchAndGotoStation"); + AIRobotManager.registerAIRobot(AIRobotSearchBlock.class, "aiRobotSearchBlock", "buildcraft.core.robots.AIRobotSearchBlock"); + AIRobotManager.registerAIRobot(AIRobotSearchEntity.class, "aiRobotSearchEntity", "buildcraft.core.robots.AIRobotSearchEntity"); + AIRobotManager.registerAIRobot(AIRobotSearchRandomGroundBlock.class, "aiRobotSearchRandomGroundBlock", "buildcraft.core.robots.AIRobotSearchRandomGroundBlock"); + AIRobotManager.registerAIRobot(AIRobotSearchStackRequest.class, "aiRobotSearchStackRequest", "buildcraft.core.robots.AIRobotSearchStackRequest"); + AIRobotManager.registerAIRobot(AIRobotSearchStation.class, "aiRobotSearchStation", "buildcraft.core.robots.AIRobotSearchStation"); + AIRobotManager.registerAIRobot(AIRobotSleep.class, "aiRobotSleep", "buildcraft.core.robots.AIRobotSleep"); + AIRobotManager.registerAIRobot(AIRobotStraightMoveTo.class, "aiRobotStraightMoveTo", "buildcraft.core.robots.AIRobotStraightMoveTo"); + AIRobotManager.registerAIRobot(AIRobotUnload.class, "aiRobotUnload", "buildcraft.core.robots.AIRobotUnload"); + AIRobotManager.registerAIRobot(AIRobotUnloadFluids.class, "aiRobotUnloadFluids", "buildcraft.core.robots.AIRobotUnloadFluids"); + AIRobotManager.registerAIRobot(AIRobotUseToolOnBlock.class, "aiRobotUseToolOnBlock", "buildcraft.core.robots.AIRobotUseToolOnBlock"); + if (BuildCraftCore.modifyWorld) { MinecraftForge.EVENT_BUS.register(new SpringPopulate()); } diff --git a/common/buildcraft/transport/TileGenericPipe.java b/common/buildcraft/transport/TileGenericPipe.java index 89b9e2dc..0723645c 100644 --- a/common/buildcraft/transport/TileGenericPipe.java +++ b/common/buildcraft/transport/TileGenericPipe.java @@ -141,7 +141,8 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler, pluggableClass = FacadePluggable.class; } else if ("buildcraft.transport.ItemPlug$PlugPluggable".equals(c)) { pluggableClass = PlugPluggable.class; - } else if ("buildcraft.transport.gates.ItemRobotStation$RobotStationPluggable".equals(c)) { + } else if ("buildcraft.transport.gates.ItemRobotStation$RobotStationPluggable".equals(c) + || "buildcraft.transport.ItemRobotStation$RobotStationPluggable".equals(c)) { pluggableClass = PipeManager.getPluggableByName("robotStation"); } } else {