Search in sources :

Example 6 with RailShape

use of net.minecraft.state.properties.RailShape in project MCMOD-Industria by M-Marvin.

the class BlockRailStraightBase method findPoweredRailSignal.

protected boolean findPoweredRailSignal(World worldIn, BlockPos pos, BlockState state, boolean searchForward, int recursionCount) {
    if (recursionCount >= 8) {
        return false;
    } else {
        int i = pos.getX();
        int j = pos.getY();
        int k = pos.getZ();
        boolean flag = true;
        RailShape railshape = state.getValue(SHAPE);
        switch(railshape) {
            case NORTH_SOUTH:
                if (searchForward) {
                    ++k;
                } else {
                    --k;
                }
                break;
            case EAST_WEST:
                if (searchForward) {
                    --i;
                } else {
                    ++i;
                }
                break;
            case ASCENDING_EAST:
                if (searchForward) {
                    --i;
                } else {
                    ++i;
                    ++j;
                    flag = false;
                }
                railshape = RailShape.EAST_WEST;
                break;
            case ASCENDING_WEST:
                if (searchForward) {
                    --i;
                    ++j;
                    flag = false;
                } else {
                    ++i;
                }
                railshape = RailShape.EAST_WEST;
                break;
            case ASCENDING_NORTH:
                if (searchForward) {
                    ++k;
                } else {
                    --k;
                    ++j;
                    flag = false;
                }
                railshape = RailShape.NORTH_SOUTH;
                break;
            case ASCENDING_SOUTH:
                if (searchForward) {
                    ++k;
                    ++j;
                    flag = false;
                } else {
                    --k;
                }
                railshape = RailShape.NORTH_SOUTH;
            case NORTH_EAST:
                break;
            case NORTH_WEST:
                break;
            case SOUTH_EAST:
                break;
            case SOUTH_WEST:
                break;
            default:
                break;
        }
        if (this.isSamePoweredRail(worldIn, new BlockPos(i, j, k), searchForward, recursionCount, railshape)) {
            return true;
        } else {
            return flag && this.isSamePoweredRail(worldIn, new BlockPos(i, j - 1, k), searchForward, recursionCount, railshape);
        }
    }
}
Also used : RailShape(net.minecraft.state.properties.RailShape) BlockPos(net.minecraft.util.math.BlockPos)

Example 7 with RailShape

use of net.minecraft.state.properties.RailShape in project MCMOD-Industria by M-Marvin.

the class BlockTSteelRail method onMinecartPass.

@Override
public void onMinecartPass(BlockState state, World world, BlockPos pos, AbstractMinecartEntity cart) {
    if (MinecartHandler.getHandlerForWorld(world).isBoosted(cart)) {
        Vector3d motion = cart.getDeltaMovement();
        double speed = Math.max(Math.abs(motion.x), Math.abs(motion.z));
        RailShape shape = state.getValue(SHAPE);
        boolean flag = shape == RailShape.NORTH_EAST || shape == RailShape.NORTH_WEST || shape == RailShape.SOUTH_EAST || shape == RailShape.SOUTH_WEST;
        if (speed > 0.1F && !flag) {
            double boostMul = 0.9F / speed;
            motion = motion.multiply(boostMul, 1, boostMul);
            cart.setDeltaMovement(motion);
        }
    }
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) RailShape(net.minecraft.state.properties.RailShape)

Example 8 with RailShape

use of net.minecraft.state.properties.RailShape in project Materialis by RCXcrafter.

the class WrenchingModifier method blockUse.

