use of com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity in project Create by Creators-of-Create.
the class PonderWorld method fixControllerTileEntities.
public void fixControllerTileEntities() {
for (BlockEntity tileEntity : tileEntities.values()) {
if (tileEntity instanceof BeltTileEntity) {
BeltTileEntity beltTileEntity = (BeltTileEntity) tileEntity;
if (!beltTileEntity.isController())
continue;
BlockPos controllerPos = tileEntity.getBlockPos();
for (BlockPos blockPos : BeltBlock.getBeltChain(this, controllerPos)) {
BlockEntity tileEntity2 = getBlockEntity(blockPos);
if (!(tileEntity2 instanceof BeltTileEntity))
continue;
BeltTileEntity belt2 = (BeltTileEntity) tileEntity2;
belt2.setController(controllerPos);
}
}
if (tileEntity instanceof IMultiTileContainer) {
IMultiTileContainer multiTile = (IMultiTileContainer) tileEntity;
BlockPos lastKnown = multiTile.getLastKnownPos();
BlockPos current = tileEntity.getBlockPos();
if (lastKnown == null || current == null)
continue;
if (multiTile.isController())
continue;
if (!lastKnown.equals(current)) {
BlockPos newControllerPos = multiTile.getController().offset(current.subtract(lastKnown));
multiTile.setController(newControllerPos);
}
}
}
}
use of com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity in project Create by Creators-of-Create.
the class FunnelTileEntity method determineCurrentMode.
public Mode determineCurrentMode() {
BlockState state = getBlockState();
if (!FunnelBlock.isFunnel(state))
return Mode.INVALID;
if (state.getOptionalValue(BlockStateProperties.POWERED).orElse(false))
return Mode.PAUSED;
if (state.getBlock() instanceof BeltFunnelBlock) {
Shape shape = state.getValue(BeltFunnelBlock.SHAPE);
if (shape == Shape.PULLING)
return Mode.TAKING_FROM_BELT;
if (shape == Shape.PUSHING)
return Mode.PUSHING_TO_BELT;
BeltTileEntity belt = BeltHelper.getSegmentTE(level, worldPosition.below());
if (belt != null)
return belt.getMovementFacing() == state.getValue(BeltFunnelBlock.HORIZONTAL_FACING) ? Mode.PUSHING_TO_BELT : Mode.TAKING_FROM_BELT;
return Mode.INVALID;
}
if (state.getBlock() instanceof FunnelBlock)
return state.getValue(FunnelBlock.EXTRACTING) ? Mode.EXTRACT : Mode.COLLECT;
return Mode.INVALID;
}
use of com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity 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.content.contraptions.relays.belt.BeltTileEntity 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;
}
Aggregations