Search in sources :

Example 6 with Direction

use of net.minecraft.util.math.Direction in project lithium-fabric by CaffeineMC.

the class PistonBlockEntityMixin method precomputePistonBaseWithMovingHeadShapes.

/**
 * Precompute all 18 possible configurations for the merged piston base and head shape.
 *
 * @return The array of the merged VoxelShapes, indexed by {@link PistonBlockEntityMixin#getIndexForMergedShape(float, Direction)}
 */
private static VoxelShape[] precomputePistonBaseWithMovingHeadShapes() {
    float[] offsets = { 0f, 0.5f, 1f };
    Direction[] directions = Direction.values();
    VoxelShape[] mergedShapes = new VoxelShape[offsets.length * directions.length];
    for (Direction facing : directions) {
        VoxelShape baseShape = Blocks.PISTON.getDefaultState().with(PistonBlock.EXTENDED, true).with(PistonBlock.FACING, facing).getCollisionShape(null, null);
        for (float offset : offsets) {
            // this cache is only required for the merged piston head + base shape.
            // this shape is only used when !this.extending
            // here: isShort = this.extending != 1.0F - this.progress < 0.25F can be simplified to:
            // isShort = f < 0.25F , because f = getAmountExtended(this.progress) can be simplified to f == 1.0F - this.progress
            // therefore isShort is dependent on the offset:
            boolean isShort = offset < 0.25f;
            VoxelShape headShape = (Blocks.PISTON_HEAD.getDefaultState().with(PistonHeadBlock.FACING, facing)).with(PistonHeadBlock.SHORT, isShort).getCollisionShape(null, null);
            VoxelShape offsetHead = headShape.offset(facing.getOffsetX() * offset, facing.getOffsetY() * offset, facing.getOffsetZ() * offset);
            mergedShapes[getIndexForMergedShape(offset, facing)] = VoxelShapes.union(baseShape, offsetHead);
        }
    }
    return mergedShapes;
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) Direction(net.minecraft.util.math.Direction)

Example 7 with Direction

use of net.minecraft.util.math.Direction in project BleachHack by BleachDrinker420.

the class StorageESP method onWorldRender.

@BleachSubscribe
public void onWorldRender(EventWorldRender.Post event) {
    if (getSetting(0).asMode().getMode() == 0) {
        // Manually render blockentities because of culling
        for (BlockEntity be : WorldUtils.getBlockEntities()) {
            int[] color = getColorForBlock(be);
            if (color != null) {
                BlockEntityRenderer<BlockEntity> renderer = mc.getBlockEntityRenderDispatcher().get(be);
                MatrixStack matrices = Renderer.matrixFrom(be.getPos().getX(), be.getPos().getY(), be.getPos().getZ());
                if (renderer != null) {
                    renderer.render(be, mc.getTickDelta(), matrices, colorVertexer.createSingleProvider(mc.getBufferBuilders().getEntityVertexConsumers(), color[0], color[1], color[2], getSetting(1).asSlider().getValueInt()), LightmapTextureManager.MAX_LIGHT_COORDINATE, OverlayTexture.DEFAULT_UV);
                } else {
                    BlockState state = be.getCachedState();
                    mc.getBlockRenderManager().getModelRenderer().renderFlat(mc.world, mc.getBlockRenderManager().getModel(state), state, be.getPos(), matrices, colorVertexer.createSingleProvider(mc.getBufferBuilders().getEntityVertexConsumers(), color[0], color[1], color[2], getSetting(1).asSlider().getValueInt()).getBuffer(RenderLayers.getMovingBlockLayer(state)), false, new Random(), 0L, OverlayTexture.DEFAULT_UV);
                }
            }
        }
        colorVertexer.draw();
        shader.render();
        shader.drawFramebufferToMain("main");
    } else {
        float width = getSetting(2).asSlider().getValueFloat();
        int fill = getSetting(3).asSlider().getValueInt();
        for (Entity e : mc.world.getEntities()) {
            int[] color = getColorForEntity(e);
            Box box = e.getBoundingBox();
            if (e instanceof ItemFrameEntity && ((ItemFrameEntity) e).getHeldItemStack().getItem() == Items.FILLED_MAP) {
                Axis axis = e.getHorizontalFacing().getAxis();
                box = box.expand(axis == Axis.X ? 0 : 0.125, axis == Axis.Y ? 0 : 0.125, axis == Axis.Z ? 0 : 0.125);
            }
            if (color != null) {
                if (width != 0)
                    Renderer.drawBoxOutline(box, QuadColor.single(color[0], color[1], color[2], 255), width);
                if (fill != 0)
                    Renderer.drawBoxFill(box, QuadColor.single(color[0], color[1], color[2], fill));
            }
        }
        Set<BlockPos> skip = new HashSet<>();
        for (BlockEntity be : WorldUtils.getBlockEntities()) {
            if (skip.contains(be.getPos()))
                continue;
            int[] color = getColorForBlock(be);
            Box box = be.getCachedState().getOutlineShape(mc.world, be.getPos()).getBoundingBox().offset(be.getPos());
            Direction dir = getChestDirection(be);
            if (dir != null) {
                box = Boxes.stretch(box, dir, 0.94);
                skip.add(be.getPos().offset(dir));
            }
            if (color != null) {
                if (width != 0)
                    Renderer.drawBoxOutline(box, QuadColor.single(color[0], color[1], color[2], 255), width);
                if (fill != 0)
                    Renderer.drawBoxFill(box, QuadColor.single(color[0], color[1], color[2], fill));
            }
        }
    }
}
Also used : ItemFrameEntity(net.minecraft.entity.decoration.ItemFrameEntity) FurnaceMinecartEntity(net.minecraft.entity.vehicle.FurnaceMinecartEntity) Entity(net.minecraft.entity.Entity) HopperMinecartEntity(net.minecraft.entity.vehicle.HopperMinecartEntity) ChestMinecartEntity(net.minecraft.entity.vehicle.ChestMinecartEntity) MatrixStack(net.minecraft.client.util.math.MatrixStack) Box(net.minecraft.util.math.Box) Direction(net.minecraft.util.math.Direction) BlockState(net.minecraft.block.BlockState) Random(java.util.Random) ItemFrameEntity(net.minecraft.entity.decoration.ItemFrameEntity) BlockPos(net.minecraft.util.math.BlockPos) Axis(net.minecraft.util.math.Direction.Axis) HashSet(java.util.HashSet) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 8 with Direction

