use of com.simibubi.create.content.contraptions.relays.belt.BeltSlope in project Create by Creators-of-Create.
the class StructureTransform method transformBelt.
protected BlockState transformBelt(BlockState state, boolean halfTurn) {
Direction initialDirection = state.getValue(BeltBlock.HORIZONTAL_FACING);
boolean diagonal = state.getValue(BeltBlock.SLOPE) == BeltSlope.DOWNWARD || state.getValue(BeltBlock.SLOPE) == BeltSlope.UPWARD;
if (!diagonal) {
for (int i = 0; i < rotation.ordinal(); i++) {
Direction direction = state.getValue(BeltBlock.HORIZONTAL_FACING);
BeltSlope slope = state.getValue(BeltBlock.SLOPE);
boolean vertical = slope == BeltSlope.VERTICAL;
boolean horizontal = slope == BeltSlope.HORIZONTAL;
boolean sideways = slope == BeltSlope.SIDEWAYS;
Direction newDirection = direction.getOpposite();
BeltSlope newSlope = BeltSlope.VERTICAL;
if (vertical) {
if (direction.getAxis() == rotationAxis) {
newDirection = direction.getCounterClockWise();
newSlope = BeltSlope.SIDEWAYS;
} else {
newSlope = BeltSlope.HORIZONTAL;
newDirection = direction;
if (direction.getAxis() == Axis.Z)
newDirection = direction.getOpposite();
}
}
if (sideways) {
newDirection = direction;
if (direction.getAxis() == rotationAxis)
newSlope = BeltSlope.HORIZONTAL;
else
newDirection = direction.getCounterClockWise();
}
if (horizontal) {
newDirection = direction;
if (direction.getAxis() == rotationAxis)
newSlope = BeltSlope.SIDEWAYS;
else if (direction.getAxis() != Axis.Z)
newDirection = direction.getOpposite();
}
state = state.setValue(BeltBlock.HORIZONTAL_FACING, newDirection);
state = state.setValue(BeltBlock.SLOPE, newSlope);
}
} else if (initialDirection.getAxis() != rotationAxis) {
for (int i = 0; i < rotation.ordinal(); i++) {
Direction direction = state.getValue(BeltBlock.HORIZONTAL_FACING);
Direction newDirection = direction.getOpposite();
BeltSlope slope = state.getValue(BeltBlock.SLOPE);
boolean upward = slope == BeltSlope.UPWARD;
boolean downward = slope == BeltSlope.DOWNWARD;
// Rotate diagonal
if (direction.getAxisDirection() == AxisDirection.POSITIVE ^ downward ^ direction.getAxis() == Axis.Z) {
state = state.setValue(BeltBlock.SLOPE, upward ? BeltSlope.DOWNWARD : BeltSlope.UPWARD);
} else {
state = state.setValue(BeltBlock.HORIZONTAL_FACING, newDirection);
}
}
} else if (halfTurn) {
Direction direction = state.getValue(BeltBlock.HORIZONTAL_FACING);
Direction newDirection = direction.getOpposite();
BeltSlope slope = state.getValue(BeltBlock.SLOPE);
boolean vertical = slope == BeltSlope.VERTICAL;
if (diagonal) {
state = state.setValue(BeltBlock.SLOPE, slope == BeltSlope.UPWARD ? BeltSlope.DOWNWARD : slope == BeltSlope.DOWNWARD ? BeltSlope.UPWARD : slope);
} else if (vertical) {
state = state.setValue(BeltBlock.HORIZONTAL_FACING, newDirection);
}
}
return state;
}
use of com.simibubi.create.content.contraptions.relays.belt.BeltSlope in project Create by Creators-of-Create.
the class BeltMovementHandler method transportEntity.
public static void transportEntity(BeltTileEntity beltTe, Entity entityIn, TransportedEntityInfo info) {
BlockPos pos = info.lastCollidedPos;
Level world = beltTe.getLevel();
BlockEntity te = world.getBlockEntity(pos);
BlockEntity tileEntityBelowPassenger = world.getBlockEntity(entityIn.blockPosition());
BlockState blockState = info.lastCollidedState;
Direction movementFacing = Direction.fromAxisAndDirection(blockState.getValue(BlockStateProperties.HORIZONTAL_FACING).getAxis(), beltTe.getSpeed() < 0 ? POSITIVE : NEGATIVE);
boolean collidedWithBelt = te instanceof BeltTileEntity;
boolean betweenBelts = tileEntityBelowPassenger instanceof BeltTileEntity && tileEntityBelowPassenger != te;
// Don't fight other Belts
if (!collidedWithBelt || betweenBelts) {
return;
}
// Too slow
boolean notHorizontal = beltTe.getBlockState().getValue(BeltBlock.SLOPE) != BeltSlope.HORIZONTAL;
if (Math.abs(beltTe.getSpeed()) < 1)
return;
// Not on top
if (entityIn.getY() - .25f < pos.getY())
return;
// Lock entities in place
boolean isPlayer = entityIn instanceof Player;
if (entityIn instanceof LivingEntity && !isPlayer)
((LivingEntity) entityIn).addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 10, 1, false, false));
final Direction beltFacing = blockState.getValue(BlockStateProperties.HORIZONTAL_FACING);
final BeltSlope slope = blockState.getValue(BeltBlock.SLOPE);
final Axis axis = beltFacing.getAxis();
float movementSpeed = beltTe.getBeltMovementSpeed();
final Direction movementDirection = Direction.get(axis == Axis.X ? NEGATIVE : POSITIVE, axis);
Vec3i centeringDirection = Direction.get(POSITIVE, beltFacing.getClockWise().getAxis()).getNormal();
Vec3 movement = Vec3.atLowerCornerOf(movementDirection.getNormal()).scale(movementSpeed);
double diffCenter = axis == Axis.Z ? (pos.getX() + .5f - entityIn.getX()) : (pos.getZ() + .5f - entityIn.getZ());
if (Math.abs(diffCenter) > 48 / 64f)
return;
BeltPart part = blockState.getValue(BeltBlock.PART);
float top = 13 / 16f;
boolean onSlope = notHorizontal && (part == BeltPart.MIDDLE || part == BeltPart.PULLEY || part == (slope == BeltSlope.UPWARD ? BeltPart.END : BeltPart.START) && entityIn.getY() - pos.getY() < top || part == (slope == BeltSlope.UPWARD ? BeltPart.START : BeltPart.END) && entityIn.getY() - pos.getY() > top);
boolean movingDown = onSlope && slope == (movementFacing == beltFacing ? BeltSlope.DOWNWARD : BeltSlope.UPWARD);
boolean movingUp = onSlope && slope == (movementFacing == beltFacing ? BeltSlope.UPWARD : BeltSlope.DOWNWARD);
if (beltFacing.getAxis() == Axis.Z) {
boolean b = movingDown;
movingDown = movingUp;
movingUp = b;
}
if (movingUp)
movement = movement.add(0, Math.abs(axis.choose(movement.x, movement.y, movement.z)), 0);
if (movingDown)
movement = movement.add(0, -Math.abs(axis.choose(movement.x, movement.y, movement.z)), 0);
Vec3 centering = Vec3.atLowerCornerOf(centeringDirection).scale(diffCenter * Math.min(Math.abs(movementSpeed), .1f) * 4);
if (!(entityIn instanceof LivingEntity) || ((LivingEntity) entityIn).zza == 0 && ((LivingEntity) entityIn).xxa == 0)
movement = movement.add(centering);
float step = entityIn.maxUpStep;
if (!isPlayer)
entityIn.maxUpStep = 1;
// Entity Collisions
if (Math.abs(movementSpeed) < .5f) {
Vec3 checkDistance = movement.normalize().scale(0.5);
AABB bb = entityIn.getBoundingBox();
AABB checkBB = new AABB(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
checkBB = checkBB.move(checkDistance).inflate(-Math.abs(checkDistance.x), -Math.abs(checkDistance.y), -Math.abs(checkDistance.z));
List<Entity> list = world.getEntities(entityIn, checkBB);
list.removeIf(e -> shouldIgnoreBlocking(entityIn, e));
if (!list.isEmpty()) {
entityIn.setDeltaMovement(0, 0, 0);
info.ticksSinceLastCollision--;
return;
}
}
entityIn.fallDistance = 0;
if (movingUp) {
float minVelocity = .13f;
float yMovement = (float) -(Math.max(Math.abs(movement.y), minVelocity));
entityIn.move(SELF, new Vec3(0, yMovement, 0));
entityIn.move(SELF, movement.multiply(1, 0, 1));
} else if (movingDown) {
entityIn.move(SELF, movement.multiply(1, 0, 1));
entityIn.move(SELF, movement.multiply(0, 1, 0));
} else {
entityIn.move(SELF, movement);
}
entityIn.setOnGround(true);
if (!isPlayer)
entityIn.maxUpStep = step;
boolean movedPastEndingSlope = onSlope && (AllBlocks.BELT.has(world.getBlockState(entityIn.blockPosition())) || AllBlocks.BELT.has(world.getBlockState(entityIn.blockPosition().below())));
if (movedPastEndingSlope && !movingDown && Math.abs(movementSpeed) > 0)
entityIn.setPos(entityIn.getX(), entityIn.getY() + movement.y, entityIn.getZ());
if (movedPastEndingSlope) {
entityIn.setDeltaMovement(movement);
entityIn.hurtMarked = true;
}
}
use of com.simibubi.create.content.contraptions.relays.belt.BeltSlope in project Create by Creators-of-Create.
the class BeltConnectorItem method createBelts.
public static void createBelts(Level world, BlockPos start, BlockPos end) {
world.playSound(null, new BlockPos(VecHelper.getCenterOf(start.offset(end)).scale(.5f)), SoundEvents.WOOL_PLACE, SoundSource.BLOCKS, 0.5F, 1F);
BeltSlope slope = getSlopeBetween(start, end);
Direction facing = getFacingFromTo(start, end);
BlockPos diff = end.subtract(start);
if (diff.getX() == diff.getZ())
facing = Direction.get(facing.getAxisDirection(), world.getBlockState(start).getValue(BlockStateProperties.AXIS) == Axis.X ? Axis.Z : Axis.X);
List<BlockPos> beltsToCreate = getBeltChainBetween(start, end, slope, facing);
BlockState beltBlock = AllBlocks.BELT.getDefaultState();
for (BlockPos pos : beltsToCreate) {
BeltPart part = pos.equals(start) ? BeltPart.START : pos.equals(end) ? BeltPart.END : BeltPart.MIDDLE;
BlockState shaftState = world.getBlockState(pos);
boolean pulley = ShaftBlock.isShaft(shaftState);
if (part == BeltPart.MIDDLE && pulley)
part = BeltPart.PULLEY;
if (pulley && shaftState.getValue(AbstractShaftBlock.AXIS) == Axis.Y)
slope = BeltSlope.SIDEWAYS;
KineticTileEntity.switchToBlockState(world, pos, beltBlock.setValue(BeltBlock.SLOPE, slope).setValue(BeltBlock.PART, part).setValue(BeltBlock.HORIZONTAL_FACING, facing));
}
}
use of com.simibubi.create.content.contraptions.relays.belt.BeltSlope in project Create by Creators-of-Create.
the class SchematicannonTileEntity method stripBeltIfNotLast.
public static BlockState stripBeltIfNotLast(BlockState blockState) {
BeltPart part = blockState.getValue(BeltBlock.PART);
if (part == BeltPart.MIDDLE)
return Blocks.AIR.defaultBlockState();
// is highest belt?
boolean isLastSegment = false;
Direction facing = blockState.getValue(BeltBlock.HORIZONTAL_FACING);
BeltSlope slope = blockState.getValue(BeltBlock.SLOPE);
boolean positive = facing.getAxisDirection() == AxisDirection.POSITIVE;
boolean start = part == BeltPart.START;
boolean end = part == BeltPart.END;
switch(slope) {
case DOWNWARD:
isLastSegment = start;
break;
case UPWARD:
isLastSegment = end;
break;
default:
isLastSegment = positive && end || !positive && start;
}
if (isLastSegment)
return blockState;
return AllBlocks.SHAFT.getDefaultState().setValue(AbstractShaftBlock.AXIS, slope == BeltSlope.SIDEWAYS ? Axis.Y : facing.getClockWise().getAxis());
}
Aggregations