use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.
the class ItemDrainTileEntity method addBehaviours.
@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
behaviours.add(new DirectBeltInputBehaviour(this).allowingBeltFunnels().setInsertionHandler(this::tryInsertingFromSide));
behaviours.add(internalTank = SmartFluidTankBehaviour.single(this, 1500).allowExtraction().forbidInsertion());
}
use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.
the class BasinBlock method canOutputTo.
public static boolean canOutputTo(BlockGetter world, BlockPos basinPos, Direction direction) {
BlockPos neighbour = basinPos.relative(direction);
BlockPos output = neighbour.below();
BlockState blockState = world.getBlockState(neighbour);
if (FunnelBlock.isFunnel(blockState)) {
if (FunnelBlock.getFunnelFacing(blockState) == direction)
return false;
} else if (!blockState.getCollisionShape(world, neighbour).isEmpty()) {
return false;
} else {
BlockEntity tileEntity = world.getBlockEntity(output);
if (tileEntity instanceof BeltTileEntity) {
BeltTileEntity belt = (BeltTileEntity) tileEntity;
return belt.getSpeed() == 0 || belt.getMovementFacing() != direction.getOpposite();
}
}
DirectBeltInputBehaviour directBeltInputBehaviour = TileEntityBehaviour.get(world, output, DirectBeltInputBehaviour.TYPE);
if (directBeltInputBehaviour != null)
return directBeltInputBehaviour.canInsertFromSide(direction);
return false;
}
use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.
the class SawTileEntity method tick.
@Override
public void tick() {
if (shouldRun() && ticksUntilNextProgress < 0)
destroyNextTick();
super.tick();
if (!canProcess())
return;
if (getSpeed() == 0)
return;
if (inventory.remainingTime == -1) {
if (!inventory.isEmpty() && !inventory.appliedRecipe)
start(inventory.getStackInSlot(0));
return;
}
float processingSpeed = Mth.clamp(Math.abs(getSpeed()) / 24, 1, 128);
inventory.remainingTime -= processingSpeed;
if (inventory.remainingTime > 0)
spawnParticles(inventory.getStackInSlot(0));
if (inventory.remainingTime < 5 && !inventory.appliedRecipe) {
if (level.isClientSide && !isVirtual())
return;
playEvent = inventory.getStackInSlot(0);
applyRecipe();
inventory.appliedRecipe = true;
inventory.recipeDuration = 20;
inventory.remainingTime = 20;
sendData();
return;
}
Vec3 itemMovement = getItemMovementVec();
Direction itemMovementFacing = Direction.getNearest(itemMovement.x, itemMovement.y, itemMovement.z);
if (inventory.remainingTime > 0)
return;
inventory.remainingTime = 0;
for (int slot = 0; slot < inventory.getSlots(); slot++) {
ItemStack stack = inventory.getStackInSlot(slot);
if (stack.isEmpty())
continue;
ItemStack tryExportingToBeltFunnel = getBehaviour(DirectBeltInputBehaviour.TYPE).tryExportingToBeltFunnel(stack, itemMovementFacing.getOpposite(), false);
if (tryExportingToBeltFunnel != null) {
if (tryExportingToBeltFunnel.getCount() != stack.getCount()) {
inventory.setStackInSlot(slot, tryExportingToBeltFunnel);
notifyUpdate();
return;
}
if (!tryExportingToBeltFunnel.isEmpty())
return;
}
}
BlockPos nextPos = worldPosition.offset(itemMovement.x, itemMovement.y, itemMovement.z);
DirectBeltInputBehaviour behaviour = TileEntityBehaviour.get(level, nextPos, DirectBeltInputBehaviour.TYPE);
if (behaviour != null) {
boolean changed = false;
if (!behaviour.canInsertFromSide(itemMovementFacing))
return;
if (level.isClientSide && !isVirtual())
return;
for (int slot = 0; slot < inventory.getSlots(); slot++) {
ItemStack stack = inventory.getStackInSlot(slot);
if (stack.isEmpty())
continue;
ItemStack remainder = behaviour.handleInsertion(stack, itemMovementFacing, false);
if (remainder.equals(stack, false))
continue;
inventory.setStackInSlot(slot, remainder);
changed = true;
}
if (changed) {
setChanged();
sendData();
}
return;
}
// Eject Items
Vec3 outPos = VecHelper.getCenterOf(worldPosition).add(itemMovement.scale(.5f).add(0, .5, 0));
Vec3 outMotion = itemMovement.scale(.0625).add(0, .125, 0);
for (int slot = 0; slot < inventory.getSlots(); slot++) {
ItemStack stack = inventory.getStackInSlot(slot);
if (stack.isEmpty())
continue;
ItemEntity entityIn = new ItemEntity(level, outPos.x, outPos.y, outPos.z, stack);
entityIn.setDeltaMovement(outMotion);
level.addFreshEntity(entityIn);
}
inventory.clear();
level.updateNeighbourForOutputSignal(worldPosition, getBlockState().getBlock());
inventory.remainingTime = -1;
sendData();
}
use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.
the class MillstoneTileEntity method addBehaviours.
@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
behaviours.add(new DirectBeltInputBehaviour(this));
super.addBehaviours(behaviours);
}
use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.
the class BeltTunnelBlock method hasValidOutput.
private boolean hasValidOutput(BlockGetter world, BlockPos pos, Direction side) {
BlockState blockState = world.getBlockState(pos.relative(side));
if (AllBlocks.BELT.has(blockState))
return blockState.getValue(BeltBlock.HORIZONTAL_FACING).getAxis() == side.getAxis();
DirectBeltInputBehaviour behaviour = TileEntityBehaviour.get(world, pos.relative(side), DirectBeltInputBehaviour.TYPE);
return behaviour != null && behaviour.canInsertFromSide(side);
}
Aggregations