use of net.minecraft.util.math.Direction in project BleachHack by BleachDrinker420.

the class WorldUtils method placeBlock.

public static boolean placeBlock(BlockPos pos, int slot, int rotateMode, boolean forceLegit, boolean airPlace, boolean swingHand) {
    if (!mc.world.isInBuildLimit(pos) || !isBlockEmpty(pos))
        return false;
    for (Direction d : Direction.values()) {
        if (!mc.world.isInBuildLimit(pos.offset(d)))
            continue;
        Block neighborBlock = mc.world.getBlockState(pos.offset(d)).getBlock();
        if (!airPlace && neighborBlock.getDefaultState().getMaterial().isReplaceable())
            continue;
        Vec3d vec = getLegitLookPos(pos.offset(d), d.getOpposite(), true, 5);
        if (vec == null) {
            if (forceLegit) {
                continue;
            }
            vec = getLegitLookPos(pos.offset(d), d.getOpposite(), false, 5);
            if (vec == null) {
                continue;
            }
        }
        int prevSlot = mc.player.getInventory().selectedSlot;
        Hand hand = InventoryUtils.selectSlot(slot);
        if (hand == null) {
            return false;
        }
        if (rotateMode == 1) {
            facePosPacket(vec.x, vec.y, vec.z);
        } else if (rotateMode == 2) {
            facePos(vec.x, vec.y, vec.z);
        }
        if (RIGHTCLICKABLE_BLOCKS.contains(neighborBlock)) {
            mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, Mode.PRESS_SHIFT_KEY));
        }
        if (swingHand) {
            mc.player.swingHand(hand);
        } else {
            mc.player.networkHandler.sendPacket(new HandSwingC2SPacket(hand));
        }
        mc.interactionManager.interactBlock(mc.player, mc.world, hand, new BlockHitResult(Vec3d.of(pos), airPlace ? d : d.getOpposite(), airPlace ? pos : pos.offset(d), false));
        if (RIGHTCLICKABLE_BLOCKS.contains(neighborBlock))
            mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, Mode.RELEASE_SHIFT_KEY));
        mc.player.getInventory().selectedSlot = prevSlot;
        return true;
    }
    return false;
}
Also used : ClientCommandC2SPacket(net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket) HandSwingC2SPacket(net.minecraft.network.packet.c2s.play.HandSwingC2SPacket) LeavesBlock(net.minecraft.block.LeavesBlock) Block(net.minecraft.block.Block) PlantBlock(net.minecraft.block.PlantBlock) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Direction(net.minecraft.util.math.Direction) Hand(net.minecraft.util.Hand) Vec3d(net.minecraft.util.math.Vec3d)

Example 9 with Direction

use of net.minecraft.util.math.Direction in project BleachHack by BleachDrinker420.

the class HoleESP method onRender.

