Search in sources :

Example 1 with PistonBlock

use of net.minecraft.block.PistonBlock in project BleachHack by BleachDrinker420.

the class AutoBedrockBreak method onTick.

@BleachSubscribe
public void onTick(EventTick event) {
    if (pos != null) {
        switch(step) {
            case 0:
                if (!mc.world.isSpaceEmpty(new Box(pos.up(), pos.add(1, 8, 1)))) {
                    reset();
                    BleachLogger.info("Not enough empty space to break this block!");
                } else if (InventoryUtils.getSlot(true, i -> mc.player.getInventory().getStack(i).getItem() == Items.PISTON) == -1) {
                    reset();
                    BleachLogger.info("Missing pistons!");
                } else if (InventoryUtils.getSlot(true, i -> mc.player.getInventory().getStack(i).getItem() == Items.REDSTONE_BLOCK) == -1) {
                    reset();
                    BleachLogger.info("Missing a redstone block!");
                } else if (InventoryUtils.getSlot(true, i -> mc.player.getInventory().getStack(i).getItem() == Items.TNT) == -1) {
                    reset();
                    BleachLogger.info("Missing TNT!");
                } else if (InventoryUtils.getSlot(true, i -> mc.player.getInventory().getStack(i).getItem() == Items.LEVER) == -1) {
                    reset();
                    BleachLogger.info("Missing a lever!");
                } else if (dirtyPlace(pos.up(3), InventoryUtils.getSlot(true, i -> mc.player.getInventory().getStack(i).getItem() == Items.REDSTONE_BLOCK), Direction.DOWN)) {
                    step++;
                }
                break;
            case 1:
                mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.Full(mc.player.getX(), mc.player.getY(), mc.player.getZ(), mc.player.getYaw(), 90, mc.player.isOnGround()));
                // mc.player.setPitch(90) "its jank either way"
                step++;
                break;
            case 2:
                if (dirtyPlace(pos.up(), InventoryUtils.getSlot(true, i -> mc.player.getInventory().getStack(i).getItem() == Items.PISTON), Direction.DOWN))
                    step++;
                break;
            case 3:
                if (dirtyPlace(pos.up(7), InventoryUtils.getSlot(true, i -> mc.player.getInventory().getStack(i).getItem() == Items.TNT), Direction.DOWN))
                    step++;
                break;
            case 4:
                if (dirtyPlace(pos.up(6), InventoryUtils.getSlot(true, i -> mc.player.getInventory().getStack(i).getItem() == Items.LEVER), Direction.UP))
                    step++;
                break;
            case 5:
                if (dirtyPlace(pos.up(5), InventoryUtils.getSlot(true, i -> mc.player.getInventory().getStack(i).getItem() == Items.TNT), Direction.DOWN))
                    step++;
                break;
            case 6:
                Vec3d leverCenter = Vec3d.ofCenter(pos.up(6));
                if (mc.player.getEyePos().distanceTo(leverCenter) <= 4.75) {
                    mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(leverCenter, Direction.DOWN, pos.up(6), false));
                    step++;
                }
                break;
            default:
                if (mc.world.getBlockState(pos).isAir() || mc.world.getBlockState(pos).getBlock() instanceof PistonBlock || (mc.world.getBlockState(pos.up()).getBlock() instanceof PistonBlock && mc.world.getBlockState(pos.up()).get(PistonBlock.FACING) != Direction.UP)) {
                    setEnabled(false);
                    return;
                }
                if (step >= 82) {
                    mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.Full(mc.player.getX(), mc.player.getY(), mc.player.getZ(), mc.player.getYaw(), -90, mc.player.isOnGround()));
                // mc.player.setPitch(-90) "its jank either way"
                }
                if (step > 84) {
                    Hand hand = InventoryUtils.selectSlot(true, i -> mc.player.getInventory().getStack(i).getItem() == Items.PISTON);
                    if (hand != null) {
                        mc.player.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(hand, new BlockHitResult(Vec3d.ofBottomCenter(pos.up()), Direction.DOWN, pos.up(), false)));
                    }
                }
                step++;
                break;
        }
    }
}
Also used : BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe) ModuleCategory(org.bleachhack.module.ModuleCategory) EventInteract(org.bleachhack.event.events.EventInteract) Box(net.minecraft.util.math.Box) EventWorldRender(org.bleachhack.event.events.EventWorldRender) InventoryUtils(org.bleachhack.util.InventoryUtils) PistonBlock(net.minecraft.block.PistonBlock) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Renderer(org.bleachhack.util.render.Renderer) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) Module(org.bleachhack.module.Module) QuadColor(org.bleachhack.util.render.color.QuadColor) Direction(net.minecraft.util.math.Direction) PlayerInteractBlockC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket) Vec3d(net.minecraft.util.math.Vec3d) BleachLogger(org.bleachhack.util.BleachLogger) PlayerMoveC2SPacket(net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket) Hand(net.minecraft.util.Hand) EventTick(org.bleachhack.event.events.EventTick) PlayerMoveC2SPacket(net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket) Box(net.minecraft.util.math.Box) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Hand(net.minecraft.util.Hand) Vec3d(net.minecraft.util.math.Vec3d) PistonBlock(net.minecraft.block.PistonBlock) PlayerInteractBlockC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 2 with PistonBlock

