use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.
the class KineticDebugger method getSelectedTE.
public static KineticTileEntity getSelectedTE() {
HitResult obj = Minecraft.getInstance().hitResult;
ClientLevel world = Minecraft.getInstance().level;
if (obj == null)
return null;
if (world == null)
return null;
if (!(obj instanceof BlockHitResult))
return null;
BlockHitResult ray = (BlockHitResult) obj;
BlockEntity te = world.getBlockEntity(ray.getBlockPos());
if (!(te instanceof KineticTileEntity))
return null;
return (KineticTileEntity) te;
}
use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.
the class BeltConnectorItem method canConnect.
public static boolean canConnect(Level world, BlockPos first, BlockPos second) {
if (!world.isAreaLoaded(first, 1))
return false;
if (!world.isAreaLoaded(second, 1))
return false;
if (!second.closerThan(first, maxLength()))
return false;
BlockPos diff = second.subtract(first);
Axis shaftAxis = world.getBlockState(first).getValue(BlockStateProperties.AXIS);
int x = diff.getX();
int y = diff.getY();
int z = diff.getZ();
int sames = ((Math.abs(x) == Math.abs(y)) ? 1 : 0) + ((Math.abs(y) == Math.abs(z)) ? 1 : 0) + ((Math.abs(z) == Math.abs(x)) ? 1 : 0);
if (shaftAxis.choose(x, y, z) != 0)
return false;
if (sames != 1)
return false;
if (shaftAxis != world.getBlockState(second).getValue(BlockStateProperties.AXIS))
return false;
if (shaftAxis == Axis.Y && x != 0 && z != 0)
return false;
BlockEntity tileEntity = world.getBlockEntity(first);
BlockEntity tileEntity2 = world.getBlockEntity(second);
if (!(tileEntity instanceof KineticTileEntity))
return false;
if (!(tileEntity2 instanceof KineticTileEntity))
return false;
float speed1 = ((KineticTileEntity) tileEntity).getTheoreticalSpeed();
float speed2 = ((KineticTileEntity) tileEntity2).getTheoreticalSpeed();
if (Math.signum(speed1) != Math.signum(speed2) && speed1 != 0 && speed2 != 0)
return false;
BlockPos step = new BlockPos(Math.signum(diff.getX()), Math.signum(diff.getY()), Math.signum(diff.getZ()));
int limit = 1000;
for (BlockPos currentPos = first.offset(step); !currentPos.equals(second) && limit-- > 0; currentPos = currentPos.offset(step)) {
BlockState blockState = world.getBlockState(currentPos);
if (ShaftBlock.isShaft(blockState) && blockState.getValue(AbstractShaftBlock.AXIS) == shaftAxis)
continue;
if (!blockState.getMaterial().isReplaceable())
return false;
}
return true;
}
use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.
the class GearshiftBlock method tick.
@Override
public void tick(BlockState state, ServerLevel worldIn, BlockPos pos, Random random) {
BlockEntity te = worldIn.getBlockEntity(pos);
if (te == null || !(te instanceof KineticTileEntity))
return;
KineticTileEntity kte = (KineticTileEntity) te;
RotationPropagator.handleAdded(worldIn, pos, kte);
}
use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.
the class GearshiftBlock method detachKinetics.
public void detachKinetics(Level worldIn, BlockPos pos, boolean reAttachNextTick) {
BlockEntity te = worldIn.getBlockEntity(pos);
if (te == null || !(te instanceof KineticTileEntity))
return;
RotationPropagator.handleRemoved(worldIn, pos, (KineticTileEntity) te);
// Re-attach next tick
if (reAttachNextTick)
worldIn.scheduleTick(pos, this, 0, TickPriority.EXTREMELY_HIGH);
}
use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.
the class CrushingWheelControllerBlock method updateSpeed.
public void updateSpeed(BlockState state, LevelAccessor world, BlockPos pos) {
withTileEntityDo(world, pos, te -> {
if (!state.getValue(VALID)) {
if (te.crushingspeed != 0) {
te.crushingspeed = 0;
te.sendData();
}
return;
}
for (Direction d : Iterate.directions) {
BlockState neighbour = world.getBlockState(pos.relative(d));
if (!AllBlocks.CRUSHING_WHEEL.has(neighbour))
continue;
if (neighbour.getValue(BlockStateProperties.AXIS) == d.getAxis())
continue;
BlockEntity adjTe = world.getBlockEntity(pos.relative(d));
if (!(adjTe instanceof KineticTileEntity))
continue;
te.crushingspeed = Math.abs(((KineticTileEntity) adjTe).getSpeed() / 50f);
te.sendData();
break;
}
});
}
Aggregations