use of mcjty.rftoolscontrol.logic.compiled.CompiledOpcode in project RFToolsControl by McJty.
the class ProcessorTileEntity method getCraftableItems.
public void getCraftableItems(List<ItemStack> stacks) {
try {
for (CardInfo info : cardInfo) {
CompiledCard compiledCard = info.getCompiledCard();
if (compiledCard != null) {
for (CompiledEvent event : compiledCard.getEvents(Opcodes.EVENT_CRAFT)) {
int index = event.getIndex();
CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
ItemStack stack = evaluateItemParameter(compiledOpcode, null, 0);
Inventory inv = evaluateInventoryParameter(compiledOpcode, null, 1);
if (!stack.isEmpty() && inv != null) {
throw new ProgException(EXCEPT_BADPARAMETERS);
}
if (stack.isEmpty() && inv == null) {
throw new ProgException(EXCEPT_BADPARAMETERS);
}
if (!stack.isEmpty()) {
stacks.add(stack);
} else {
// Find all crafting cards in the inventory
IItemHandler handler = getItemHandlerAt(inv);
for (int i = 0; i < handler.getSlots(); i++) {
ItemStack s = handler.getStackInSlot(i);
if (!s.isEmpty() && s.getItem() == ModItems.craftingCardItem) {
ItemStack result = CraftingCardItem.getResult(s);
if (!result.isEmpty()) {
stacks.add(result);
}
}
}
}
}
}
}
} catch (ProgException e) {
exception(e.getExceptionType(), null);
}
}
use of mcjty.rftoolscontrol.logic.compiled.CompiledOpcode in project RFToolsControl by McJty.
the class ProcessorTileEntity method handleEventsRedstoneOn.
private void handleEventsRedstoneOn(int i, CompiledCard compiledCard) {
int redstoneOnMask = powerLevel & ~prevIn;
if (redstoneOnMask != 0) {
for (CompiledEvent event : compiledCard.getEvents(Opcodes.EVENT_REDSTONE_ON)) {
int index = event.getIndex();
CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
BlockSide side = evaluateSideParameter(compiledOpcode, null, 0);
if (side == null || !side.hasNodeName()) {
EnumFacing facing = side == null ? null : side.getSide();
if (facing == null || ((redstoneOnMask >> facing.ordinal()) & 1) == 1) {
runOrQueueEvent(i, event, null, null);
}
}
}
}
}
use of mcjty.rftoolscontrol.logic.compiled.CompiledOpcode in project RFToolsControl by McJty.
the class ProcessorTileEntity method handleEventsRedstoneOff.
private void handleEventsRedstoneOff(int i, CompiledCard compiledCard) {
int redstoneOffMask = prevIn & ~powerLevel;
if (redstoneOffMask != 0) {
for (CompiledEvent event : compiledCard.getEvents(Opcodes.EVENT_REDSTONE_OFF)) {
int index = event.getIndex();
CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
BlockSide side = evaluateSideParameter(compiledOpcode, null, 0);
if (side == null || !side.hasNodeName()) {
EnumFacing facing = side == null ? null : side.getSide();
if (facing == null || ((redstoneOffMask >> facing.ordinal()) & 1) == 1) {
runOrQueueEvent(i, event, null, null);
}
}
}
}
}
use of mcjty.rftoolscontrol.logic.compiled.CompiledOpcode in project RFToolsControl by McJty.
the class RunningProgram method run.
public boolean run(ProcessorTileEntity processor) {
if (delay > 0) {
delay--;
return false;
}
if (lock != null) {
if (processor.testLock(lock)) {
return false;
}
lock = null;
}
try {
CompiledOpcode opcode = opcodes(processor).get(current);
if (DEBUG) {
System.out.println(opcode.getOpcode());
}
IOpcodeRunnable.OpcodeResult result = opcode.run(processor, this);
if (result == IOpcodeRunnable.OpcodeResult.POSITIVE) {
current = opcode.getPrimaryIndex();
} else if (result == IOpcodeRunnable.OpcodeResult.NEGATIVE) {
current = opcode.getSecondaryIndex();
} else {
// Stay at this opcode
}
} catch (ProgException e) {
throw e;
} catch (Exception e) {
LogManager.getLogger().log(Level.ERROR, "Opcode failed with: ", e);
throw new ProgException(ExceptionType.EXCEPT_INTERNALERROR);
}
return true;
}
Aggregations