API change: make WorldProperties a HashMap and not hardcoded
This commit is contained in:
parent
d6dce9ee44
commit
76edcc657d
|
@ -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<Block> softBlocks = new HashSet<Block>();
|
||||
|
||||
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<String, IWorldProperty> worldProperties = new HashMap<String, IWorldProperty>();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue