From 7fa702a3ae3cf9a5343f791280e60b601de308b4 Mon Sep 17 00:00:00 2001 From: asiekierka Date: Mon, 23 Mar 2015 23:16:00 +0100 Subject: [PATCH] robot code changes - @hea3ven please review --- .../core/blueprints/SchematicRegistry.java | 9 +++++++++ common/buildcraft/robotics/ai/AIRobotBreak.java | 1 - .../boards/BoardRobotGenericBreakBlock.java | 16 +++++++++++----- .../robotics/boards/BoardRobotHarvesterNBT.java | 2 +- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/common/buildcraft/core/blueprints/SchematicRegistry.java b/common/buildcraft/core/blueprints/SchematicRegistry.java index 2caaafac..129968ca 100644 --- a/common/buildcraft/core/blueprints/SchematicRegistry.java +++ b/common/buildcraft/core/blueprints/SchematicRegistry.java @@ -35,6 +35,8 @@ public final class SchematicRegistry implements ISchematicRegistry { public final HashMap, SchematicConstructor> schematicEntities = new HashMap, SchematicConstructor>(); + private static final HashMap, Constructor> emptyConstructorMap = new HashMap, Constructor>(); + private final HashSet modsForbidden = new HashSet(); private final HashSet blocksForbidden = new HashSet(); @@ -58,6 +60,10 @@ public final class SchematicRegistry implements ISchematicRegistry { } private Constructor findConstructor() throws IllegalArgumentException { + if (params.length == 0 && emptyConstructorMap.containsKey(clazz)) { + return emptyConstructorMap.get(clazz); + } + for (Constructor c : clazz.getConstructors()) { Class[] typesSignature = c.getParameterTypes(); if (typesSignature.length != params.length) { @@ -83,6 +89,9 @@ public final class SchematicRegistry implements ISchematicRegistry { if (!valid) { continue; } + if (c != null && params.length == 0) { + emptyConstructorMap.put(clazz, c); + } return c; } throw new IllegalArgumentException("Builder: Could not find matching constructor for class " + clazz); diff --git a/common/buildcraft/robotics/ai/AIRobotBreak.java b/common/buildcraft/robotics/ai/AIRobotBreak.java index 2e0da5a1..796ab8ad 100644 --- a/common/buildcraft/robotics/ai/AIRobotBreak.java +++ b/common/buildcraft/robotics/ai/AIRobotBreak.java @@ -56,7 +56,6 @@ public class AIRobotBreak extends AIRobot { @Override public void update() { - if (block == null || block.isAir(robot.worldObj, blockToBreak.x, blockToBreak.y, blockToBreak.z)) { terminate(); } diff --git a/common/buildcraft/robotics/boards/BoardRobotGenericBreakBlock.java b/common/buildcraft/robotics/boards/BoardRobotGenericBreakBlock.java index 15268d20..37ffdb3f 100644 --- a/common/buildcraft/robotics/boards/BoardRobotGenericBreakBlock.java +++ b/common/buildcraft/robotics/boards/BoardRobotGenericBreakBlock.java @@ -37,7 +37,8 @@ import buildcraft.api.statements.StatementSlot; public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot { - private BlockIndex indexStored; + protected BlockIndex indexStored; + private ArrayList blockFilter = new ArrayList(); private ArrayList metaFilter = new ArrayList(); @@ -54,11 +55,12 @@ public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot { */ public abstract boolean isExpectedBlock(World world, int x, int y, int z); - public final void preemt(AIRobot ai) { + @Override + public final void preempt(AIRobot ai) { if (ai instanceof AIRobotSearchBlock) { BlockIndex index = ((AIRobotSearchBlock) ai).blockFound; - if (!robot.getRegistry().isTaken(new ResourceIdBlock(index))) { + if (robot.getRegistry().isTaken(new ResourceIdBlock(index))) { abortDelegateAI(); } } @@ -105,12 +107,16 @@ public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot { } } } else if (ai instanceof AIRobotGotoBlock) { - startDelegateAI(new AIRobotBreak(robot, indexStored)); - } else if (ai instanceof AIRobotBreak) { + startDelegateAI(getBlockBreakAI()); + } else if (ai.getClass().isInstance(getBlockBreakAI())) { releaseBlockFound(); } } + protected AIRobot getBlockBreakAI() { + return new AIRobotBreak(robot, indexStored); + } + private void releaseBlockFound() { if (indexStored != null) { robot.getRegistry().release(new ResourceIdBlock(indexStored)); diff --git a/common/buildcraft/robotics/boards/BoardRobotHarvesterNBT.java b/common/buildcraft/robotics/boards/BoardRobotHarvesterNBT.java index ee6b81f4..23232218 100755 --- a/common/buildcraft/robotics/boards/BoardRobotHarvesterNBT.java +++ b/common/buildcraft/robotics/boards/BoardRobotHarvesterNBT.java @@ -64,4 +64,4 @@ public final class BoardRobotHarvesterNBT extends RedstoneBoardRobotNBT { public ResourceLocation getRobotTexture() { return TEXTURE; } -} +} \ No newline at end of file