@BleachSubscribe
public void onRender(EventWorldRender.Post event) {
    if (getSetting(1).asToggle().getState()) {
        int bottomMode = getSetting(1).asToggle().getChild(0).asMode().getMode();
        Direction[] excludeDirs = ArrayUtils.remove(Direction.values(), 0);
        if (bottomMode == 0 || bottomMode == 2) {
            int alpha = (int) (getSetting(1).asToggle().getChild(2).asSlider().getValueFloat() * 255);
            holes.forEach((pos, color) -> Renderer.drawBoxFill(pos, QuadColor.single(color[0], color[1], color[2], alpha), excludeDirs));
        }
        if (bottomMode == 0 || bottomMode == 1) {
            holes.forEach((pos, color) -> Renderer.drawBoxOutline(pos, QuadColor.single(color[0], color[1], color[2], 255), getSetting(1).asToggle().getChild(1).asSlider().getValueFloat(), excludeDirs));
        }
    }
    if (getSetting(2).asToggle().getState()) {
        int sideMode = getSetting(2).asToggle().getChild(0).asMode().getMode();
        float height = getSetting(2).asToggle().getChild(3).asSlider().getValueFloat();
        int alpha = (int) (getSetting(2).asToggle().getChild(2).asSlider().getValueFloat() * 255);
        Direction[] excludeDirs = new Direction[] { Direction.UP, Direction.DOWN };
        if (sideMode == 0 || sideMode == 1) {
            CardinalDirection gradientDir = sideMode == 0 ? CardinalDirection.NORTH : CardinalDirection.SOUTH;
            holes.forEach((pos, color) -> Renderer.drawBoxFill(new Box(pos, pos.add(1, 0, 1)).stretch(0, height, 0), QuadColor.gradient(color[0], color[1], color[2], alpha, color[0], color[1], color[2], 0, gradientDir), excludeDirs));
        } else {
            if (sideMode == 2 || sideMode == 4) {
                holes.forEach((pos, color) -> Renderer.drawBoxFill(new Box(pos, pos.add(1, 0, 1)).stretch(0, height, 0), QuadColor.single(color[0], color[1], color[2], alpha), excludeDirs));
            }
            if (sideMode == 2 || sideMode == 3) {
                holes.forEach((pos, color) -> Renderer.drawBoxOutline(new Box(pos, pos.add(1, 0, 1)).stretch(0, height, 0), QuadColor.single(color[0], color[1], color[2], 255), getSetting(2).asToggle().getChild(1).asSlider().getValueFloat(), excludeDirs));
            }
        }
    }
}
Also used : CardinalDirection(org.bleachhack.util.render.color.QuadColor.CardinalDirection) Box(net.minecraft.util.math.Box) CardinalDirection(org.bleachhack.util.render.color.QuadColor.CardinalDirection) Direction(net.minecraft.util.math.Direction) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 10 with Direction

use of net.minecraft.util.math.Direction in project BleachHack by BleachDrinker420.

the class CrystalAura method getCrystalPoses.

public Set<Vec3d> getCrystalPoses() {
    Set<Vec3d> poses = new HashSet<>();
    int range = (int) Math.floor(getSetting(7).asSlider().getValue());
    for (int x = -range; x <= range; x++) {
        for (int y = -range; y <= range; y++) {
            for (int z = -range; z <= range; z++) {
                BlockPos basePos = new BlockPos(mc.player.getEyePos()).add(x, y, z);
                if (!canPlace(basePos) || (blacklist.containsKey(basePos) && getSetting(4).asToggle().getChild(2).asToggle().getState()))
                    continue;
                if (getSetting(4).asToggle().getChild(3).asToggle().getState()) {
                    boolean allBad = true;
                    for (Direction d : Direction.values()) {
                        if (WorldUtils.getLegitLookPos(basePos, d, true, 5) != null) {
                            allBad = false;
                            break;
                        }
                    }
                    if (allBad) {
                        continue;
                    }
                }
                if (mc.player.getPos().distanceTo(Vec3d.of(basePos).add(0.5, 1, 0.5)) <= getSetting(7).asSlider().getValue() + 0.25)
                    poses.add(Vec3d.of(basePos).add(0.5, 1, 0.5));
            }
        }
    }
    return poses;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.math.Direction) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

Direction (net.minecraft.util.math.Direction)184 BlockPos (net.minecraft.util.math.BlockPos)89 BlockState (net.minecraft.block.BlockState)46 Vec3d (net.minecraft.util.math.Vec3d)19 Block (net.minecraft.block.Block)14 BlockHitResult (net.minecraft.util.hit.BlockHitResult)13 Box (net.minecraft.util.math.Box)11 VoxelShape (net.minecraft.util.shape.VoxelShape)8 SculkVeinBlock (frozenblock.wild.mod.blocks.SculkVeinBlock)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 ArrayList (java.util.ArrayList)6 World (net.minecraft.world.World)6 Random (java.util.Random)5 Environment (net.fabricmc.api.Environment)5 BakedQuad (net.minecraft.client.render.model.BakedQuad)5 Nullable (org.jetbrains.annotations.Nullable)5 List (java.util.List)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 EventHandler (meteordevelopment.orbit.EventHandler)4