use of pneumaticCraft.common.recipes.programs.AssemblyProgram.EnumMachine in project PneumaticCraft by MineMaarten.
the class TileEntityAssemblyController method updateEntity.
@Override
public void updateEntity() {
if (!worldObj.isRemote && firstRun)
updateConnections();
// curProgram must be available on the client, or we can't show program-problems in the GUI
if (curProgram == null && !goingToHomePosition && inventory[PROGRAM_INVENTORY_INDEX] != null && inventory[PROGRAM_INVENTORY_INDEX].getItem() == Itemss.assemblyProgram) {
AssemblyProgram program = ItemAssemblyProgram.getProgramFromItem(inventory[PROGRAM_INVENTORY_INDEX].getItemDamage());
curProgram = program;
} else if (curProgram != null && (inventory[PROGRAM_INVENTORY_INDEX] == null || curProgram.getClass() != ItemAssemblyProgram.getProgramFromItem(inventory[PROGRAM_INVENTORY_INDEX].getItemDamage()).getClass())) {
curProgram = null;
if (!worldObj.isRemote)
goingToHomePosition = true;
}
if (!worldObj.isRemote) {
displayedText = "Standby";
if (getPressure(ForgeDirection.UNKNOWN) >= PneumaticValues.MIN_PRESSURE_ASSEMBLY_CONTROLLER) {
if (curProgram != null || goingToHomePosition) {
List<IAssemblyMachine> machineList = getMachines();
EnumMachine[] requiredMachines = curProgram != null ? curProgram.getRequiredMachines() : EnumMachine.values();
TileEntityAssemblyDrill drill = null;
TileEntityAssemblyLaser laser = null;
TileEntityAssemblyIOUnit ioUnitImport = null;
TileEntityAssemblyIOUnit ioUnitExport = null;
TileEntityAssemblyPlatform platform = null;
foundDuplicateMachine = false;
boolean[] foundMachines = new boolean[requiredMachines.length];
for (IAssemblyMachine machine : machineList) {
if (machine != this && machine instanceof TileEntityAssemblyController)
foundDuplicateMachine = true;
for (int i = 0; i < requiredMachines.length; i++) {
switch(requiredMachines[i]) {
case DRILL:
if (machine instanceof TileEntityAssemblyDrill) {
if (drill != null)
foundDuplicateMachine = true;
drill = (TileEntityAssemblyDrill) machine;
foundMachines[i] = true;
}
break;
case LASER:
if (machine instanceof TileEntityAssemblyLaser) {
if (laser != null)
foundDuplicateMachine = true;
laser = (TileEntityAssemblyLaser) machine;
foundMachines[i] = true;
}
break;
case IO_UNIT_IMPORT:
if (machine instanceof TileEntityAssemblyIOUnit && ((TileEntityAssemblyIOUnit) machine).getBlockMetadata() == 0) {
if (ioUnitImport != null)
foundDuplicateMachine = true;
ioUnitImport = (TileEntityAssemblyIOUnit) machine;
foundMachines[i] = true;
}
break;
case IO_UNIT_EXPORT:
if (machine instanceof TileEntityAssemblyIOUnit && ((TileEntityAssemblyIOUnit) machine).getBlockMetadata() == 1) {
if (ioUnitExport != null)
foundDuplicateMachine = true;
ioUnitExport = (TileEntityAssemblyIOUnit) machine;
foundMachines[i] = true;
}
break;
case PLATFORM:
if (machine instanceof TileEntityAssemblyPlatform) {
if (platform != null)
foundDuplicateMachine = true;
platform = (TileEntityAssemblyPlatform) machine;
foundMachines[i] = true;
}
break;
}
}
}
foundAllMachines = true;
for (boolean foundMachine : foundMachines) {
if (!foundMachine) {
foundAllMachines = false;
break;
}
}
if ((foundAllMachines || curProgram == null) && !foundDuplicateMachine) {
// if(firstRun || areAllMachinesDone(machineList)) {
boolean useAir;
if (curProgram != null) {
useAir = curProgram.executeStep(this, platform, ioUnitImport, ioUnitExport, drill, laser);
if (useAir)
displayedText = "Running...";
} else {
useAir = true;
goToHomePosition(platform, ioUnitImport, ioUnitExport, drill, laser);
displayedText = "Resetting...";
}
if (useAir)
addAir(-(int) (PneumaticValues.USAGE_ASSEMBLING * getSpeedUsageMultiplierFromUpgrades(getUpgradeSlots())), ForgeDirection.UNKNOWN);
float speedMultiplier = getSpeedMultiplierFromUpgrades(getUpgradeSlots());
for (IAssemblyMachine machine : machineList) {
machine.setSpeed(speedMultiplier);
}
}
}
}
hasProblem = hasProblem();
}
super.updateEntity();
}
Aggregations