use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.
the class ItemDrainTileEntity method tick.
@Override
public void tick() {
super.tick();
if (heldItem == null) {
processingTicks = 0;
return;
}
boolean onClient = level.isClientSide && !isVirtual();
if (processingTicks > 0) {
heldItem.prevBeltPosition = .5f;
boolean wasAtBeginning = processingTicks == FILLING_TIME;
if (!onClient || processingTicks < FILLING_TIME)
processingTicks--;
if (!continueProcessing()) {
processingTicks = 0;
notifyUpdate();
return;
}
if (wasAtBeginning != (processingTicks == FILLING_TIME))
sendData();
return;
}
heldItem.prevBeltPosition = heldItem.beltPosition;
heldItem.prevSideOffset = heldItem.sideOffset;
heldItem.beltPosition += itemMovementPerTick();
if (heldItem.beltPosition > 1) {
heldItem.beltPosition = 1;
if (onClient)
return;
Direction side = heldItem.insertedFrom;
ItemStack tryExportingToBeltFunnel = getBehaviour(DirectBeltInputBehaviour.TYPE).tryExportingToBeltFunnel(heldItem.stack, side.getOpposite(), false);
if (tryExportingToBeltFunnel != null) {
if (tryExportingToBeltFunnel.getCount() != heldItem.stack.getCount()) {
if (tryExportingToBeltFunnel.isEmpty())
heldItem = null;
else
heldItem.stack = tryExportingToBeltFunnel;
notifyUpdate();
return;
}
if (!tryExportingToBeltFunnel.isEmpty())
return;
}
BlockPos nextPosition = worldPosition.relative(side);
DirectBeltInputBehaviour directBeltInputBehaviour = TileEntityBehaviour.get(level, nextPosition, DirectBeltInputBehaviour.TYPE);
if (directBeltInputBehaviour == null) {
if (!BlockHelper.hasBlockSolidSide(level.getBlockState(nextPosition), level, nextPosition, side.getOpposite())) {
ItemStack ejected = heldItem.stack;
Vec3 outPos = VecHelper.getCenterOf(worldPosition).add(Vec3.atLowerCornerOf(side.getNormal()).scale(.75));
float movementSpeed = itemMovementPerTick();
Vec3 outMotion = Vec3.atLowerCornerOf(side.getNormal()).scale(movementSpeed).add(0, 1 / 8f, 0);
outPos.add(outMotion.normalize());
ItemEntity entity = new ItemEntity(level, outPos.x, outPos.y + 6 / 16f, outPos.z, ejected);
entity.setDeltaMovement(outMotion);
entity.setDefaultPickUpDelay();
entity.hurtMarked = true;
level.addFreshEntity(entity);
heldItem = null;
notifyUpdate();
}
return;
}
if (!directBeltInputBehaviour.canInsertFromSide(side))
return;
ItemStack returned = directBeltInputBehaviour.handleInsertion(heldItem.copy(), side, false);
if (returned.isEmpty()) {
if (level.getBlockEntity(nextPosition) instanceof ItemDrainTileEntity)
AllTriggers.triggerForNearbyPlayers(AllTriggers.CHAINED_ITEM_DRAIN, level, worldPosition, 5);
heldItem = null;
notifyUpdate();
return;
}
if (returned.getCount() != heldItem.stack.getCount()) {
heldItem.stack = returned;
notifyUpdate();
return;
}
return;
}
if (heldItem.prevBeltPosition < .5f && heldItem.beltPosition >= .5f) {
if (!EmptyingByBasin.canItemBeEmptied(level, heldItem.stack))
return;
heldItem.beltPosition = .5f;
if (onClient)
return;
processingTicks = FILLING_TIME;
sendData();
}
}
use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.
the class BrassTunnelTileEntity method addValidOutputsOf.
private void addValidOutputsOf(BrassTunnelTileEntity tunnelTE, List<Pair<BrassTunnelTileEntity, Direction>> validOutputs) {
syncSet.add(tunnelTE);
BeltTileEntity below = BeltHelper.getSegmentTE(level, tunnelTE.worldPosition.below());
if (below == null)
return;
Direction movementFacing = below.getMovementFacing();
BlockState blockState = getBlockState();
if (!AllBlocks.BRASS_TUNNEL.has(blockState))
return;
boolean prioritizeSides = tunnelTE == this;
for (boolean sidePass : Iterate.trueAndFalse) {
if (!prioritizeSides && sidePass)
continue;
for (Direction direction : Iterate.horizontalDirections) {
if (direction == movementFacing && below.getSpeed() == 0)
continue;
if (prioritizeSides && sidePass == (direction.getAxis() == movementFacing.getAxis()))
continue;
if (direction == movementFacing.getOpposite())
continue;
if (tunnelTE.sides.contains(direction)) {
BlockPos offset = tunnelTE.worldPosition.below().relative(direction);
DirectBeltInputBehaviour inputBehaviour = TileEntityBehaviour.get(level, offset, DirectBeltInputBehaviour.TYPE);
if (inputBehaviour == null) {
if (direction == movementFacing)
if (!BlockHelper.hasBlockSolidSide(level.getBlockState(offset), level, offset, direction.getOpposite()))
validOutputs.add(Pair.of(tunnelTE, direction));
continue;
}
if (inputBehaviour.canInsertFromSide(direction))
validOutputs.add(Pair.of(tunnelTE, direction));
continue;
}
}
}
}
use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.
the class BrassTunnelTileEntity method insertIntoTunnel.
@Nullable
protected ItemStack insertIntoTunnel(BrassTunnelTileEntity tunnel, Direction side, ItemStack stack, boolean simulate) {
if (stack.isEmpty())
return stack;
if (!tunnel.testFlapFilter(side, stack))
return null;
BeltTileEntity below = BeltHelper.getSegmentTE(level, tunnel.worldPosition.below());
if (below == null)
return null;
BlockPos offset = tunnel.getBlockPos().below().relative(side);
DirectBeltInputBehaviour sideOutput = TileEntityBehaviour.get(level, offset, DirectBeltInputBehaviour.TYPE);
if (sideOutput != null) {
if (!sideOutput.canInsertFromSide(side))
return null;
ItemStack result = sideOutput.handleInsertion(stack, side, simulate);
if (result.isEmpty() && !simulate)
tunnel.flap(side, false);
return result;
}
Direction movementFacing = below.getMovementFacing();
if (side == movementFacing)
if (!BlockHelper.hasBlockSolidSide(level.getBlockState(offset), level, offset, side.getOpposite())) {
BeltTileEntity controllerTE = below.getControllerTE();
if (controllerTE == null)
return null;
if (!simulate) {
tunnel.flap(side, true);
ItemStack ejected = stack;
float beltMovementSpeed = below.getDirectionAwareBeltMovementSpeed();
float movementSpeed = Math.max(Math.abs(beltMovementSpeed), 1 / 8f);
int additionalOffset = beltMovementSpeed > 0 ? 1 : 0;
Vec3 outPos = BeltHelper.getVectorForOffset(controllerTE, below.index + additionalOffset);
Vec3 outMotion = Vec3.atLowerCornerOf(side.getNormal()).scale(movementSpeed).add(0, 1 / 8f, 0);
outPos.add(outMotion.normalize());
ItemEntity entity = new ItemEntity(level, outPos.x, outPos.y + 6 / 16f, outPos.z, ejected);
entity.setDeltaMovement(outMotion);
entity.setDefaultPickUpDelay();
entity.hurtMarked = true;
level.addFreshEntity(entity);
}
return ItemStack.EMPTY;
}
return null;
}
use of com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour in project Create by Creators-of-Create.
the class DepotBehaviour method addSubBehaviours.
public void addSubBehaviours(List<TileEntityBehaviour> behaviours) {
behaviours.add(new DirectBeltInputBehaviour(tileEntity).allowingBeltFunnels().setInsertionHandler(this::tryInsertingFromSide));
transportedHandler = new TransportedItemStackHandlerBehaviour(tileEntity, this::applyToAllItems).withStackPlacement(this::getWorldPositionOf);
behaviours.add(transportedHandler);
}
Aggregations