Search in sources :

Example 61 with Axis

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

the class ItemVaultCTBehaviour method getUpDirection.

@Override
protected Direction getUpDirection(BlockAndTintGetter reader, BlockPos pos, BlockState state, Direction face) {
    Axis vaultBlockAxis = ItemVaultBlock.getVaultBlockAxis(state);
    boolean alongX = vaultBlockAxis == Axis.X;
    if (face.getAxis().isVertical() && alongX)
        return super.getUpDirection(reader, pos, state, face).getClockWise();
    if (face.getAxis() == vaultBlockAxis || face.getAxis().isVertical())
        return super.getUpDirection(reader, pos, state, face);
    return Direction.fromAxisAndDirection(vaultBlockAxis, alongX ? AxisDirection.POSITIVE : AxisDirection.NEGATIVE);
}
Also used : Axis(net.minecraft.core.Direction.Axis)

Example 62 with Axis

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

the class ItemVaultConnectivityHandler method formVaults.

private static void formVaults(BlockEntityType<?> type, BlockGetter world, VaultSearchCache cache, List<ItemVaultTileEntity> frontier) {
    PriorityQueue<Pair<Integer, ItemVaultTileEntity>> creationQueue = makeCreationQueue();
    Set<BlockPos> visited = new HashSet<>();
    int minY = Integer.MAX_VALUE;
    for (ItemVaultTileEntity fluidTankTileEntity : frontier) {
        BlockPos pos = fluidTankTileEntity.getBlockPos();
        minY = Math.min(pos.getY(), minY);
    }
    minY -= 3;
    while (!frontier.isEmpty()) {
        ItemVaultTileEntity tank = frontier.remove(0);
        BlockPos tankPos = tank.getBlockPos();
        if (visited.contains(tankPos))
            continue;
        visited.add(tankPos);
        int amount = tryToFormNewVault(tank, cache, true);
        if (amount > 1)
            creationQueue.add(Pair.of(amount, tank));
        for (Axis axis : Iterate.axes) {
            Direction d = Direction.fromAxisAndDirection(axis, AxisDirection.NEGATIVE);
            BlockPos next = tankPos.relative(d);
            if (next.getY() <= minY)
                continue;
            if (visited.contains(next))
                continue;
            ItemVaultTileEntity nextTank = vaultAt(type, world, next);
            if (nextTank == null)
                continue;
            if (nextTank.isRemoved())
                continue;
            frontier.add(nextTank);
        }
    }
    visited.clear();
    while (!creationQueue.isEmpty()) {
        Pair<Integer, ItemVaultTileEntity> next = creationQueue.poll();
        ItemVaultTileEntity toCreate = next.getValue();
        if (visited.contains(toCreate.getBlockPos()))
            continue;
        visited.add(toCreate.getBlockPos());
        tryToFormNewVault(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 63 with Axis

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

the class ItemVaultItem method tryMultiPlace.

private void tryMultiPlace(BlockPlaceContext ctx) {
    Player player = ctx.getPlayer();
    if (player == null)
        return;
    if (player.isSteppingCarefully())
        return;
    Direction face = ctx.getClickedFace();
    ItemStack stack = ctx.getItemInHand();
    Level world = ctx.getLevel();
    BlockPos pos = ctx.getClickedPos();
    BlockPos placedOnPos = pos.relative(face.getOpposite());
    BlockState placedOnState = world.getBlockState(placedOnPos);
    if (!ItemVaultBlock.isVault(placedOnState))
        return;
    ItemVaultTileEntity tankAt = ItemVaultConnectivityHandler.vaultAt(AllTileEntities.ITEM_VAULT.get(), world, placedOnPos);
    if (tankAt == null)
        return;
    ItemVaultTileEntity controllerTE = tankAt.getControllerTE();
    if (controllerTE == null)
        return;
    int width = controllerTE.radius;
    if (width == 1)
        return;
    int tanksToPlace = 0;
    Axis vaultBlockAxis = ItemVaultBlock.getVaultBlockAxis(placedOnState);
    if (vaultBlockAxis == null)
        return;
    if (face.getAxis() != vaultBlockAxis)
        return;
    Direction vaultFacing = Direction.fromAxisAndDirection(vaultBlockAxis, AxisDirection.POSITIVE);
    BlockPos startPos = face == vaultFacing.getOpposite() ? controllerTE.getBlockPos().relative(vaultFacing.getOpposite()) : controllerTE.getBlockPos().relative(vaultFacing, controllerTE.length);
    if (VecHelper.getCoordinate(startPos, vaultBlockAxis) != VecHelper.getCoordinate(pos, vaultBlockAxis))
        return;
    for (int xOffset = 0; xOffset < width; xOffset++) {
        for (int zOffset = 0; zOffset < width; zOffset++) {
            BlockPos offsetPos = vaultBlockAxis == Axis.X ? startPos.offset(0, xOffset, zOffset) : startPos.offset(xOffset, zOffset, 0);
            BlockState blockState = world.getBlockState(offsetPos);
            if (ItemVaultBlock.isVault(blockState))
                continue;
            if (!blockState.getMaterial().isReplaceable())
                return;
            tanksToPlace++;
        }
    }
    if (!player.isCreative() && stack.getCount() < tanksToPlace)
        return;
    for (int xOffset = 0; xOffset < width; xOffset++) {
        for (int zOffset = 0; zOffset < width; zOffset++) {
            BlockPos offsetPos = vaultBlockAxis == Axis.X ? startPos.offset(0, xOffset, zOffset) : startPos.offset(xOffset, zOffset, 0);
            BlockState blockState = world.getBlockState(offsetPos);
            if (ItemVaultBlock.isVault(blockState))
                continue;
            BlockPlaceContext context = BlockPlaceContext.at(ctx, offsetPos, face);
            player.getPersistentData().putBoolean("SilenceVaultSound", true);
            super.place(context);
            player.getPersistentData().remove("SilenceVaultSound");
        }
    }
}
Also used : Player(net.minecraft.world.entity.player.Player) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPlaceContext(net.minecraft.world.item.context.BlockPlaceContext) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) Axis(net.minecraft.core.Direction.Axis)

Example 64 with Axis

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

the class ConnectedPillarBlock method updateColumn.

private BlockState updateColumn(Level level, BlockPos pos, BlockState state, boolean present) {
    MutableBlockPos currentPos = new MutableBlockPos();
    Axis axis = state.getValue(AXIS);
    for (Direction connection : Iterate.directions) {
        if (connection.getAxis() == axis)
            continue;
        boolean connect = true;
        Move: for (Direction movement : Iterate.directionsInAxis(axis)) {
            currentPos.set(pos);
            for (int i = 0; i < 1000; i++) {
                if (!level.isAreaLoaded(currentPos, 1))
                    break;
                BlockState other1 = currentPos.equals(pos) ? state : level.getBlockState(currentPos);
                BlockState other2 = level.getBlockState(currentPos.relative(connection));
                boolean col1 = canConnect(state, other1);
                boolean col2 = canConnect(state, other2);
                currentPos.move(movement);
                if (!col1 && !col2)
                    break;
                if (col1 && col2)
                    continue;
                connect = false;
                break Move;
            }
        }
        state = setConnection(state, connection, connect);
    }
    return state;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) Axis(net.minecraft.core.Direction.Axis)

Example 65 with Axis

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

the class AABBOutline method renderFace.

protected void renderFace(PoseStack ms, SuperRenderTypeBuffer buffer, Direction direction, Vec3 p1, Vec3 p2, Vec3 p3, Vec3 p4, boolean noCull) {
    if (!params.faceTexture.isPresent())
        return;
    ResourceLocation faceTexture = params.faceTexture.get().getLocation();
    float alphaBefore = params.alpha;
    params.alpha = (direction == params.getHighlightedFace() && params.hightlightedFaceTexture.isPresent()) ? 1 : 0.5f;
    RenderType translucentType = RenderTypes.getOutlineTranslucent(faceTexture, !noCull);
    VertexConsumer builder = buffer.getLateBuffer(translucentType);
    Axis axis = direction.getAxis();
    Vec3 uDiff = p2.subtract(p1);
    Vec3 vDiff = p4.subtract(p1);
    float maxU = (float) Math.abs(axis == Axis.X ? uDiff.z : uDiff.x);
    float maxV = (float) Math.abs(axis == Axis.Y ? vDiff.z : vDiff.y);
    putQuadUV(ms, builder, p1, p2, p3, p4, 0, 0, maxU, maxV, Direction.UP);
    params.alpha = alphaBefore;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Vec3(net.minecraft.world.phys.Vec3) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) RenderType(net.minecraft.client.renderer.RenderType) Axis(net.minecraft.core.Direction.Axis)

Aggregations

Axis (net.minecraft.core.Direction.Axis)87 Direction (net.minecraft.core.Direction)43 BlockPos (net.minecraft.core.BlockPos)39 BlockState (net.minecraft.world.level.block.state.BlockState)37 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