use of net.minecraft.block.PistonBlock in project lithium-fabric by CaffeineMC.

the class PistonBlockEntityMixin method skipVoxelShapeUnion.

/**
 * Avoid calling {@link VoxelShapes#union(VoxelShape, VoxelShape)} whenever possible - use precomputed merged piston head + base shapes and
 * cache the results for all union calls with an empty shape as first argument. (these are all other cases)
 */
@Inject(method = "getCollisionShape(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/util/shape/VoxelShape;", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Direction;getOffsetX()I", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void skipVoxelShapeUnion(BlockView world, BlockPos pos, CallbackInfoReturnable<VoxelShape> cir, VoxelShape voxelShape, Direction direction, BlockState blockState, float f) {
    if (this.extending || !this.source || !(this.pushedBlock.getBlock() instanceof PistonBlock)) {
        // here voxelShape2.isEmpty() is guaranteed, vanilla code would call union() which calls simplify()
        VoxelShape blockShape = blockState.getCollisionShape(world, pos);
        // we cache the simplified shapes, as the simplify() method costs a lot of CPU time and allocates several objects
        VoxelShape offsetAndSimplified = getOffsetAndSimplified(blockShape, Math.abs(f), f < 0f ? this.facing.getOpposite() : this.facing);
        cir.setReturnValue(offsetAndSimplified);
    } else {
        // retracting piston heads have to act like their base as well, as the base block is replaced with the moving block
        // f >= 0f is guaranteed (assuming no other mod interferes)
        int index = getIndexForMergedShape(f, this.facing);
        cir.setReturnValue(PISTON_BASE_WITH_MOVING_HEAD_SHAPES[index]);
    }
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) PistonBlock(net.minecraft.block.PistonBlock) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

PistonBlock (net.minecraft.block.PistonBlock)2 Items (net.minecraft.item.Items)1 PlayerInteractBlockC2SPacket (net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket)1 PlayerMoveC2SPacket (net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket)1 Hand (net.minecraft.util.Hand)1 BlockHitResult (net.minecraft.util.hit.BlockHitResult)1 BlockPos (net.minecraft.util.math.BlockPos)1 Box (net.minecraft.util.math.Box)1 Direction (net.minecraft.util.math.Direction)1 Vec3d (net.minecraft.util.math.Vec3d)1 VoxelShape (net.minecraft.util.shape.VoxelShape)1 EventInteract (org.bleachhack.event.events.EventInteract)1 EventTick (org.bleachhack.event.events.EventTick)1 EventWorldRender (org.bleachhack.event.events.EventWorldRender)1 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)1 Module (org.bleachhack.module.Module)1 ModuleCategory (org.bleachhack.module.ModuleCategory)1 BleachLogger (org.bleachhack.util.BleachLogger)1 InventoryUtils (org.bleachhack.util.InventoryUtils)1 Renderer (org.bleachhack.util.render.Renderer)1