|
5 | 5 |
|
6 | 6 | package meteordevelopment.meteorclient.systems.modules.player; |
7 | 7 |
|
| 8 | +import meteordevelopment.meteorclient.events.entity.player.InteractItemEvent; |
8 | 9 | import meteordevelopment.meteorclient.events.render.Render3DEvent; |
9 | 10 | import meteordevelopment.meteorclient.events.world.TickEvent; |
10 | 11 | import meteordevelopment.meteorclient.renderer.ShapeMode; |
11 | 12 | import meteordevelopment.meteorclient.settings.*; |
12 | 13 | import meteordevelopment.meteorclient.systems.modules.Categories; |
13 | 14 | import meteordevelopment.meteorclient.systems.modules.Module; |
| 15 | +import meteordevelopment.meteorclient.utils.player.InvUtils; |
14 | 16 | import meteordevelopment.meteorclient.utils.render.color.SettingColor; |
15 | 17 | import meteordevelopment.meteorclient.utils.world.BlockUtils; |
16 | 18 | import meteordevelopment.orbit.EventHandler; |
17 | | -import net.minecraft.item.BlockItem; |
18 | | -import net.minecraft.item.SpawnEggItem; |
19 | | -import net.minecraft.util.Hand; |
| 19 | +import net.minecraft.block.Block; |
| 20 | +import net.minecraft.block.Blocks; |
| 21 | +import net.minecraft.item.*; |
| 22 | +import net.minecraft.util.ActionResult; |
20 | 23 | import net.minecraft.util.hit.BlockHitResult; |
21 | 24 | import net.minecraft.util.hit.HitResult; |
| 25 | +import net.minecraft.util.math.Vec3d; |
22 | 26 |
|
23 | 27 | public class AirPlace extends Module { |
24 | 28 | private final SettingGroup sgGeneral = settings.getDefaultGroup(); |
@@ -80,24 +84,44 @@ public AirPlace() { |
80 | 84 | } |
81 | 85 |
|
82 | 86 | @EventHandler |
83 | | - private void onTick(TickEvent.Post event) { |
| 87 | + private void onTick(TickEvent.Pre event) { |
| 88 | + if (!InvUtils.testInHands(this::placeable)) return; |
| 89 | + if (mc.crosshairTarget != null && mc.crosshairTarget.getType() != HitResult.Type.MISS) return; |
| 90 | + |
84 | 91 | double r = customRange.get() ? range.get() : mc.player.getBlockInteractionRange(); |
85 | 92 | hitResult = mc.getCameraEntity().raycast(r, 0, false); |
| 93 | + } |
| 94 | + |
| 95 | + @EventHandler |
| 96 | + private void onInteractItem(InteractItemEvent event) { |
| 97 | + if (!(hitResult instanceof BlockHitResult bhr) || !placeable(mc.player.getStackInHand(event.hand))) return; |
86 | 98 |
|
87 | | - if (!(hitResult instanceof BlockHitResult blockHitResult) || !(mc.player.getMainHandStack().getItem() instanceof BlockItem) && !(mc.player.getMainHandStack().getItem() instanceof SpawnEggItem)) return; |
| 99 | + Block toPlace = Blocks.OBSIDIAN; |
| 100 | + Item i = mc.player.getStackInHand(event.hand).getItem(); |
| 101 | + if (i instanceof BlockItem blockItem) toPlace = blockItem.getBlock(); |
| 102 | + if (!BlockUtils.canPlaceBlock(bhr.getBlockPos(), (i instanceof ArmorStandItem || i instanceof BlockItem), toPlace)) return; |
88 | 103 |
|
89 | | - if (mc.options.useKey.isPressed()) { |
90 | | - BlockUtils.place(blockHitResult.getBlockPos(), Hand.MAIN_HAND, mc.player.getInventory().getSelectedSlot(), false, 0, true, true, false); |
91 | | - } |
| 104 | + Vec3d hitPos = Vec3d.ofCenter(bhr.getBlockPos()); |
| 105 | + |
| 106 | + BlockHitResult b = new BlockHitResult(hitPos, mc.player.getMovementDirection().getOpposite(), bhr.getBlockPos(), false); |
| 107 | + BlockUtils.interact(b, event.hand, true); |
| 108 | + |
| 109 | + event.toReturn = ActionResult.SUCCESS; |
92 | 110 | } |
93 | 111 |
|
94 | 112 | @EventHandler |
95 | 113 | private void onRender(Render3DEvent event) { |
96 | | - if (!(hitResult instanceof BlockHitResult blockHitResult) |
97 | | - || !mc.world.getBlockState(blockHitResult.getBlockPos()).isReplaceable() |
98 | | - || !(mc.player.getMainHandStack().getItem() instanceof BlockItem) && !(mc.player.getMainHandStack().getItem() instanceof SpawnEggItem) |
| 114 | + if (!(hitResult instanceof BlockHitResult bhr) |
| 115 | + || (mc.crosshairTarget != null && mc.crosshairTarget.getType() != HitResult.Type.MISS) |
| 116 | + || !mc.world.getBlockState(bhr.getBlockPos()).isReplaceable() |
| 117 | + || !InvUtils.testInHands(this::placeable) |
99 | 118 | || !render.get()) return; |
100 | 119 |
|
101 | | - event.renderer.box(blockHitResult.getBlockPos(), sideColor.get(), lineColor.get(), shapeMode.get(), 0); |
| 120 | + event.renderer.box(bhr.getBlockPos(), sideColor.get(), lineColor.get(), shapeMode.get(), 0); |
| 121 | + } |
| 122 | + |
| 123 | + private boolean placeable(ItemStack stack) { |
| 124 | + Item i = stack.getItem(); |
| 125 | + return i instanceof BlockItem || i instanceof SpawnEggItem || i instanceof FireworkRocketItem || i instanceof ArmorStandItem; |
102 | 126 | } |
103 | 127 | } |
0 commit comments