robot code changes - @hea3ven please review
This commit is contained in:
parent
097492883d
commit
7fa702a3ae
4 changed files with 21 additions and 7 deletions
|
@ -35,6 +35,8 @@ public final class SchematicRegistry implements ISchematicRegistry {
|
|||
|
||||
public final HashMap<Class<? extends Entity>, SchematicConstructor> schematicEntities = new HashMap<Class<? extends Entity>, SchematicConstructor>();
|
||||
|
||||
private static final HashMap<Class<? extends Schematic>, Constructor<?>> emptyConstructorMap = new HashMap<Class<? extends Schematic>, Constructor<?>>();
|
||||
|
||||
private final HashSet<String> modsForbidden = new HashSet<String>();
|
||||
private final HashSet<String> blocksForbidden = new HashSet<String>();
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@ import buildcraft.api.statements.StatementSlot;
|
|||
|
||||
public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot {
|
||||
|
||||
private BlockIndex indexStored;
|
||||
protected BlockIndex indexStored;
|
||||
|
||||
private ArrayList<Block> blockFilter = new ArrayList<Block>();
|
||||
private ArrayList<Integer> metaFilter = new ArrayList<Integer>();
|
||||
|
||||
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue