Search in sources :

Example 1 with Axis

use of net.minecraft.util.Direction.Axis in project Create_Aeronautics by Eriksonnaren.

the class RotationPropagatorMixin method getRotationSpeedModifier.

private static float getRotationSpeedModifier(KineticTileEntity from, KineticTileEntity to) {
    BlockState stateFrom = from.getBlockState();
    BlockState stateTo = to.getBlockState();
    Block fromBlock = stateFrom.getBlock();
    Block toBlock = stateTo.getBlock();
    if (fromBlock instanceof IRotate && toBlock instanceof IRotate) {
        IRotate definitionFrom = (IRotate) fromBlock;
        IRotate definitionTo = (IRotate) toBlock;
        BlockPos diff = to.getBlockPos().subtract(from.getBlockPos());
        Direction direction = Direction.getNearest((float) diff.getX(), (float) diff.getY(), (float) diff.getZ());
        World world = from.getLevel();
        boolean alignedAxes = true;
        Axis[] var12 = Axis.values();
        int var13 = var12.length;
        Axis sourceAxis;
        for (int var14 = 0; var14 < var13; ++var14) {
            sourceAxis = var12[var14];
            if (sourceAxis != direction.getAxis() && sourceAxis.choose(diff.getX(), diff.getY(), diff.getZ()) != 0) {
                alignedAxes = false;
            }
        }
        boolean connectedByAxis = alignedAxes && definitionFrom.hasShaftTowards(world, from.getBlockPos(), stateFrom, direction) && definitionTo.hasShaftTowards(world, to.getBlockPos(), stateTo, direction.getOpposite());
        boolean connectedByGears = ICogWheel.isSmallCog(stateFrom) && ICogWheel.isSmallCog(stateTo);
        float custom = from.propagateRotationTo(to, stateFrom, stateTo, diff, connectedByAxis, connectedByGears);
        if (custom != 0.0F) {
            return custom;
        } else if (connectedByAxis) {
            float axisModifier = getAxisModifier(to, direction.getOpposite());
            if (axisModifier != 0.0F) {
                axisModifier = 1.0F / axisModifier;
            }
            return getAxisModifier(from, direction) * axisModifier;
        } else if (fromBlock instanceof EncasedBeltBlock && toBlock instanceof EncasedBeltBlock) {
            boolean connected = EncasedBeltBlock.areBlocksConnected(stateFrom, stateTo, direction);
            return connected ? EncasedBeltBlock.getRotationSpeedModifier(from, to) : 0.0F;
        } else if (isLargeToLargeGear(stateFrom, stateTo, diff)) {
            sourceAxis = (Axis) stateFrom.getValue(BlockStateProperties.AXIS);
            Axis targetAxis = (Axis) stateTo.getValue(BlockStateProperties.AXIS);
            int sourceAxisDiff = sourceAxis.choose(diff.getX(), diff.getY(), diff.getZ());
            int targetAxisDiff = targetAxis.choose(diff.getX(), diff.getY(), diff.getZ());
            return sourceAxisDiff > 0 ^ targetAxisDiff > 0 ? -1.0F : 1.0F;
        } else if (ICogWheel.isLargeCog(stateFrom) && ICogWheel.isSmallCog(stateTo) && isLargeToSmallCog(stateFrom, stateTo, definitionTo, diff)) {
            return -2.0F;
        } else if (ICogWheel.isLargeCog(stateTo) && ICogWheel.isSmallCog(stateFrom) && isLargeToSmallCog(stateTo, stateFrom, definitionFrom, diff)) {
            return -0.5F;
        } else {
            if (connectedByGears) {
                if (diff.distManhattan(BlockPos.ZERO) != 1) {
                    return 0.0F;
                }
                if (ICogWheel.isLargeCog(stateTo)) {
                    return 0.0F;
                }
                if (direction.getAxis() == definitionFrom.getRotationAxis(stateFrom)) {
                    return 0.0F;
                }
                if (definitionFrom.getRotationAxis(stateFrom) == definitionTo.getRotationAxis(stateTo)) {
                    return -1.0F;
                }
            }
            return 0.0F;
        }
    } else {
        return 0.0F;
    }
}
Also used : IRotate(com.simibubi.create.content.contraptions.base.IRotate) BlockState(net.minecraft.block.BlockState) Block(net.minecraft.block.Block) CogWheelBlock(com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock) EncasedBeltBlock(com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock) SpeedControllerBlock(com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerBlock) EncasedBeltBlock(com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Direction(net.minecraft.util.Direction) Axis(net.minecraft.util.Direction.Axis)

Example 2 with Axis

use of net.minecraft.util.Direction.Axis in project MCMOD-Industria by M-Marvin.

the class BlockRLinearConector method addBlocksToMove.

@SuppressWarnings("deprecation")
public boolean addBlocksToMove(AdvancedPistonBlockStructureHelper pistonStructureHelper, BlockPos pos, BlockState state, World world) {
    Axis axis = state.getValue(AXIS);
    int range = state.getValue(RANGE);
    boolean flag12 = true;
    boolean flag22 = true;
    for (int i = 1; i <= range; i++) {
        BlockPos pos1 = pos;
        BlockPos pos2 = pos;
        switch(axis) {
            case X:
                // Stop Block Detecting in Push-Direction
                if (pistonStructureHelper.getMoveDirection() == Direction.EAST)
                    flag12 = false;
                pos1 = pos.relative(Direction.EAST, i);
                if (pistonStructureHelper.getMoveDirection() == Direction.WEST)
                    flag22 = false;
                pos2 = pos.relative(Direction.WEST, i);
                break;
            case Y:
                if (pistonStructureHelper.getMoveDirection() == Direction.UP)
                    flag12 = false;
                pos1 = pos.relative(Direction.UP, i);
                if (pistonStructureHelper.getMoveDirection() == Direction.DOWN)
                    flag22 = false;
                pos2 = pos.relative(Direction.DOWN, i);
                break;
            case Z:
                if (pistonStructureHelper.getMoveDirection() == Direction.SOUTH)
                    flag12 = false;
                pos1 = pos.relative(Direction.SOUTH, i);
                if (pistonStructureHelper.getMoveDirection() == Direction.NORTH)
                    flag22 = false;
                pos2 = pos.relative(Direction.NORTH, i);
                break;
        }
        BlockState state1 = world.getBlockState(pos1);
        BlockState state2 = world.getBlockState(pos2);
        // Check if Block in Push DIrection is Moveable
        if (!BlockRAdvancedPiston.canPush(state1, world, pos1, pistonStructureHelper.getMoveDirection(), true, pistonStructureHelper.getMoveDirection()))
            flag12 = false;
        if (!BlockRAdvancedPiston.canPush(state2, world, pos2, pistonStructureHelper.getMoveDirection(), true, pistonStructureHelper.getMoveDirection()))
            flag22 = false;
        if (pos1.equals(pistonStructureHelper.getPistonPos()) || state1.isAir() || state1.getPistonPushReaction() == PushReaction.DESTROY)
            flag12 = false;
        if (pos2.equals(pistonStructureHelper.getPistonPos()) || state2.isAir() || state2.getPistonPushReaction() == PushReaction.DESTROY)
            flag22 = false;
        boolean flag1 = !flag12 ? true : pistonStructureHelper.addBlockLine(pos1, pistonStructureHelper.getMoveDirection());
        boolean flag2 = !flag22 ? true : pistonStructureHelper.addBlockLine(pos2, pistonStructureHelper.getMoveDirection());
        if (state1.getBlock() == ModItems.conector_block)
            flag12 = false;
        if (state2.getBlock() == ModItems.conector_block)
            flag22 = false;
        if (!flag1 || !flag2)
            return false;
    }
    return true;
}
Also used : BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) Axis(net.minecraft.util.Direction.Axis)

