|
5 | 5 |
|
6 | 6 | package meteordevelopment.meteorclient.systems.modules.player; |
7 | 7 |
|
8 | | -import meteordevelopment.meteorclient.events.entity.player.AttackEntityEvent; |
9 | | -import meteordevelopment.meteorclient.events.entity.player.StartBreakingBlockEvent; |
| 8 | +import meteordevelopment.meteorclient.events.entity.player.*; |
10 | 9 | import meteordevelopment.meteorclient.settings.*; |
11 | 10 | import meteordevelopment.meteorclient.systems.modules.Categories; |
12 | 11 | import meteordevelopment.meteorclient.systems.modules.Module; |
13 | 12 | import meteordevelopment.meteorclient.systems.modules.Modules; |
14 | 13 | import meteordevelopment.meteorclient.utils.Utils; |
15 | | -import meteordevelopment.meteorclient.utils.world.BlockUtils; |
16 | 14 | import meteordevelopment.orbit.EventHandler; |
17 | 15 | import meteordevelopment.orbit.EventPriority; |
| 16 | +import net.minecraft.block.Block; |
| 17 | +import net.minecraft.block.BlockState; |
| 18 | +import net.minecraft.block.Blocks; |
| 19 | +import net.minecraft.block.PumpkinBlock; |
18 | 20 | import net.minecraft.enchantment.Enchantments; |
| 21 | +import net.minecraft.entity.passive.SheepEntity; |
| 22 | +import net.minecraft.entity.passive.SnowGolemEntity; |
19 | 23 | import net.minecraft.item.*; |
| 24 | +import net.minecraft.registry.tag.BlockTags; |
20 | 25 | import net.minecraft.registry.tag.ItemTags; |
21 | 26 |
|
22 | 27 | import java.util.List; |
| 28 | +import java.util.Objects; |
23 | 29 |
|
24 | 30 | public class ToolSaver extends Module { |
25 | 31 | private final SettingGroup sgGeneral = settings.getDefaultGroup(); |
@@ -86,6 +92,82 @@ private void onStartBreakingBlock(StartBreakingBlockEvent event) { |
86 | 92 | } |
87 | 93 | } |
88 | 94 |
|
| 95 | + @EventHandler(priority = EventPriority.HIGH) |
| 96 | + private void onInteractBlock(InteractBlockEvent event) { |
| 97 | + ItemStack s = mc.player.getStackInHand(event.hand); |
| 98 | + BlockState bs = mc.world.getBlockState(event.result.getBlockPos()); |
| 99 | + |
| 100 | + switch (toolType(s)) { |
| 101 | + case AXE: |
| 102 | + if (!bs.isIn(BlockTags.LOGS) && !isWaxedCopperBlock(bs.getBlock())) return; |
| 103 | + break; |
| 104 | + case SHEAR: |
| 105 | + if (!(bs.getBlock() instanceof PumpkinBlock)) return; |
| 106 | + break; |
| 107 | + case FLINT_AND_STEEL: |
| 108 | + break; |
| 109 | + default: |
| 110 | + return; |
| 111 | + } |
| 112 | + |
| 113 | + if (!_canUse(s)) { |
| 114 | + mc.options.useKey.setPressed(false); |
| 115 | + event.cancel(); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + @EventHandler(priority = EventPriority.HIGH) |
| 120 | + private void onInteractEntity(InteractEntityEvent event) { |
| 121 | + ItemStack s = mc.player.getStackInHand(event.hand); |
| 122 | + |
| 123 | + if (toolType(s) != ToolType.SHEAR) return; |
| 124 | + if (!(event.entity instanceof SheepEntity || event.entity instanceof SnowGolemEntity)) return; |
| 125 | + |
| 126 | + if (!_canUse(s)) { |
| 127 | + mc.options.useKey.setPressed(false); |
| 128 | + event.cancel(); |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + private static boolean isWaxedCopperBlock(Block b) { |
| 133 | + // there is no block tag or other apparent way to find waxed blocks... |
| 134 | + return b == Blocks.WAXED_WEATHERED_CHISELED_COPPER |
| 135 | + || b == Blocks.WAXED_EXPOSED_CHISELED_COPPER |
| 136 | + || b == Blocks.WAXED_CHISELED_COPPER |
| 137 | + || b == Blocks.WAXED_COPPER_BLOCK |
| 138 | + || b == Blocks.WAXED_WEATHERED_COPPER |
| 139 | + || b == Blocks.WAXED_EXPOSED_COPPER |
| 140 | + || b == Blocks.WAXED_OXIDIZED_COPPER |
| 141 | + || b == Blocks.WAXED_OXIDIZED_CUT_COPPER |
| 142 | + || b == Blocks.WAXED_WEATHERED_CUT_COPPER |
| 143 | + || b == Blocks.WAXED_EXPOSED_CUT_COPPER |
| 144 | + || b == Blocks.WAXED_CUT_COPPER |
| 145 | + || b == Blocks.WAXED_OXIDIZED_CUT_COPPER_STAIRS |
| 146 | + || b == Blocks.WAXED_WEATHERED_CUT_COPPER_STAIRS |
| 147 | + || b == Blocks.WAXED_EXPOSED_CUT_COPPER_STAIRS |
| 148 | + || b == Blocks.WAXED_CUT_COPPER_STAIRS |
| 149 | + || b == Blocks.WAXED_OXIDIZED_CUT_COPPER_SLAB |
| 150 | + || b == Blocks.WAXED_WEATHERED_CUT_COPPER_SLAB |
| 151 | + || b == Blocks.WAXED_EXPOSED_CUT_COPPER_SLAB |
| 152 | + || b == Blocks.WAXED_CUT_COPPER_SLAB |
| 153 | + || b == Blocks.WAXED_COPPER_DOOR |
| 154 | + || b == Blocks.WAXED_EXPOSED_COPPER_DOOR |
| 155 | + || b == Blocks.WAXED_OXIDIZED_COPPER_DOOR |
| 156 | + || b == Blocks.WAXED_WEATHERED_COPPER_DOOR |
| 157 | + || b == Blocks.WAXED_COPPER_TRAPDOOR |
| 158 | + || b == Blocks.WAXED_EXPOSED_COPPER_TRAPDOOR |
| 159 | + || b == Blocks.WAXED_OXIDIZED_COPPER_TRAPDOOR |
| 160 | + || b == Blocks.WAXED_WEATHERED_COPPER_TRAPDOOR |
| 161 | + || b == Blocks.WAXED_COPPER_GRATE |
| 162 | + || b == Blocks.WAXED_EXPOSED_COPPER_GRATE |
| 163 | + || b == Blocks.WAXED_WEATHERED_COPPER_GRATE |
| 164 | + || b == Blocks.WAXED_OXIDIZED_COPPER_GRATE |
| 165 | + || b == Blocks.WAXED_COPPER_BULB |
| 166 | + || b == Blocks.WAXED_EXPOSED_COPPER_BULB |
| 167 | + || b == Blocks.WAXED_WEATHERED_COPPER_BULB |
| 168 | + || b == Blocks.WAXED_OXIDIZED_COPPER_BULB; |
| 169 | + } |
| 170 | + |
89 | 171 |
|
90 | 172 | @EventHandler(priority = EventPriority.HIGH) |
91 | 173 | private void onAttackEntity(AttackEntityEvent event) { |
@@ -160,8 +242,7 @@ private boolean isIgnored(ItemStack tool) { |
160 | 242 | } |
161 | 243 |
|
162 | 244 | private boolean _canUse(ItemStack tool) { |
163 | | - ToolSaver ts = Modules.get().get(ToolSaver.class); |
164 | | - return !ts.isActive() || ts.isIgnored(tool) || !ts.isBroken(tool) || ts.canBreak(tool); |
| 245 | + return !isActive() || isIgnored(tool) || !isBroken(tool) || canBreak(tool); |
165 | 246 | } |
166 | 247 |
|
167 | 248 | public static boolean canUse(ItemStack tool) { |
|
0 commit comments