Search in sources :

Example 21 with KineticTileEntity

use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.

the class GantryShaftBlock method neighborChanged.

@Override
public void neighborChanged(BlockState state, Level worldIn, BlockPos pos, Block p_220069_4_, BlockPos p_220069_5_, boolean p_220069_6_) {
    if (worldIn.isClientSide)
        return;
    boolean previouslyPowered = state.getValue(POWERED);
    // shouldBePowered(state, worldIn, pos);
    boolean shouldPower = worldIn.hasNeighborSignal(pos);
    if (!previouslyPowered && !shouldPower && shouldBePowered(state, worldIn, pos)) {
        worldIn.setBlock(pos, state.setValue(POWERED, true), 3);
        return;
    }
    if (previouslyPowered == shouldPower)
        return;
    // Collect affected gantry shafts
    List<BlockPos> toUpdate = new ArrayList<>();
    Direction facing = state.getValue(FACING);
    Axis axis = facing.getAxis();
    for (Direction d : Iterate.directionsInAxis(axis)) {
        BlockPos currentPos = pos.relative(d);
        while (true) {
            if (!worldIn.isLoaded(currentPos))
                break;
            BlockState currentState = worldIn.getBlockState(currentPos);
            if (!(currentState.getBlock() instanceof GantryShaftBlock))
                break;
            if (currentState.getValue(FACING) != facing)
                break;
            if (!shouldPower && currentState.getValue(POWERED) && worldIn.hasNeighborSignal(currentPos))
                return;
            if (currentState.getValue(POWERED) == shouldPower)
                break;
            toUpdate.add(currentPos);
            currentPos = currentPos.relative(d);
        }
    }
    toUpdate.add(pos);
    for (BlockPos blockPos : toUpdate) {
        BlockState blockState = worldIn.getBlockState(blockPos);
        BlockEntity te = worldIn.getBlockEntity(blockPos);
        if (te instanceof KineticTileEntity)
            ((KineticTileEntity) te).detachKinetics();
        if (blockState.getBlock() instanceof GantryShaftBlock)
            worldIn.setBlock(blockPos, blockState.setValue(POWERED, shouldPower), 2);
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) Axis(net.minecraft.core.Direction.Axis) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 22 with KineticTileEntity

use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.

the class TurntableBlock method entityInside.

@Override
public void entityInside(BlockState state, Level worldIn, BlockPos pos, Entity e) {
    if (!e.isOnGround())
        return;
    if (e.getDeltaMovement().y > 0)
        return;
    if (e.getY() < pos.getY() + .5f)
        return;
    withTileEntityDo(worldIn, pos, te -> {
        float speed = ((KineticTileEntity) te).getSpeed() * 3 / 10;
        if (speed == 0)
            return;
        Level world = e.getCommandSenderWorld();
        if (world.isClientSide && (e instanceof Player)) {
            if (worldIn.getBlockState(e.blockPosition()) != state) {
                Vec3 origin = VecHelper.getCenterOf(pos);
                Vec3 offset = e.position().subtract(origin);
                offset = VecHelper.rotate(offset, Mth.clamp(speed, -16, 16) / 1f, Axis.Y);
                Vec3 movement = origin.add(offset).subtract(e.position());
                e.setDeltaMovement(e.getDeltaMovement().add(movement));
                e.hurtMarked = true;
            }
        }
        if ((e instanceof Player))
            return;
        if (world.isClientSide)
            return;
        if ((e instanceof LivingEntity)) {
            float diff = e.getYHeadRot() - speed;
            ((LivingEntity) e).setNoActionTime(20);
            e.setYBodyRot(diff);
            e.setYHeadRot(diff);
            e.setOnGround(false);
            e.hurtMarked = true;
        }
        e.setYRot(e.getYRot() - speed);
    });
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) Player(net.minecraft.world.entity.player.Player) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) Vec3(net.minecraft.world.phys.Vec3) Level(net.minecraft.world.level.Level)

Example 23 with KineticTileEntity

use of com.simibubi.create.content.contraptions.base.KineticTileEntity in project Create by Creators-of-Create.

the class BlockHelper method placeSchematicBlock.

public static void placeSchematicBlock(Level world, BlockState state, BlockPos target, ItemStack stack, @Nullable CompoundTag data) {
    // Piston
    if (state.hasProperty(BlockStateProperties.EXTENDED))
        state = state.setValue(BlockStateProperties.EXTENDED, Boolean.FALSE);
    if (state.hasProperty(BlockStateProperties.WATERLOGGED))
        state = state.setValue(BlockStateProperties.WATERLOGGED, Boolean.FALSE);
    if (AllBlocks.BELT.has(state)) {
        world.setBlock(target, state, 2);
        return;
    } else if (state.getBlock() == Blocks.COMPOSTER)
        state = Blocks.COMPOSTER.defaultBlockState();
    else if (state.getBlock() != Blocks.SEA_PICKLE && state.getBlock() instanceof IPlantable)
        state = ((IPlantable) state.getBlock()).getPlant(world, target);
    if (world.dimensionType().ultraWarm() && state.getFluidState().getType().is(FluidTags.WATER)) {
        int i = target.getX();
        int j = target.getY();
        int k = target.getZ();
        world.playSound(null, target, SoundEvents.FIRE_EXTINGUISH, SoundSource.BLOCKS, 0.5F, 2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
        for (int l = 0; l < 8; ++l) {
            world.addParticle(ParticleTypes.LARGE_SMOKE, i + Math.random(), j + Math.random(), k + Math.random(), 0.0D, 0.0D, 0.0D);
        }
        Block.dropResources(state, world, target);
        return;
    }
    if (state.getBlock() instanceof BaseRailBlock) {
        placeRailWithoutUpdate(world, state, target);
    } else {
        world.setBlock(target, state, 18);
    }
    if (data != null) {
        BlockEntity tile = world.getBlockEntity(target);
        if (tile != null) {
            data.putInt("x", target.getX());
            data.putInt("y", target.getY());
            data.putInt("z", target.getZ());
            if (tile instanceof KineticTileEntity)
                ((KineticTileEntity) tile).warnOfMovement();
            tile.load(data);
        }
    }
    try {
        state.getBlock().setPlacedBy(world, target, state, null, stack);
    } catch (Exception e) {
    }
}
Also used : BaseRailBlock(net.minecraft.world.level.block.BaseRailBlock) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) IPlantable(net.minecraftforge.common.IPlantable) 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