Example 3 with Axis

use of net.minecraft.util.Direction.Axis in project MCMOD-Industria by M-Marvin.

the class BlockEnergyBarrierBorder method buildFieldOnSide.

@SuppressWarnings("deprecation")
protected void buildFieldOnSide(BlockState state, World world, BlockPos pos, Direction side, boolean active) {
    HashMap<BlockPos, Axis> buildPositions = new HashMap<BlockPos, Axis>();
    for (int i = 0; i < MAX_BUILD_DISTANCE; i++) {
        BlockPos buildPos = pos.relative(side, i);
        BlockState replaceState = world.getBlockState(buildPos);
        if (!active && replaceState.getBlock() == ModItems.energy_barrier) {
            buildPositions.put(buildPos, side.getAxis());
        } else if (replaceState.getBlock() instanceof BlockEnergyBarrierBorder) {
            world.setBlockAndUpdate(buildPos, replaceState.setValue(ACTIVE, active));
            break;
        } else if (active && replaceState.getBlock().getExplosionResistance(replaceState, world, buildPos, null) <= BUILD_DESTROY_FORCE && replaceState.getBlock() != ModItems.energy_barrier) {
            buildPositions.put(buildPos, side.getAxis());
        } else if (active) {
            return;
        } else if (!active && replaceState.isAir()) {
            break;
        }
        if (i == MAX_BUILD_DISTANCE - 1)
            return;
    }
    buildPositions.entrySet().forEach((entry) -> {
        BlockPos position = entry.getKey();
        Axis axis = entry.getValue();
        if (active) {
            world.destroyBlock(position, true);
            world.setBlockAndUpdate(position, ModItems.energy_barrier.createEnergyField(axis, getConnectedSides(world, pos.relative(side, -1), axis)));
        } else {
            world.destroyBlock(position, false);
        }
    });
}
Also used : BlockState(net.minecraft.block.BlockState) HashMap(java.util.HashMap) BlockPos(net.minecraft.util.math.BlockPos) Axis(net.minecraft.util.Direction.Axis)

