Search in sources :

Example 16 with KineticTileEntity

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;
}
Also used : BlockHitResult(net.minecraft.world.phys.BlockHitResult) HitResult(net.minecraft.world.phys.HitResult) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) BlockHitResult(net.minecraft.world.phys.BlockHitResult) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 17 with KineticTileEntity

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;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) BlockPos(net.minecraft.core.BlockPos) Axis(net.minecraft.core.Direction.Axis) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 18 with KineticTileEntity

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);
}
Also used : KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 19 with KineticTileEntity

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);
}
Also used : KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 20 with KineticTileEntity

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;
        }
    });
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) Direction(net.minecraft.core.Direction) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

KineticTileEntity (com.simibubi.create.content.contraptions.base.KineticTileEntity)23 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)11 BlockPos (net.minecraft.core.BlockPos)8 BlockState (net.minecraft.world.level.block.state.BlockState)7 Level (net.minecraft.world.level.Level)5 IRotate (com.simibubi.create.content.contraptions.base.IRotate)4 TileEntity (net.minecraft.tileentity.TileEntity)4 SplitShaftTileEntity (com.simibubi.create.content.contraptions.relays.encased.SplitShaftTileEntity)3 Iterator (java.util.Iterator)3 Axis (net.minecraft.core.Direction.Axis)3 LinkedList (java.util.LinkedList)2 ClientLevel (net.minecraft.client.multiplayer.ClientLevel)2 Direction (net.minecraft.core.Direction)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vec3 (net.minecraft.world.phys.Vec3)2 ControllerTileEntity (com.lowdragmc.multiblocked.api.tile.ControllerTileEntity)1 AllBlocks (com.simibubi.create.AllBlocks)1 AllInteractionBehaviours (com.simibubi.create.AllInteractionBehaviours)1 AllMovementBehaviours (com.simibubi.create.AllMovementBehaviours)1 SeatBlock (com.simibubi.create.content.contraptions.components.actors.SeatBlock)1