Search in sources :

Example 16 with Axis

use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.

the class KineticEffectHandler method spawnRotationIndicators.

public void spawnRotationIndicators() {
    float speed = kte.getSpeed();
    if (speed == 0)
        return;
    BlockState state = kte.getBlockState();
    Block block = state.getBlock();
    if (!(block instanceof KineticBlock))
        return;
    KineticBlock kb = (KineticBlock) block;
    float radius1 = kb.getParticleInitialRadius();
    float radius2 = kb.getParticleTargetRadius();
    Axis axis = kb.getRotationAxis(state);
    BlockPos pos = kte.getBlockPos();
    Level world = kte.getLevel();
    if (axis == null)
        return;
    if (world == null)
        return;
    char axisChar = axis.name().charAt(0);
    Vec3 vec = VecHelper.getCenterOf(pos);
    SpeedLevel speedLevel = SpeedLevel.of(speed);
    int color = speedLevel.getColor();
    int particleSpeed = speedLevel.getParticleSpeed();
    particleSpeed *= Math.signum(speed);
    if (world instanceof ServerLevel) {
        AllTriggers.triggerForNearbyPlayers(AllTriggers.ROTATION, world, pos, 5);
        RotationIndicatorParticleData particleData = new RotationIndicatorParticleData(color, particleSpeed, radius1, radius2, 10, axisChar);
        ((ServerLevel) world).sendParticles(particleData, vec.x, vec.y, vec.z, 20, 0, 0, 0, 1);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SpeedLevel(com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel) BlockState(net.minecraft.world.level.block.state.BlockState) Vec3(net.minecraft.world.phys.Vec3) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) ServerLevel(net.minecraft.server.level.ServerLevel) SpeedLevel(com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel) Level(net.minecraft.world.level.Level) Axis(net.minecraft.core.Direction.Axis) RotationIndicatorParticleData(com.simibubi.create.content.contraptions.particle.RotationIndicatorParticleData)

Example 17 with Axis

use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.

the class KineticTileEntity method addPropagationLocations.

/**
 * Specify additional locations the rotation propagator should look for
 * potentially connected components. Neighbour list contains offset positions in
 * all 6 directions by default.
 *
 * @param block
 * @param state
 * @param neighbours
 * @return
 */
public List<BlockPos> addPropagationLocations(IRotate block, BlockState state, List<BlockPos> neighbours) {
    if (!canPropagateDiagonally(block, state))
        return neighbours;
    Axis axis = block.getRotationAxis(state);
    BlockPos.betweenClosedStream(new BlockPos(-1, -1, -1), new BlockPos(1, 1, 1)).forEach(offset -> {
        if (axis.choose(offset.getX(), offset.getY(), offset.getZ()) != 0)
            return;
        if (offset.distSqr(0, 0, 0, false) != BlockPos.ZERO.distSqr(1, 1, 0, false))
            return;
        neighbours.add(worldPosition.offset(offset));
    });
    return neighbours;
}
Also used : BlockPos(net.minecraft.core.BlockPos) Axis(net.minecraft.core.Direction.Axis)

Example 18 with Axis

use of net.minecraft.core.Direction.Axis 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)

Example 19 with Axis

use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.

the class RotationPropagator method isLargeToLargeGear.

private static boolean isLargeToLargeGear(BlockState from, BlockState to, BlockPos diff) {
    if (!ICogWheel.isLargeCog(from) || !ICogWheel.isLargeCog(to))
        return false;
    Axis fromAxis = from.getValue(AXIS);
    Axis toAxis = to.getValue(AXIS);
    if (fromAxis == toAxis)
        return false;
    for (Axis axis : Axis.values()) {
        int axisDiff = axis.choose(diff.getX(), diff.getY(), diff.getZ());
        if (axis == fromAxis || axis == toAxis) {
            if (axisDiff == 0)
                return false;
        } else if (axisDiff != 0)
            return false;
    }
    return true;
}
Also used : Axis(net.minecraft.core.Direction.Axis)

Example 20 with Axis

use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.

the class BrassTunnelTileEntity method getAdjacent.

@Nullable
protected BrassTunnelTileEntity getAdjacent(boolean leftSide) {
    if (!hasLevel())
        return null;
    BlockState blockState = getBlockState();
    if (!AllBlocks.BRASS_TUNNEL.has(blockState))
        return null;
    Axis axis = blockState.getValue(BrassTunnelBlock.HORIZONTAL_AXIS);
    Direction baseDirection = Direction.get(AxisDirection.POSITIVE, axis);
    Direction direction = leftSide ? baseDirection.getCounterClockWise() : baseDirection.getClockWise();
    BlockPos adjacentPos = worldPosition.relative(direction);
    BlockState adjacentBlockState = level.getBlockState(adjacentPos);
    if (!AllBlocks.BRASS_TUNNEL.has(adjacentBlockState))
        return null;
    if (adjacentBlockState.getValue(BrassTunnelBlock.HORIZONTAL_AXIS) != axis)
        return null;
    BlockEntity adjacentTE = level.getBlockEntity(adjacentPos);
    if (adjacentTE.isRemoved())
        return null;
    if (!(adjacentTE instanceof BrassTunnelTileEntity))
        return null;
    return (BrassTunnelTileEntity) adjacentTE;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) Axis(net.minecraft.core.Direction.Axis) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Nullable(javax.annotation.Nullable)

Aggregations

Axis (net.minecraft.core.Direction.Axis)85 Direction (net.minecraft.core.Direction)43 BlockPos (net.minecraft.core.BlockPos)39 BlockState (net.minecraft.world.level.block.state.BlockState)35 AxisDirection (net.minecraft.core.Direction.AxisDirection)24 Vec3 (net.minecraft.world.phys.Vec3)14 Level (net.minecraft.world.level.Level)13 IRotate (com.simibubi.create.content.contraptions.base.IRotate)9 SuperByteBuffer (com.simibubi.create.foundation.render.SuperByteBuffer)7 Block (net.minecraft.world.level.block.Block)7 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)6 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)5 Player (net.minecraft.world.entity.player.Player)5 HashSet (java.util.HashSet)4 ItemStack (net.minecraft.world.item.ItemStack)4 KineticTileEntity (com.simibubi.create.content.contraptions.base.KineticTileEntity)3 Part (com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock.Part)3 ArrayList (java.util.ArrayList)3 ServerLevel (net.minecraft.server.level.ServerLevel)3 StructureBlockInfo (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo)3