robot code changes - @hea3ven please review
This commit is contained in:
parent
097492883d
commit
7fa702a3ae
|
@ -35,6 +35,8 @@ public final class SchematicRegistry implements ISchematicRegistry {
|
||||||
|
|
||||||
public final HashMap<Class<? extends Entity>, SchematicConstructor> schematicEntities = new HashMap<Class<? extends Entity>, SchematicConstructor>();
|
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> modsForbidden = new HashSet<String>();
|
||||||
private final HashSet<String> blocksForbidden = 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 {
|
private Constructor<?> findConstructor() throws IllegalArgumentException {
|
||||||
|
if (params.length == 0 && emptyConstructorMap.containsKey(clazz)) {
|
||||||
|
return emptyConstructorMap.get(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
for (Constructor<?> c : clazz.getConstructors()) {
|
for (Constructor<?> c : clazz.getConstructors()) {
|
||||||
Class<?>[] typesSignature = c.getParameterTypes();
|
Class<?>[] typesSignature = c.getParameterTypes();
|
||||||
if (typesSignature.length != params.length) {
|
if (typesSignature.length != params.length) {
|
||||||
|
@ -83,6 +89,9 @@ public final class SchematicRegistry implements ISchematicRegistry {
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (c != null && params.length == 0) {
|
||||||
|
emptyConstructorMap.put(clazz, c);
|
||||||
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Builder: Could not find matching constructor for class " + clazz);
|
throw new IllegalArgumentException("Builder: Could not find matching constructor for class " + clazz);
|
||||||
|
|
|
@ -56,7 +56,6 @@ public class AIRobotBreak extends AIRobot {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
|
|
||||||
if (block == null || block.isAir(robot.worldObj, blockToBreak.x, blockToBreak.y, blockToBreak.z)) {
|
if (block == null || block.isAir(robot.worldObj, blockToBreak.x, blockToBreak.y, blockToBreak.z)) {
|
||||||
terminate();
|
terminate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,8 @@ import buildcraft.api.statements.StatementSlot;
|
||||||
|
|
||||||
public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot {
|
public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot {
|
||||||
|
|
||||||
private BlockIndex indexStored;
|
protected BlockIndex indexStored;
|
||||||
|
|
||||||
private ArrayList<Block> blockFilter = new ArrayList<Block>();
|
private ArrayList<Block> blockFilter = new ArrayList<Block>();
|
||||||
private ArrayList<Integer> metaFilter = new ArrayList<Integer>();
|
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 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) {
|
if (ai instanceof AIRobotSearchBlock) {
|
||||||
BlockIndex index = ((AIRobotSearchBlock) ai).blockFound;
|
BlockIndex index = ((AIRobotSearchBlock) ai).blockFound;
|
||||||
|
|
||||||
if (!robot.getRegistry().isTaken(new ResourceIdBlock(index))) {
|
if (robot.getRegistry().isTaken(new ResourceIdBlock(index))) {
|
||||||
abortDelegateAI();
|
abortDelegateAI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,12 +107,16 @@ public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ai instanceof AIRobotGotoBlock) {
|
} else if (ai instanceof AIRobotGotoBlock) {
|
||||||
startDelegateAI(new AIRobotBreak(robot, indexStored));
|
startDelegateAI(getBlockBreakAI());
|
||||||
} else if (ai instanceof AIRobotBreak) {
|
} else if (ai.getClass().isInstance(getBlockBreakAI())) {
|
||||||
releaseBlockFound();
|
releaseBlockFound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected AIRobot getBlockBreakAI() {
|
||||||
|
return new AIRobotBreak(robot, indexStored);
|
||||||
|
}
|
||||||
|
|
||||||
private void releaseBlockFound() {
|
private void releaseBlockFound() {
|
||||||
if (indexStored != null) {
|
if (indexStored != null) {
|
||||||
robot.getRegistry().release(new ResourceIdBlock(indexStored));
|
robot.getRegistry().release(new ResourceIdBlock(indexStored));
|
||||||
|
|
Loading…
Reference in a new issue