Example 4 with Axis

use of net.minecraft.util.Direction.Axis in project FrostedHeart by TeamMoegMC.

the class FluidPipeBlock method getAxis.

@Nullable
private Axis getAxis(IBlockReader world, BlockPos pos, BlockState state) {
    if (!type.isInstance(state.getBlock()))
        return null;
    for (Axis axis : Axis.values()) {
        Direction d1 = Direction.getFacingFromAxis(AxisDirection.NEGATIVE, axis);
        Direction d2 = Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis);
        boolean openAt1 = isOpenAt(state, d1);
        boolean openAt2 = isOpenAt(state, d2);
        if (openAt1 && openAt2) {
            return axis;
        }
    }
    return null;
}
Also used : AxisDirection(net.minecraft.util.Direction.AxisDirection) Direction(net.minecraft.util.Direction) Axis(net.minecraft.util.Direction.Axis) Nullable(javax.annotation.Nullable)

Example 5 with Axis

use of net.minecraft.util.Direction.Axis in project Ceramics by KnightMiner.

the class KilnBlock method animateTick.

@Override
@OnlyIn(Dist.CLIENT)
public void animateTick(BlockState state, World world, BlockPos pos, Random random) {
    if (state.get(LIT)) {
        double x = pos.getX() + 0.5D;
        double y = pos.getY();
        double z = pos.getZ() + 0.5D;
        if (random.nextDouble() < 0.1D) {
            world.playSound(x, y, z, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
        }
        Direction facing = state.get(FACING);
        Axis axis = facing.getAxis();
        double axisOffset = random.nextDouble() * 0.6D - 0.3D;
        double xOffset = axis == Axis.X ? (double) facing.getXOffset() * 0.52D : axisOffset;
        double yOffset = random.nextDouble() * 7.0D / 16.0D;
        double zOffset = axis == Axis.Z ? (double) facing.getZOffset() * 0.52D : axisOffset;
        world.addParticle(ParticleTypes.SMOKE, x + xOffset, y + yOffset, z + zOffset, 0.0D, 0.0D, 0.0D);
    }
}
Also used : Direction(net.minecraft.util.Direction) Axis(net.minecraft.util.Direction.Axis) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Aggregations

Axis (net.minecraft.util.Direction.Axis)8 BlockState (net.minecraft.block.BlockState)4 Direction (net.minecraft.util.Direction)4 BlockPos (net.minecraft.util.math.BlockPos)4 World (net.minecraft.world.World)2 IRotate (com.simibubi.create.content.contraptions.base.IRotate)1 SpeedControllerBlock (com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerBlock)1 CogWheelBlock (com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock)1 EncasedBeltBlock (com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock)1 HashMap (java.util.HashMap)1 Nullable (javax.annotation.Nullable)1 IEnergyContainer (mekanism.api.energy.IEnergyContainer)1 FloatingLong (mekanism.api.math.FloatingLong)1 PacketLightningRender (mekanism.common.network.to_client.PacketLightningRender)1 Block (net.minecraft.block.Block)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ItemStack (net.minecraft.item.ItemStack)1 PathPoint (net.minecraft.pathfinding.PathPoint)1 AxisDirection (net.minecraft.util.Direction.AxisDirection)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1