use of muramasa.antimatter.cover.CoverStack in project GT-4-Reimagined by Trinsdar.
the class CoverConveyor method onUpdate.
@Override
public void onUpdate(CoverStack<?> instance, Direction side) {
if (instance.getTile() == null || instance.getTile().getWorld().getGameTime() % (speeds.get(tier)) != 0)
return;
boolean isMachine = instance.getTile() instanceof TileEntityMachine;
BlockState state = instance.getTile().getWorld().getBlockState(instance.getTile().getPos().offset(side));
// Drop into world.
if (state == Blocks.AIR.getDefaultState() && isMachine) {
World world = instance.getTile().getWorld();
BlockPos pos = instance.getTile().getPos();
ItemStack stack = ((TileEntityMachine) instance.getTile()).itemHandler.map(ih -> Utils.extractAny(ih.getOutputHandler())).orElse(ItemStack.EMPTY);
if (stack.isEmpty())
return;
world.addEntity(new ItemEntity(world, pos.getX() + side.getXOffset(), pos.getY() + side.getYOffset(), pos.getZ() + side.getZOffset(), stack));
}
if (!(state.hasTileEntity()))
return;
TileEntity adjTile = instance.getTile().getWorld().getTileEntity(instance.getTile().getPos().offset(side));
if (adjTile == null) {
return;
}
if (isMachine) {
((TileEntityMachine) instance.getTile()).itemHandler.ifPresent(ih -> adjTile.getCapability(ITEM_HANDLER_CAPABILITY).ifPresent(other -> Utils.transferItems(ih.getOutputHandler(), other, true)));
} else {
Utils.transferItemsOnCap(instance.getTile(), adjTile, true);
}
}
Aggregations