API change: make WorldProperties a HashMap and not hardcoded
This commit is contained in:
parent
d6dce9ee44
commit
76edcc657d
9 changed files with 38 additions and 40 deletions
|
@ -8,6 +8,7 @@
|
||||||
*/
|
*/
|
||||||
package buildcraft.api.core;
|
package buildcraft.api.core;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -19,16 +20,7 @@ public final class BuildCraftAPI {
|
||||||
public static ICoreProxy proxy;
|
public static ICoreProxy proxy;
|
||||||
|
|
||||||
public static final Set<Block> softBlocks = new HashSet<Block>();
|
public static final Set<Block> softBlocks = new HashSet<Block>();
|
||||||
|
public static final HashMap<String, IWorldProperty> worldProperties = new HashMap<String, IWorldProperty>();
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deactivate constructor
|
* Deactivate constructor
|
||||||
|
@ -36,7 +28,18 @@ public final class BuildCraftAPI {
|
||||||
private 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) {
|
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,)")
|
@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 {
|
public class BuildCraftCore extends BuildCraftMod {
|
||||||
|
|
||||||
@Mod.Instance("BuildCraft|Core")
|
@Mod.Instance("BuildCraft|Core")
|
||||||
public static BuildCraftCore instance;
|
public static BuildCraftCore instance;
|
||||||
|
|
||||||
|
@ -516,18 +515,17 @@ public class BuildCraftCore extends BuildCraftMod {
|
||||||
|
|
||||||
FMLCommonHandler.instance().bus().register(new TickHandlerCore());
|
FMLCommonHandler.instance().bus().register(new TickHandlerCore());
|
||||||
|
|
||||||
BuildCraftAPI.isSoftProperty = new WorldPropertyIsSoft();
|
BuildCraftAPI.registerWorldProperty("soft", new WorldPropertyIsSoft());
|
||||||
BuildCraftAPI.isWoodProperty = new WorldPropertyIsWood();
|
BuildCraftAPI.registerWorldProperty("wood", new WorldPropertyIsWood());
|
||||||
BuildCraftAPI.isLeavesProperty = new WorldPropertyIsLeaf();
|
BuildCraftAPI.registerWorldProperty("leaves", new WorldPropertyIsLeaf());
|
||||||
BuildCraftAPI.isOreProperty = new IWorldProperty[4];
|
for (int i = 0; i < 4; i++) {
|
||||||
for (int i = 0; i < BuildCraftAPI.isOreProperty.length; i++) {
|
BuildCraftAPI.registerWorldProperty("ore@hardness=" + i, new WorldPropertyIsOre(i));
|
||||||
BuildCraftAPI.isOreProperty[i] = new WorldPropertyIsOre(i);
|
|
||||||
}
|
}
|
||||||
BuildCraftAPI.isHarvestableProperty = new WorldPropertyIsHarvestable();
|
BuildCraftAPI.registerWorldProperty("harvestable", new WorldPropertyIsHarvestable());
|
||||||
BuildCraftAPI.isFarmlandProperty = new WorldPropertyIsFarmland();
|
BuildCraftAPI.registerWorldProperty("farmland", new WorldPropertyIsFarmland());
|
||||||
BuildCraftAPI.isShoveled = new WorldPropertyIsShoveled();
|
BuildCraftAPI.registerWorldProperty("shoveled", new WorldPropertyIsShoveled());
|
||||||
BuildCraftAPI.isDirtProperty = new WorldPropertyIsDirt();
|
BuildCraftAPI.registerWorldProperty("dirt", new WorldPropertyIsDirt());
|
||||||
BuildCraftAPI.isFluidSource = new WorldPropertyIsFluidSource();
|
BuildCraftAPI.registerWorldProperty("fluidSource", new WorldPropertyIsFluidSource());
|
||||||
|
|
||||||
ColorUtils.initialize();
|
ColorUtils.initialize();
|
||||||
|
|
||||||
|
@ -648,16 +646,9 @@ public class BuildCraftCore extends BuildCraftMod {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void cleanRegistries(WorldEvent.Unload unload) {
|
public void cleanRegistries(WorldEvent.Unload unload) {
|
||||||
BuildCraftAPI.isSoftProperty.clear();
|
for (IWorldProperty property : BuildCraftAPI.worldProperties.values()) {
|
||||||
BuildCraftAPI.isWoodProperty.clear();
|
property.clear();
|
||||||
BuildCraftAPI.isLeavesProperty.clear();
|
|
||||||
for (int i = 0; i < BuildCraftAPI.isOreProperty.length; i++) {
|
|
||||||
BuildCraftAPI.isOreProperty[i].clear();
|
|
||||||
}
|
}
|
||||||
BuildCraftAPI.isHarvestableProperty.clear();
|
|
||||||
BuildCraftAPI.isFarmlandProperty.clear();
|
|
||||||
BuildCraftAPI.isShoveled.clear();
|
|
||||||
BuildCraftAPI.isDirtProperty.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
|
|
|
@ -17,6 +17,7 @@ import buildcraft.api.boards.RedstoneBoardRobot;
|
||||||
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
||||||
import buildcraft.api.core.BlockIndex;
|
import buildcraft.api.core.BlockIndex;
|
||||||
import buildcraft.api.core.BuildCraftAPI;
|
import buildcraft.api.core.BuildCraftAPI;
|
||||||
|
import buildcraft.api.core.IWorldProperty;
|
||||||
import buildcraft.api.robots.AIRobot;
|
import buildcraft.api.robots.AIRobot;
|
||||||
import buildcraft.api.robots.EntityRobotBase;
|
import buildcraft.api.robots.EntityRobotBase;
|
||||||
import buildcraft.core.inventory.filters.IStackFilter;
|
import buildcraft.core.inventory.filters.IStackFilter;
|
||||||
|
@ -44,6 +45,7 @@ public class BoardRobotFarmer extends RedstoneBoardRobot {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
|
final IWorldProperty isDirt = BuildCraftAPI.getWorldProperty("dirt");
|
||||||
if (robot.getHeldItem() == null) {
|
if (robot.getHeldItem() == null) {
|
||||||
startDelegateAI(new AIRobotFetchAndEquipItemStack(robot, new IStackFilter() {
|
startDelegateAI(new AIRobotFetchAndEquipItemStack(robot, new IStackFilter() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,7 +57,7 @@ public class BoardRobotFarmer extends RedstoneBoardRobot {
|
||||||
startDelegateAI(new AIRobotSearchBlock(robot, new IBlockFilter() {
|
startDelegateAI(new AIRobotSearchBlock(robot, new IBlockFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(World world, int x, int y, int z) {
|
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))
|
&& !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z))
|
||||||
&& isAirAbove(world, x, y, z);
|
&& isAirAbove(world, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,6 @@ public class BoardRobotHarvester extends BoardRobotGenericBreakBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isExpectedBlock(World world, int x, int y, int z) {
|
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
|
@Override
|
||||||
public boolean isExpectedBlock(World world, int x, int y, int z) {
|
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
|
@Override
|
||||||
public boolean isExpectedBlock(World world, int x, int y, int z) {
|
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;
|
import buildcraft.robots.ai.AIRobotFetchAndEquipItemStack;
|
||||||
|
|
||||||
public class BoardRobotMiner extends BoardRobotGenericBreakBlock {
|
public class BoardRobotMiner extends BoardRobotGenericBreakBlock {
|
||||||
|
private static final int MAX_HARVEST_LEVEL = 3;
|
||||||
private int harvestLevel = 0;
|
private int harvestLevel = 0;
|
||||||
|
|
||||||
public BoardRobotMiner(EntityRobotBase iRobot) {
|
public BoardRobotMiner(EntityRobotBase iRobot) {
|
||||||
|
@ -58,7 +58,7 @@ public class BoardRobotMiner extends BoardRobotGenericBreakBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isExpectedBlock(World world, int x, int y, int z) {
|
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);
|
.get(world, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import buildcraft.api.boards.RedstoneBoardRobot;
|
||||||
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
||||||
import buildcraft.api.core.BlockIndex;
|
import buildcraft.api.core.BlockIndex;
|
||||||
import buildcraft.api.core.BuildCraftAPI;
|
import buildcraft.api.core.BuildCraftAPI;
|
||||||
|
import buildcraft.api.core.IWorldProperty;
|
||||||
import buildcraft.api.robots.AIRobot;
|
import buildcraft.api.robots.AIRobot;
|
||||||
import buildcraft.api.robots.EntityRobotBase;
|
import buildcraft.api.robots.EntityRobotBase;
|
||||||
import buildcraft.api.statements.IStatementParameter;
|
import buildcraft.api.statements.IStatementParameter;
|
||||||
|
@ -56,6 +57,7 @@ public class BoardRobotPump extends RedstoneBoardRobot {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
|
final IWorldProperty isFluidSource = BuildCraftAPI.getWorldProperty("fluidSource");
|
||||||
FluidStack tank = robot.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid;
|
FluidStack tank = robot.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid;
|
||||||
|
|
||||||
if (tank != null && tank.amount > 0) {
|
if (tank != null && tank.amount > 0) {
|
||||||
|
@ -67,7 +69,7 @@ public class BoardRobotPump extends RedstoneBoardRobot {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(World world, int x, int y, int z) {
|
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))) {
|
&& !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z))) {
|
||||||
return matchesGateFilter(world, x, y, z);
|
return matchesGateFilter(world, x, y, z);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class BoardRobotShovelman extends BoardRobotGenericBreakBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isExpectedBlock(World world, int x, int y, int z) {
|
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