Search in sources :

Example 6 with BaseRailBlock

use of net.minecraft.world.level.block.BaseRailBlock in project Botania by VazkiiMods.

the class BehaviourPoolMinecart method execute.

@Nonnull
@Override
public ItemStack execute(BlockSource source, ItemStack stack) {
    Direction enumfacing = source.getBlockState().getValue(DispenserBlock.FACING);
    Level world = source.getLevel();
    double d0 = source.x() + (double) enumfacing.getStepX() * 1.125D;
    double d1 = Math.floor(source.y()) + (double) enumfacing.getStepY();
    double d2 = source.z() + (double) enumfacing.getStepZ() * 1.125D;
    BlockPos blockpos = source.getPos().relative(enumfacing);
    BlockState iblockstate = world.getBlockState(blockpos);
    RailShape railshape = iblockstate.getBlock() instanceof BaseRailBlock ? iblockstate.getValue(((BaseRailBlock) iblockstate.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH;
    double d3;
    if (iblockstate.is(BlockTags.RAILS)) {
        if (railshape.isAscending()) {
            d3 = 0.6D;
        } else {
            d3 = 0.1D;
        }
    } else {
        if (!iblockstate.isAir() || !world.getBlockState(blockpos.below()).is(BlockTags.RAILS)) {
            return this.behaviourDefaultDispenseItem.dispense(source, stack);
        }
        BlockState iblockstate1 = world.getBlockState(blockpos.below());
        RailShape railshape1 = iblockstate1.getBlock() instanceof BaseRailBlock ? iblockstate1.getValue(((BaseRailBlock) iblockstate1.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH;
        if (enumfacing != Direction.DOWN && railshape1.isAscending()) {
            d3 = -0.4D;
        } else {
            d3 = -0.9D;
        }
    }
    AbstractMinecart entityminecart = new EntityPoolMinecart(world, d0, d1 + d3, d2);
    if (stack.hasCustomHoverName()) {
        entityminecart.setCustomName(stack.getHoverName());
    }
    world.addFreshEntity(entityminecart);
    stack.shrink(1);
    return stack;
}
Also used : EntityPoolMinecart(vazkii.botania.common.entity.EntityPoolMinecart) BlockState(net.minecraft.world.level.block.state.BlockState) BaseRailBlock(net.minecraft.world.level.block.BaseRailBlock) AbstractMinecart(net.minecraft.world.entity.vehicle.AbstractMinecart) RailShape(net.minecraft.world.level.block.state.properties.RailShape) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) Nonnull(javax.annotation.Nonnull)

Example 7 with BaseRailBlock

use of net.minecraft.world.level.block.BaseRailBlock in project Botania by VazkiiMods.

the class ItemPoolMinecart method useOn.

// [VanillaCopy] MinecartItem
@Nonnull
@Override
public InteractionResult useOn(UseOnContext context) {
    Level world = context.getLevel();
    BlockPos blockPos = context.getClickedPos();
    BlockState blockState = world.getBlockState(blockPos);
    if (!blockState.is(BlockTags.RAILS)) {
        return InteractionResult.FAIL;
    } else {
        ItemStack itemStack = context.getItemInHand();
        if (!world.isClientSide) {
            RailShape railShape = blockState.getBlock() instanceof BaseRailBlock ? blockState.getValue(((BaseRailBlock) blockState.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH;
            double d = 0.0D;
            if (railShape.isAscending()) {
                d = 0.5D;
            }
            AbstractMinecart abstractMinecartEntity = new EntityPoolMinecart(world, (double) blockPos.getX() + 0.5D, (double) blockPos.getY() + 0.0625D + d, (double) blockPos.getZ() + 0.5D);
            if (itemStack.hasCustomHoverName()) {
                abstractMinecartEntity.setCustomName(itemStack.getHoverName());
            }
            world.addFreshEntity(abstractMinecartEntity);
        }
        itemStack.shrink(1);
        return InteractionResult.sidedSuccess(world.isClientSide);
    }
}
Also used : EntityPoolMinecart(vazkii.botania.common.entity.EntityPoolMinecart) BlockState(net.minecraft.world.level.block.state.BlockState) BaseRailBlock(net.minecraft.world.level.block.BaseRailBlock) AbstractMinecart(net.minecraft.world.entity.vehicle.AbstractMinecart) RailShape(net.minecraft.world.level.block.state.properties.RailShape) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 8 with BaseRailBlock

use of net.minecraft.world.level.block.BaseRailBlock in project Create by Creators-of-Create.

the class CartAssemblerBlock method getRailBlock.

public static BlockState getRailBlock(BlockState state) {
    BaseRailBlock railBlock = (BaseRailBlock) state.getValue(RAIL_TYPE).getBlock();
    @SuppressWarnings("deprecation") BlockState railState = railBlock.defaultBlockState().setValue(railBlock.getShapeProperty(), state.getValue(RAIL_SHAPE));
    if (railState.hasProperty(ControllerRailBlock.BACKWARDS))
        railState = railState.setValue(ControllerRailBlock.BACKWARDS, state.getValue(BACKWARDS));
    return railState;
}
Also used : BaseRailBlock(net.minecraft.world.level.block.BaseRailBlock) BlockState(net.minecraft.world.level.block.state.BlockState)

Example 9 with BaseRailBlock

use of net.minecraft.world.level.block.BaseRailBlock in project Create by Creators-of-Create.

the class OrientedContraptionEntity method updateOrientation.

protected boolean updateOrientation(boolean rotationLock, boolean wasStalled, Entity riding, boolean isOnCoupling) {
    if (isOnCoupling) {
        Couple<MinecartController> coupledCarts = getCoupledCartsIfPresent();
        if (coupledCarts == null)
            return false;
        Vec3 positionVec = coupledCarts.getFirst().cart().position();
        Vec3 coupledVec = coupledCarts.getSecond().cart().position();
        double diffX = positionVec.x - coupledVec.x;
        double diffY = positionVec.y - coupledVec.y;
        double diffZ = positionVec.z - coupledVec.z;
        prevYaw = yaw;
        prevPitch = pitch;
        yaw = (float) (Mth.atan2(diffZ, diffX) * 180 / Math.PI);
        pitch = (float) (Math.atan2(diffY, Math.sqrt(diffX * diffX + diffZ * diffZ)) * 180 / Math.PI);
        if (getCouplingId().equals(riding.getUUID())) {
            pitch *= -1;
            yaw += 180;
        }
        return false;
    }
    if (contraption instanceof StabilizedContraption) {
        if (!(riding instanceof OrientedContraptionEntity))
            return false;
        StabilizedContraption stabilized = (StabilizedContraption) contraption;
        Direction facing = stabilized.getFacing();
        if (facing.getAxis().isVertical())
            return false;
        OrientedContraptionEntity parent = (OrientedContraptionEntity) riding;
        prevYaw = yaw;
        yaw = -parent.getViewYRot(1);
        return false;
    }
    prevYaw = yaw;
    if (wasStalled)
        return false;
    boolean rotating = false;
    Vec3 movementVector = riding.getDeltaMovement();
    Vec3 locationDiff = riding.position().subtract(riding.xo, riding.yo, riding.zo);
    if (!(riding instanceof AbstractMinecart))
        movementVector = locationDiff;
    Vec3 motion = movementVector.normalize();
    if (!rotationLock) {
        if (riding instanceof AbstractMinecart) {
            AbstractMinecart minecartEntity = (AbstractMinecart) riding;
            BlockPos railPosition = minecartEntity.getCurrentRailPosition();
            BlockState blockState = level.getBlockState(railPosition);
            if (blockState.getBlock() instanceof BaseRailBlock) {
                BaseRailBlock abstractRailBlock = (BaseRailBlock) blockState.getBlock();
                RailShape railDirection = abstractRailBlock.getRailDirection(blockState, level, railPosition, minecartEntity);
                motion = VecHelper.project(motion, MinecartSim2020.getRailVec(railDirection));
            }
        }
        if (motion.length() > 0) {
            targetYaw = yawFromVector(motion);
            if (targetYaw < 0)
                targetYaw += 360;
            if (yaw < 0)
                yaw += 360;
        }
        prevYaw = yaw;
        float maxApproachSpeed = (float) (motion.length() * 12f / (Math.max(1, getBoundingBox().getXsize() / 6f)));
        float yawHint = AngleHelper.getShortestAngleDiff(yaw, yawFromVector(locationDiff));
        float approach = AngleHelper.getShortestAngleDiff(yaw, targetYaw, yawHint);
        approach = Mth.clamp(approach, -maxApproachSpeed, maxApproachSpeed);
        yaw += approach;
        if (Math.abs(AngleHelper.getShortestAngleDiff(yaw, targetYaw)) < 1f)
            yaw = targetYaw;
        else
            rotating = true;
    }
    return rotating;
}
Also used : AbstractMinecart(net.minecraft.world.entity.vehicle.AbstractMinecart) MinecartController(com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController) CapabilityMinecartController(com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController) Direction(net.minecraft.core.Direction) StabilizedContraption(com.simibubi.create.content.contraptions.components.structureMovement.bearing.StabilizedContraption) BlockState(net.minecraft.world.level.block.state.BlockState) BaseRailBlock(net.minecraft.world.level.block.BaseRailBlock) RailShape(net.minecraft.world.level.block.state.properties.RailShape) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos)

Example 10 with BaseRailBlock

use of net.minecraft.world.level.block.BaseRailBlock 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

BaseRailBlock (net.minecraft.world.level.block.BaseRailBlock)11 BlockState (net.minecraft.world.level.block.state.BlockState)9 BlockPos (net.minecraft.core.BlockPos)8 RailShape (net.minecraft.world.level.block.state.properties.RailShape)8 AbstractMinecart (net.minecraft.world.entity.vehicle.AbstractMinecart)6 Vec3 (net.minecraft.world.phys.Vec3)5 Direction (net.minecraft.core.Direction)4 Level (net.minecraft.world.level.Level)4 Nonnull (javax.annotation.Nonnull)2 Player (net.minecraft.world.entity.player.Player)2 ItemStack (net.minecraft.world.item.ItemStack)2 Block (net.minecraft.world.level.block.Block)2 EntityPoolMinecart (vazkii.botania.common.entity.EntityPoolMinecart)2 KineticTileEntity (com.simibubi.create.content.contraptions.base.KineticTileEntity)1 StabilizedContraption (com.simibubi.create.content.contraptions.components.structureMovement.bearing.StabilizedContraption)1 CapabilityMinecartController (com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController)1 MinecartController (com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController)1 ControllerRailBlock (com.simibubi.create.content.contraptions.components.tracks.ControllerRailBlock)1 VecHelper (com.simibubi.create.foundation.utility.VecHelper)1 AxisDirection (net.minecraft.core.Direction.AxisDirection)1