public ActionResultType blockUse(IModifierToolStack tool, int level, World world, BlockPos pos, BlockState state, ItemUseContext context) {
    if (context.getPlayer().isSecondaryUseActive() || !state.getBlock().canEntityDestroy(state, world, pos, context.getPlayer()) || state.getHarvestLevel() > tool.getStats().getInt(ToolStats.HARVEST_LEVEL) || !isRotatable(state, world, pos))
        return ActionResultType.PASS;
    Direction face = context.getClickedFace();
    Rotation rotation = context.getClickedFace().getAxisDirection() == Direction.AxisDirection.POSITIVE ? Rotation.CLOCKWISE_90 : Rotation.COUNTERCLOCKWISE_90;
    for (Property<?> prop : state.getProperties()) {
        if (prop instanceof DirectionProperty) {
            Direction direction = state.getValue((DirectionProperty) prop);
            Direction newDirection = rotateDirection(direction, face.getAxis(), rotation);
            if (newDirection != direction) {
                // make sure something changed
                BlockState newState = null;
                // check if the block can even be rotated like this
                int attempts = 0;
                boolean success = false;
                while (attempts < 3) {
                    if (prop.getPossibleValues().contains(newDirection)) {
                        newState = state.setValue((DirectionProperty) prop, newDirection);
                        if (newState.canSurvive(world, pos)) {
                            success = true;
                            break;
                        }
                    }
                    // try the next rotation
                    newDirection = rotateDirection(newDirection, face.getAxis(), rotation);
                    attempts++;
                }
                if (success) {
                    world.setBlock(pos, newState, Constants.BlockFlags.DEFAULT_AND_RERENDER);
                    ToolDamageUtil.damage(tool, 1, context.getPlayer(), context.getItemInHand());
                    return ActionResultType.SUCCESS;
                }
            }
        }
        if (prop == BlockStateProperties.AXIS || prop == BlockStateProperties.HORIZONTAL_AXIS) {
            Direction.Axis axis = prop == BlockStateProperties.AXIS ? state.getValue(BlockStateProperties.AXIS) : state.getValue(BlockStateProperties.HORIZONTAL_AXIS);
            Direction.Axis newAxis = rotateAxis(axis, face.getAxis(), rotation);
            if (newAxis != axis) {
                // check if the block can even be rotated like this
                if (prop.getPossibleValues().contains(newAxis)) {
                    BlockState newState;
                    if (prop == BlockStateProperties.AXIS)
                        newState = state.setValue(BlockStateProperties.AXIS, newAxis);
                    else
                        newState = state.setValue(BlockStateProperties.HORIZONTAL_AXIS, newAxis);
                    if (newState.canSurvive(world, pos)) {
                        world.setBlock(pos, newState, Constants.BlockFlags.DEFAULT_AND_RERENDER);
                        ToolDamageUtil.damage(tool, 1, context.getPlayer(), context.getItemInHand());
                        return ActionResultType.SUCCESS;
                    }
                }
            }
        }
        if (prop == BlockStateProperties.RAIL_SHAPE || prop == BlockStateProperties.RAIL_SHAPE_STRAIGHT) {
            RailShape shape = prop == BlockStateProperties.RAIL_SHAPE ? state.getValue(BlockStateProperties.RAIL_SHAPE) : state.getValue(BlockStateProperties.RAIL_SHAPE_STRAIGHT);
            RailShape newShape = rotateRail(shape, face.getAxis(), rotation);
            if (newShape != shape) {
                // check if the block can even be rotated like this
                if (shouldRailBeRemoved(pos, world, newShape))
                    newShape = rotateRail(shape, face.getAxis(), rotation.getRotated(Rotation.CLOCKWISE_180));
                if (!shouldRailBeRemoved(pos, world, newShape) && prop.getPossibleValues().contains(newShape)) {
                    BlockState newState;
                    if (prop == BlockStateProperties.RAIL_SHAPE)
                        newState = state.setValue(BlockStateProperties.RAIL_SHAPE, newShape);
                    else
                        newState = state.setValue(BlockStateProperties.RAIL_SHAPE_STRAIGHT, newShape);
                    world.setBlock(pos, newState, Constants.BlockFlags.DEFAULT_AND_RERENDER);
                    ToolDamageUtil.damage(tool, 1, context.getPlayer(), context.getItemInHand());
                    return ActionResultType.SUCCESS;
                }
            }
        }
        if (prop == BlockStateProperties.ROTATION_16) {
            int rotation16 = state.getValue(BlockStateProperties.ROTATION_16);
            rotation16 = (rotation16 + 1) % 16;
            world.setBlock(pos, state.setValue(BlockStateProperties.ROTATION_16, rotation16), Constants.BlockFlags.DEFAULT_AND_RERENDER);
            ToolDamageUtil.damage(tool, 1, context.getPlayer(), context.getItemInHand());
            return ActionResultType.SUCCESS;
        }
        if (prop == BlockStateProperties.HALF) {
            Half half = state.getValue(BlockStateProperties.HALF);
            if (half == Half.TOP)
                half = Half.BOTTOM;
            else
                half = Half.TOP;
            BlockState newState = state.setValue(BlockStateProperties.HALF, half);
            if (newState.canSurvive(world, pos)) {
                world.setBlock(pos, state.setValue(BlockStateProperties.HALF, half), Constants.BlockFlags.DEFAULT_AND_RERENDER);
                ToolDamageUtil.damage(tool, 1, context.getPlayer(), context.getItemInHand());
                return ActionResultType.SUCCESS;
            }
        }
        if (prop == BlockStateProperties.SLAB_TYPE) {
            SlabType half = state.getValue(BlockStateProperties.SLAB_TYPE);
            if (half != SlabType.DOUBLE) {
                if (half == SlabType.TOP)
                    half = SlabType.BOTTOM;
                else
                    half = SlabType.TOP;
                BlockState newState = state.setValue(BlockStateProperties.SLAB_TYPE, half);
                if (newState.canSurvive(world, pos)) {
                    world.setBlock(pos, newState, Constants.BlockFlags.DEFAULT_AND_RERENDER);
                    ToolDamageUtil.damage(tool, 1, context.getPlayer(), context.getItemInHand());
                    return ActionResultType.SUCCESS;
                }
            }
        }
    }
    return ActionResultType.PASS;
}
Also used : Half(net.minecraft.state.properties.Half) SlabType(net.minecraft.state.properties.SlabType) BlockState(net.minecraft.block.BlockState) RailShape(net.minecraft.state.properties.RailShape) DirectionProperty(net.minecraft.state.DirectionProperty) Direction(net.minecraft.util.Direction) Rotation(net.minecraft.util.Rotation)

Aggregations

RailShape (net.minecraft.state.properties.RailShape)8 AbstractRailBlock (net.minecraft.block.AbstractRailBlock)5 Vector3d (net.minecraft.util.math.vector.Vector3d)5 BlockState (net.minecraft.block.BlockState)4 BlockPos (net.minecraft.util.math.BlockPos)4 MinecoloniesMinecart (com.minecolonies.api.entity.MinecoloniesMinecart)2 PoweredRailBlock (net.minecraft.block.PoweredRailBlock)2 Vector3i (net.minecraft.util.math.vector.Vector3i)2 AbstractMinecartEntity (net.minecraft.entity.item.minecart.AbstractMinecartEntity)1 ItemStack (net.minecraft.item.ItemStack)1 DirectionProperty (net.minecraft.state.DirectionProperty)1 Half (net.minecraft.state.properties.Half)1 SlabType (net.minecraft.state.properties.SlabType)1 Direction (net.minecraft.util.Direction)1 Rotation (net.minecraft.util.Rotation)1 World (net.minecraft.world.World)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1