diff --git a/api/buildcraft/api/core/BuildCraftAPI.java b/api/buildcraft/api/core/BuildCraftAPI.java index ece327f9..9cb0b07e 100644 --- a/api/buildcraft/api/core/BuildCraftAPI.java +++ b/api/buildcraft/api/core/BuildCraftAPI.java @@ -8,6 +8,7 @@ */ package buildcraft.api.core; +import java.util.HashMap; import java.util.HashSet; import java.util.Set; @@ -19,16 +20,7 @@ public final class BuildCraftAPI { public static ICoreProxy proxy; public static final Set softBlocks = new HashSet(); - - public static IWorldProperty isSoftProperty; - public static IWorldProperty isWoodProperty; - public static IWorldProperty isLeavesProperty; - public static IWorldProperty[] isOreProperty; - public static IWorldProperty isHarvestableProperty; - public static IWorldProperty isFarmlandProperty; - public static IWorldProperty isDirtProperty; - public static IWorldProperty isShoveled; - public static IWorldProperty isFluidSource; + public static final HashMap worldProperties = new HashMap(); /** * Deactivate constructor @@ -36,7 +28,18 @@ public final class BuildCraftAPI { private BuildCraftAPI() { } + public static IWorldProperty getWorldProperty(String name) { + return worldProperties.get(name); + } + + public static void registerWorldProperty(String name, IWorldProperty property) { + if (worldProperties.containsKey(name)) { + BCLog.logger.warn("The WorldProperty key '" + name + "' is being overidden with " + property.getClass().getSimpleName() + "!"); + } + worldProperties.put(name, property); + } + public static boolean isSoftBlock(World world, int x, int y, int z) { - return isSoftProperty.get(world, x, y, z); + return worldProperties.get("soft").get(world, x, y, z); } } diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index 76663dcd..0c09caef 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -187,7 +187,6 @@ import buildcraft.robots.boards.BoardRobotStripes; @Mod(name = "BuildCraft", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Core", acceptedMinecraftVersions = "[1.7.10,1.8)", dependencies = "required-after:Forge@[10.13.0.1236,)") public class BuildCraftCore extends BuildCraftMod { - @Mod.Instance("BuildCraft|Core") public static BuildCraftCore instance; @@ -516,18 +515,17 @@ public class BuildCraftCore extends BuildCraftMod { FMLCommonHandler.instance().bus().register(new TickHandlerCore()); - BuildCraftAPI.isSoftProperty = new WorldPropertyIsSoft(); - BuildCraftAPI.isWoodProperty = new WorldPropertyIsWood(); - BuildCraftAPI.isLeavesProperty = new WorldPropertyIsLeaf(); - BuildCraftAPI.isOreProperty = new IWorldProperty[4]; - for (int i = 0; i < BuildCraftAPI.isOreProperty.length; i++) { - BuildCraftAPI.isOreProperty[i] = new WorldPropertyIsOre(i); + BuildCraftAPI.registerWorldProperty("soft", new WorldPropertyIsSoft()); + BuildCraftAPI.registerWorldProperty("wood", new WorldPropertyIsWood()); + BuildCraftAPI.registerWorldProperty("leaves", new WorldPropertyIsLeaf()); + for (int i = 0; i < 4; i++) { + BuildCraftAPI.registerWorldProperty("ore@hardness=" + i, new WorldPropertyIsOre(i)); } - BuildCraftAPI.isHarvestableProperty = new WorldPropertyIsHarvestable(); - BuildCraftAPI.isFarmlandProperty = new WorldPropertyIsFarmland(); - BuildCraftAPI.isShoveled = new WorldPropertyIsShoveled(); - BuildCraftAPI.isDirtProperty = new WorldPropertyIsDirt(); - BuildCraftAPI.isFluidSource = new WorldPropertyIsFluidSource(); + BuildCraftAPI.registerWorldProperty("harvestable", new WorldPropertyIsHarvestable()); + BuildCraftAPI.registerWorldProperty("farmland", new WorldPropertyIsFarmland()); + BuildCraftAPI.registerWorldProperty("shoveled", new WorldPropertyIsShoveled()); + BuildCraftAPI.registerWorldProperty("dirt", new WorldPropertyIsDirt()); + BuildCraftAPI.registerWorldProperty("fluidSource", new WorldPropertyIsFluidSource()); ColorUtils.initialize(); @@ -648,16 +646,9 @@ public class BuildCraftCore extends BuildCraftMod { @SubscribeEvent public void cleanRegistries(WorldEvent.Unload unload) { - BuildCraftAPI.isSoftProperty.clear(); - BuildCraftAPI.isWoodProperty.clear(); - BuildCraftAPI.isLeavesProperty.clear(); - for (int i = 0; i < BuildCraftAPI.isOreProperty.length; i++) { - BuildCraftAPI.isOreProperty[i].clear(); + for (IWorldProperty property : BuildCraftAPI.worldProperties.values()) { + property.clear(); } - BuildCraftAPI.isHarvestableProperty.clear(); - BuildCraftAPI.isFarmlandProperty.clear(); - BuildCraftAPI.isShoveled.clear(); - BuildCraftAPI.isDirtProperty.clear(); } @Mod.EventHandler diff --git a/common/buildcraft/robots/boards/BoardRobotFarmer.java b/common/buildcraft/robots/boards/BoardRobotFarmer.java index caec42f1..5c2915be 100644 --- a/common/buildcraft/robots/boards/BoardRobotFarmer.java +++ b/common/buildcraft/robots/boards/BoardRobotFarmer.java @@ -17,6 +17,7 @@ import buildcraft.api.boards.RedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardRobotNBT; import buildcraft.api.core.BlockIndex; import buildcraft.api.core.BuildCraftAPI; +import buildcraft.api.core.IWorldProperty; import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.EntityRobotBase; import buildcraft.core.inventory.filters.IStackFilter; @@ -44,6 +45,7 @@ public class BoardRobotFarmer extends RedstoneBoardRobot { @Override public void update() { + final IWorldProperty isDirt = BuildCraftAPI.getWorldProperty("dirt"); if (robot.getHeldItem() == null) { startDelegateAI(new AIRobotFetchAndEquipItemStack(robot, new IStackFilter() { @Override @@ -55,7 +57,7 @@ public class BoardRobotFarmer extends RedstoneBoardRobot { startDelegateAI(new AIRobotSearchBlock(robot, new IBlockFilter() { @Override public boolean matches(World world, int x, int y, int z) { - return BuildCraftAPI.isDirtProperty.get(world, x, y, z) + return isDirt.get(world, x, y, z) && !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z)) && isAirAbove(world, x, y, z); } diff --git a/common/buildcraft/robots/boards/BoardRobotHarvester.java b/common/buildcraft/robots/boards/BoardRobotHarvester.java index 7e3fa168..5a8097de 100755 --- a/common/buildcraft/robots/boards/BoardRobotHarvester.java +++ b/common/buildcraft/robots/boards/BoardRobotHarvester.java @@ -38,6 +38,6 @@ public class BoardRobotHarvester extends BoardRobotGenericBreakBlock { @Override public boolean isExpectedBlock(World world, int x, int y, int z) { - return BuildCraftAPI.isHarvestableProperty.get(world, x, y, z); + return BuildCraftAPI.getWorldProperty("harvestable").get(world, x, y, z); } } diff --git a/common/buildcraft/robots/boards/BoardRobotLeaveCutter.java b/common/buildcraft/robots/boards/BoardRobotLeaveCutter.java index f97236ad..b4642366 100755 --- a/common/buildcraft/robots/boards/BoardRobotLeaveCutter.java +++ b/common/buildcraft/robots/boards/BoardRobotLeaveCutter.java @@ -34,7 +34,7 @@ public class BoardRobotLeaveCutter extends BoardRobotGenericBreakBlock { @Override public boolean isExpectedBlock(World world, int x, int y, int z) { - return BuildCraftAPI.isLeavesProperty.get(world, x, y, z); + return BuildCraftAPI.getWorldProperty("leaves").get(world, x, y, z); } } diff --git a/common/buildcraft/robots/boards/BoardRobotLumberjack.java b/common/buildcraft/robots/boards/BoardRobotLumberjack.java index 63c0d40c..7b234036 100755 --- a/common/buildcraft/robots/boards/BoardRobotLumberjack.java +++ b/common/buildcraft/robots/boards/BoardRobotLumberjack.java @@ -39,6 +39,6 @@ public class BoardRobotLumberjack extends BoardRobotGenericBreakBlock { @Override public boolean isExpectedBlock(World world, int x, int y, int z) { - return BuildCraftAPI.isWoodProperty.get(world, x, y, z); + return BuildCraftAPI.getWorldProperty("wood").get(world, x, y, z); } } diff --git a/common/buildcraft/robots/boards/BoardRobotMiner.java b/common/buildcraft/robots/boards/BoardRobotMiner.java index 4787a7e0..e53f6fc4 100755 --- a/common/buildcraft/robots/boards/BoardRobotMiner.java +++ b/common/buildcraft/robots/boards/BoardRobotMiner.java @@ -19,7 +19,7 @@ import buildcraft.api.robots.EntityRobotBase; import buildcraft.robots.ai.AIRobotFetchAndEquipItemStack; public class BoardRobotMiner extends BoardRobotGenericBreakBlock { - + private static final int MAX_HARVEST_LEVEL = 3; private int harvestLevel = 0; public BoardRobotMiner(EntityRobotBase iRobot) { @@ -58,7 +58,7 @@ public class BoardRobotMiner extends BoardRobotGenericBreakBlock { @Override public boolean isExpectedBlock(World world, int x, int y, int z) { - return BuildCraftAPI.isOreProperty[Math.min(BuildCraftAPI.isOreProperty.length, harvestLevel)] + return BuildCraftAPI.getWorldProperty("ore@hardness=" + Math.min(MAX_HARVEST_LEVEL, harvestLevel)) .get(world, x, y, z); } diff --git a/common/buildcraft/robots/boards/BoardRobotPump.java b/common/buildcraft/robots/boards/BoardRobotPump.java index 3fbcaa25..7c4e3fa6 100644 --- a/common/buildcraft/robots/boards/BoardRobotPump.java +++ b/common/buildcraft/robots/boards/BoardRobotPump.java @@ -24,6 +24,7 @@ import buildcraft.api.boards.RedstoneBoardRobot; import buildcraft.api.boards.RedstoneBoardRobotNBT; import buildcraft.api.core.BlockIndex; import buildcraft.api.core.BuildCraftAPI; +import buildcraft.api.core.IWorldProperty; import buildcraft.api.robots.AIRobot; import buildcraft.api.robots.EntityRobotBase; import buildcraft.api.statements.IStatementParameter; @@ -56,6 +57,7 @@ public class BoardRobotPump extends RedstoneBoardRobot { @Override public void update() { + final IWorldProperty isFluidSource = BuildCraftAPI.getWorldProperty("fluidSource"); FluidStack tank = robot.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid; if (tank != null && tank.amount > 0) { @@ -67,7 +69,7 @@ public class BoardRobotPump extends RedstoneBoardRobot { @Override public boolean matches(World world, int x, int y, int z) { - if (BuildCraftAPI.isFluidSource.get(world, x, y, z) + if (isFluidSource.get(world, x, y, z) && !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z))) { return matchesGateFilter(world, x, y, z); } else { diff --git a/common/buildcraft/robots/boards/BoardRobotShovelman.java b/common/buildcraft/robots/boards/BoardRobotShovelman.java index d80c6479..ceaad3d4 100755 --- a/common/buildcraft/robots/boards/BoardRobotShovelman.java +++ b/common/buildcraft/robots/boards/BoardRobotShovelman.java @@ -36,7 +36,7 @@ public class BoardRobotShovelman extends BoardRobotGenericBreakBlock { @Override public boolean isExpectedBlock(World world, int x, int y, int z) { - return BuildCraftAPI.isShoveled.get(world, x, y, z); + return BuildCraftAPI.getWorldProperty("shoveled").get(world, x, y, z); } }