use of muramasa.antimatter.tile.TileEntityMachine 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);
}
}
use of muramasa.antimatter.tile.TileEntityMachine in project AntimatterAPI by GregTech-Intergalactical.
the class BlockMachine method createTileEntity.
@Nullable
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
TileEntityMachine machine = (TileEntityMachine) getType().getTileType().create();
machine.ofState(state);
return machine;
}
use of muramasa.antimatter.tile.TileEntityMachine in project AntimatterAPI by GregTech-Intergalactical.
the class BlockMachine method getConfig.
@Override
public ModelConfig getConfig(BlockState state, IBlockReader world, BlockPos.Mutable mut, BlockPos pos) {
Direction facing = state.get(BlockStateProperties.HORIZONTAL_FACING);
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityMachine) {
MachineState machineState = ((TileEntityMachine) tile).getMachineState();
if (((TileEntityMachine) tile).coverHandler.isPresent()) {
CoverHandler<?> h = ((TileEntityMachine) tile).coverHandler.orElse(null);
return config.set(new int[] { h.get(Utils.coverRotateFacing(UP, facing)).skipRender() ? getModelId(facing, UP, machineState) : 0, h.get(Utils.coverRotateFacing(DOWN, facing)).skipRender() ? getModelId(facing, DOWN, machineState) : 0, h.get(Utils.coverRotateFacing(NORTH, facing)).skipRender() ? getModelId(facing, NORTH, machineState) : 0, h.get(Utils.coverRotateFacing(SOUTH, facing)).skipRender() ? getModelId(facing, SOUTH, machineState) : 0, h.get(Utils.coverRotateFacing(WEST, facing)).skipRender() ? getModelId(facing, WEST, machineState) : 0, h.get(Utils.coverRotateFacing(EAST, facing)).skipRender() ? getModelId(facing, EAST, machineState) : 0 });
} else {
return config.set(new int[] { getModelId(facing, UP, machineState), getModelId(facing, DOWN, machineState), getModelId(facing, NORTH, machineState), getModelId(facing, SOUTH, machineState), getModelId(facing, WEST, machineState), getModelId(facing, EAST, machineState) });
}
}
return config.set(new int[] { 0 });
}
use of muramasa.antimatter.tile.TileEntityMachine in project AntimatterAPI by GregTech-Intergalactical.
the class CoverOutput method onMachineEvent.
@Override
public void onMachineEvent(CoverInstance instance, TileEntityMachine tile, IMachineEvent event) {
// TODO: Refactor? <- YES!
if (event == MachineEvent.ITEMS_OUTPUTTED && instance.getNbt().getBoolean(KEY_OUTPUT)) {
Direction outputDir = tile.getOutputFacing();
TileEntity adjTile = Utils.getTile(tile.getWorld(), tile.getPos().offset(outputDir));
if (adjTile == null)
return;
adjTile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, outputDir.getOpposite()).ifPresent(adjHandler -> {
tile.itemHandler.ifPresent(h -> Utils.transferItems(h.getOutputHandler(), adjHandler));
});
} else if (event == MachineEvent.FLUIDS_OUTPUTTED) {
Direction outputDir = tile.getOutputFacing();
TileEntity adjTile = Utils.getTile(tile.getWorld(), tile.getPos().offset(outputDir));
if (adjTile == null)
return;
adjTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, outputDir.getOpposite()).ifPresent(adjHandler -> {
tile.fluidHandler.ifPresent(h -> Utils.transferFluids(h.getOutputTanks(), adjHandler));
});
}
}
use of muramasa.antimatter.tile.TileEntityMachine in project AntimatterAPI by GregTech-Intergalactical.
the class BlockMachine method onBlockActivated.
@Nonnull
@Override
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
if (!world.isRemote) {
TileEntityMachine tile = (TileEntityMachine) world.getTileEntity(pos);
if (tile != null) {
AntimatterCaps.getCustomEnergyHandler(tile).ifPresent(e -> System.out.println(e.getEnergy()));
ItemStack stack = player.getHeldItem(hand);
AntimatterToolType type = Utils.getToolType(player);
if (hand == Hand.MAIN_HAND) {
if (player.getHeldItem(hand).getItem() instanceof ItemCover) {
boolean ok = tile.getCapability(AntimatterCaps.COVERABLE_HANDLER_CAPABILITY, hit.getFace()).map(i -> i.placeCover(player, hit.getFace(), stack, ((ItemCover) stack.getItem()).getCover())).orElse(false);
if (ok) {
return ActionResultType.SUCCESS;
}
}
// Handle tool types.
if (type == WRENCH || type == ELECTRIC_WRENCH) {
boolean ok = player.isCrouching() ? tile.setFacing(Utils.getInteractSide(hit)) : tile.setOutputFacing(Utils.getInteractSide(hit));
return ok ? ActionResultType.SUCCESS : ActionResultType.PASS;
} else if (type == HAMMER) {
tile.toggleMachine();
// TODO: Replace by new TranslationTextComponent()
player.sendMessage(new StringTextComponent("Machine was " + (tile.getMachineState() == MachineState.DISABLED ? "disabled" : "enabled")));
return ActionResultType.SUCCESS;
} else if (type == CROWBAR) {
return tile.getCapability(AntimatterCaps.COVERABLE_HANDLER_CAPABILITY).map(h -> h.removeCover(player, hit.getFace())).orElse(false) ? ActionResultType.SUCCESS : ActionResultType.PASS;
} else if (type == SCREWDRIVER || type == ELECTRIC_SCREWDRIVER) {
CoverInstance<?> instance = tile.getCapability(AntimatterCaps.COVERABLE_HANDLER_CAPABILITY).map(h -> h.get(hit.getFace())).orElse(COVER_EMPTY);
return !instance.isEmpty() && instance.getCover().hasGui() && instance.openGui(player, hit.getFace()) ? ActionResultType.SUCCESS : ActionResultType.PASS;
}
// Has gui?
if (getType().has(MachineFlag.GUI)) {
NetworkHooks.openGui((ServerPlayerEntity) player, tile, tile.getPos());
return ActionResultType.SUCCESS;
}
// Otherwise, interact with fluids
if (tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, hit.getFace()).map(fh -> FluidUtil.tryEmptyContainer(stack, fh, 1000, player, true).success).orElse(false)) {
return ActionResultType.SUCCESS;
}
return tile.getCapability(AntimatterCaps.COVERABLE_HANDLER_CAPABILITY).map(h -> h.onInteract(player, hand, hit.getFace(), Utils.getToolType(player))).orElse(false) ? ActionResultType.SUCCESS : ActionResultType.PASS;
}
}
}
return ActionResultType.PASS;
}
Aggregations