Search in sources :

Example 71 with Axis

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

the class KineticTileEntityRenderer method standardKineticRotationTransform.

public static SuperByteBuffer standardKineticRotationTransform(SuperByteBuffer buffer, KineticTileEntity te, int light) {
    final BlockPos pos = te.getBlockPos();
    Axis axis = ((IRotate) te.getBlockState().getBlock()).getRotationAxis(te.getBlockState());
    return kineticRotationTransform(buffer, te, axis, getAngleForTe(te, pos, axis), light);
}
Also used : BlockPos(net.minecraft.core.BlockPos) Axis(net.minecraft.core.Direction.Axis)

Example 72 with Axis

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

the class FluidTankConnectivityHandler method formTanks.

private static void formTanks(BlockEntityType<?> type, BlockGetter world, TankSearchCache cache, List<FluidTankTileEntity> frontier) {
    PriorityQueue<Pair<Integer, FluidTankTileEntity>> creationQueue = makeCreationQueue();
    Set<BlockPos> visited = new HashSet<>();
    int minX = Integer.MAX_VALUE;
    int minZ = Integer.MAX_VALUE;
    for (FluidTankTileEntity fluidTankTileEntity : frontier) {
        BlockPos pos = fluidTankTileEntity.getBlockPos();
        minX = Math.min(pos.getX(), minX);
        minZ = Math.min(pos.getZ(), minZ);
    }
    minX -= FluidTankTileEntity.getMaxSize();
    minZ -= FluidTankTileEntity.getMaxSize();
    while (!frontier.isEmpty()) {
        FluidTankTileEntity tank = frontier.remove(0);
        BlockPos tankPos = tank.getBlockPos();
        if (visited.contains(tankPos))
            continue;
        visited.add(tankPos);
        int amount = tryToFormNewTank(tank, cache, true);
        if (amount > 1)
            creationQueue.add(Pair.of(amount, tank));
        for (Axis axis : Iterate.axes) {
            Direction d = Direction.get(AxisDirection.NEGATIVE, axis);
            BlockPos next = tankPos.relative(d);
            if (next.getX() <= minX || next.getZ() <= minZ)
                continue;
            if (visited.contains(next))
                continue;
            FluidTankTileEntity nextTank = tankAt(type, world, next);
            if (nextTank == null)
                continue;
            if (nextTank.isRemoved())
                continue;
            frontier.add(nextTank);
        }
    }
    visited.clear();
    while (!creationQueue.isEmpty()) {
        Pair<Integer, FluidTankTileEntity> next = creationQueue.poll();
        FluidTankTileEntity toCreate = next.getValue();
        if (visited.contains(toCreate.getBlockPos()))
            continue;
        visited.add(toCreate.getBlockPos());
        tryToFormNewTank(toCreate, cache, false);
    }
}
Also used : BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) Axis(net.minecraft.core.Direction.Axis) Pair(org.apache.commons.lang3.tuple.Pair) HashSet(java.util.HashSet)

Example 73 with Axis

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

the class FluidPipeBlock method onWrenched.

@Override
public InteractionResult onWrenched(BlockState state, UseOnContext context) {
    if (tryRemoveBracket(context))
        return InteractionResult.SUCCESS;
    Level world = context.getLevel();
    BlockPos pos = context.getClickedPos();
    Direction clickedFace = context.getClickedFace();
    Axis axis = getAxis(world, pos, state);
    if (axis == null) {
        Vec3 clickLocation = context.getClickLocation().subtract(pos.getX(), pos.getY(), pos.getZ());
        double closest = Float.MAX_VALUE;
        Direction argClosest = Direction.UP;
        for (Direction direction : Iterate.directions) {
            if (clickedFace.getAxis() == direction.getAxis())
                continue;
            Vec3 centerOf = Vec3.atCenterOf(direction.getNormal());
            double distance = centerOf.distanceToSqr(clickLocation);
            if (distance < closest) {
                closest = distance;
                argClosest = direction;
            }
        }
        axis = argClosest.getAxis();
    }
    if (clickedFace.getAxis() == axis)
        return InteractionResult.PASS;
    if (!world.isClientSide) {
        FluidTransportBehaviour.cacheFlows(world, pos);
        world.setBlockAndUpdate(pos, AllBlocks.GLASS_FLUID_PIPE.getDefaultState().setValue(GlassFluidPipeBlock.AXIS, axis).setValue(BlockStateProperties.WATERLOGGED, state.getValue(BlockStateProperties.WATERLOGGED)));
        FluidTransportBehaviour.loadFlows(world, pos);
    }
    return InteractionResult.SUCCESS;
}
Also used : Vec3(net.minecraft.world.phys.Vec3) ServerLevel(net.minecraft.server.level.ServerLevel) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) Axis(net.minecraft.core.Direction.Axis)

Example 74 with Axis

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

the class FluidPropagator method getStraightPipeAxis.

@Nullable
public static Axis getStraightPipeAxis(BlockState state) {
    if (state.getBlock() instanceof PumpBlock)
        return state.getValue(PumpBlock.FACING).getAxis();
    if (state.getBlock() instanceof AxisPipeBlock)
        return state.getValue(AxisPipeBlock.AXIS);
    if (!FluidPipeBlock.isPipe(state))
        return null;
    Axis axisFound = null;
    int connections = 0;
    for (Axis axis : Iterate.axes) {
        Direction d1 = Direction.get(AxisDirection.NEGATIVE, axis);
        Direction d2 = Direction.get(AxisDirection.POSITIVE, axis);
        boolean openAt1 = FluidPipeBlock.isOpenAt(state, d1);
        boolean openAt2 = FluidPipeBlock.isOpenAt(state, d2);
        if (openAt1)
            connections++;
        if (openAt2)
            connections++;
        if (openAt1 && openAt2)
            if (axisFound != null)
                return null;
            else
                axisFound = axis;
    }
    return connections == 2 ? axisFound : null;
}
Also used : AxisPipeBlock(com.simibubi.create.content.contraptions.fluids.pipes.AxisPipeBlock) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) Axis(net.minecraft.core.Direction.Axis) Nullable(javax.annotation.Nullable)

Example 75 with Axis

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

the class BrassTunnelTileEntity method hasDistributionBehaviour.

public boolean hasDistributionBehaviour() {
    if (flaps.isEmpty())
        return false;
    if (connectedLeft || connectedRight)
        return true;
    BlockState blockState = getBlockState();
    if (!AllBlocks.BRASS_TUNNEL.has(blockState))
        return false;
    Axis axis = blockState.getValue(BrassTunnelBlock.HORIZONTAL_AXIS);
    for (Direction direction : flaps.keySet()) if (direction.getAxis() != axis)
        return true;
    return false;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) Axis(net.minecraft.core.Direction.Axis)

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