Search in sources :

Example 1 with EncasedBeltBlock

use of com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock 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 EncasedBeltBlock

use of com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock in project Create by Creators-of-Create.

the class RotationPropagator method getRotationSpeedModifier.

/**
 * Determines the change in rotation between two attached kinetic entities. For
 * instance, an axis connection returns 1 while a 1-to-1 gear connection
 * reverses the rotation and therefore returns -1.
 *
 * @param from
 * @param to
 * @return
 */
private static float getRotationSpeedModifier(KineticTileEntity from, KineticTileEntity to) {
    final BlockState stateFrom = from.getBlockState();
    final BlockState stateTo = to.getBlockState();
    Block fromBlock = stateFrom.getBlock();
    Block toBlock = stateTo.getBlock();
    if (!(fromBlock instanceof IRotate && toBlock instanceof IRotate))
        return 0;
    final IRotate definitionFrom = (IRotate) fromBlock;
    final IRotate definitionTo = (IRotate) toBlock;
    final BlockPos diff = to.getBlockPos().subtract(from.getBlockPos());
    final Direction direction = Direction.getNearest(diff.getX(), diff.getY(), diff.getZ());
    final Level world = from.getLevel();
    boolean alignedAxes = true;
    for (Axis axis : Axis.values()) if (axis != direction.getAxis())
        if (axis.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)
        return custom;
    // Axis <-> Axis
    if (connectedByAxis) {
        float axisModifier = getAxisModifier(to, direction.getOpposite());
        if (axisModifier != 0)
            axisModifier = 1 / axisModifier;
        return getAxisModifier(from, direction) * axisModifier;
    }
    // Attached Encased Belts
    if (fromBlock instanceof EncasedBeltBlock && toBlock instanceof EncasedBeltBlock) {
        boolean connected = EncasedBeltBlock.areBlocksConnected(stateFrom, stateTo, direction);
        return connected ? EncasedBeltBlock.getRotationSpeedModifier(from, to) : 0;
    }
    // Large Gear <-> Large Gear
    if (isLargeToLargeGear(stateFrom, stateTo, diff)) {
        Axis sourceAxis = stateFrom.getValue(AXIS);
        Axis targetAxis = stateTo.getValue(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 : 1;
    }
    // Gear <-> Large Gear
    if (ICogWheel.isLargeCog(stateFrom) && ICogWheel.isSmallCog(stateTo))
        if (isLargeToSmallCog(stateFrom, stateTo, definitionTo, diff))
            return -2f;
    if (ICogWheel.isLargeCog(stateTo) && ICogWheel.isSmallCog(stateFrom))
        if (isLargeToSmallCog(stateTo, stateFrom, definitionFrom, diff))
            return -.5f;
    // Gear <-> Gear
    if (connectedByGears) {
        if (diff.distManhattan(BlockPos.ZERO) != 1)
            return 0;
        if (ICogWheel.isLargeCog(stateTo))
            return 0;
        if (direction.getAxis() == definitionFrom.getRotationAxis(stateFrom))
            return 0;
        if (definitionFrom.getRotationAxis(stateFrom) == definitionTo.getRotationAxis(stateTo))
            return -1;
    }
    return 0;
}
Also used : IRotate(com.simibubi.create.content.contraptions.base.IRotate) BlockState(net.minecraft.world.level.block.state.BlockState) CogWheelBlock(com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock) SpeedControllerBlock(com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerBlock) Block(net.minecraft.world.level.block.Block) EncasedBeltBlock(com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock) EncasedBeltBlock(com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) Direction(net.minecraft.core.Direction) Axis(net.minecraft.core.Direction.Axis)

Aggregations

IRotate (com.simibubi.create.content.contraptions.base.IRotate)2 SpeedControllerBlock (com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerBlock)2 CogWheelBlock (com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock)2 EncasedBeltBlock (com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock)2 Block (net.minecraft.block.Block)1 BlockState (net.minecraft.block.BlockState)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 Axis (net.minecraft.core.Direction.Axis)1 Direction (net.minecraft.util.Direction)1 Axis (net.minecraft.util.Direction.Axis)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 Level (net.minecraft.world.level.Level)1 Block (net.minecraft.world.level.block.Block)1 BlockState (net.minecraft.world.level.block.state.BlockState)1