fix #37, add firecharge setting

This commit is contained in:
C10udburst
2021-09-11 10:27:31 +02:00
parent 4963fce4cf
commit 7fe0883c6f

View File

@@ -15,9 +15,8 @@ import meteordevelopment.meteorclient.utils.player.PlayerUtils;
import meteordevelopment.meteorclient.utils.world.BlockIterator; import meteordevelopment.meteorclient.utils.world.BlockIterator;
import meteordevelopment.meteorclient.utils.world.BlockUtils; import meteordevelopment.meteorclient.utils.world.BlockUtils;
import meteordevelopment.orbit.EventHandler; import meteordevelopment.orbit.EventHandler;
import net.minecraft.block.Blocks; import net.minecraft.block.TntBlock;
import net.minecraft.item.FlintAndSteelItem; import net.minecraft.item.*;
import net.minecraft.item.Items;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@@ -81,6 +80,15 @@ public class AutoTNT extends Module {
.name("anti-break") .name("anti-break")
.description("Whether to save flint and steel from breaking.") .description("Whether to save flint and steel from breaking.")
.defaultValue(true) .defaultValue(true)
.visible(ignite::get)
.build()
);
private final Setting<Boolean> fireCharge = sgGeneral.add(new BoolSetting.Builder()
.name("fire-charge")
.description("Whether to also use fire charges.")
.defaultValue(true)
.visible(ignite::get)
.build() .build()
); );
@@ -97,7 +105,6 @@ public class AutoTNT extends Module {
private final Pool<TntPos> placePool = new Pool<>(TntPos::new); private final Pool<TntPos> placePool = new Pool<>(TntPos::new);
private int igniteTick = 0; private int igniteTick = 0;
private int placeTick = 0; private int placeTick = 0;
private int prevSlot;
public AutoTNT() { public AutoTNT() {
super(MeteorRejectsAddon.CATEGORY, "auto-tnt", "Places and/or ignites tnt automatically. Good for griefing."); super(MeteorRejectsAddon.CATEGORY, "auto-tnt", "Places and/or ignites tnt automatically. Good for griefing.");
@@ -116,17 +123,9 @@ public class AutoTNT extends Module {
for (BlockPos.Mutable blockPos : blocksToIgnite) ignitePool.free(blockPos); for (BlockPos.Mutable blockPos : blocksToIgnite) ignitePool.free(blockPos);
blocksToIgnite.clear(); blocksToIgnite.clear();
// Item check
FindItemResult findSlot = InvUtils.findInHotbar(item -> item.getItem() instanceof FlintAndSteelItem && (antiBreak.get() && (item.getMaxDamage() - item.getDamage()) > 10));
if (!findSlot.found()) {
error("No flint and steel in hotbar");
toggle();
return;
}
// Register // Register
BlockIterator.register(horizontalRange.get(), verticalRange.get(), (blockPos, blockState) -> { BlockIterator.register(horizontalRange.get(), verticalRange.get(), (blockPos, blockState) -> {
if (blockState.getBlock() == Blocks.TNT) blocksToIgnite.add(ignitePool.get().set(blockPos)); if (blockState.getBlock() instanceof TntBlock) blocksToIgnite.add(ignitePool.get().set(blockPos));
}); });
} }
@@ -135,14 +134,6 @@ public class AutoTNT extends Module {
for (TntPos tntPos : blocksToPlace) placePool.free(tntPos); for (TntPos tntPos : blocksToPlace) placePool.free(tntPos);
blocksToPlace.clear(); blocksToPlace.clear();
// Item check
FindItemResult findSlot = InvUtils.findInHotbar(item -> item.getItem() == Items.TNT);
if (!findSlot.found()) {
error("No tnt in hotbar");
toggle();
return;
}
// Register // Register
BlockIterator.register(horizontalRange.get(), verticalRange.get(), (blockPos, blockState) -> { BlockIterator.register(horizontalRange.get(), verticalRange.get(), (blockPos, blockState) -> {
if (BlockUtils.canPlace(blockPos)) blocksToPlace.add(placePool.get().set(blockPos, TntDamage.calculate(blockPos))); if (BlockUtils.canPlace(blockPos)) blocksToPlace.add(placePool.get().set(blockPos, TntDamage.calculate(blockPos)));
@@ -159,12 +150,27 @@ public class AutoTNT extends Module {
blocksToIgnite.sort(Comparator.comparingDouble(PlayerUtils::distanceTo)); blocksToIgnite.sort(Comparator.comparingDouble(PlayerUtils::distanceTo));
// Ignition // Ignition
ignite(blocksToIgnite.get(0), InvUtils.findInHotbar(item -> item.getItem() instanceof FlintAndSteelItem && (antiBreak.get() && (item.getMaxDamage() - item.getDamage()) > 10))); FindItemResult itemResult = InvUtils.findInHotbar(item -> {
if (item.getItem() instanceof FlintAndSteelItem) {
return (antiBreak.get() && (item.getMaxDamage() - item.getDamage()) > 10);
}
else if (item.getItem() instanceof FireChargeItem) {
return fireCharge.get();
}
return false;
});
if (!itemResult.found()) {
error("No flint and steel in hotbar");
toggle();
return;
}
ignite(blocksToIgnite.get(0), itemResult);
// Reset ticks // Reset ticks
igniteTick = 0; igniteTick = 0;
} else igniteTick++;
} }
}
igniteTick++;
// Placement // Placement
if (place.get() && blocksToPlace.size() > 0) { if (place.get() && blocksToPlace.size() > 0) {
@@ -173,13 +179,20 @@ public class AutoTNT extends Module {
blocksToPlace.sort(Comparator.comparingInt(o -> o.score)); blocksToPlace.sort(Comparator.comparingInt(o -> o.score));
// Placement // Placement
place(blocksToPlace.get(0).blockPos, InvUtils.findInHotbar(item -> item.getItem() == Items.TNT)); FindItemResult itemResult = InvUtils.findInHotbar(item -> item.getItem() == Items.TNT);
if (!itemResult.found()) {
error("No tnt in hotbar");
toggle();
return;
}
place(blocksToPlace.get(0).blockPos, itemResult);
// Reset ticks // Reset ticks
placeTick = 0; placeTick = 0;
} else placeTick++;
} }
} }
placeTick++;
}
private void ignite(BlockPos pos, FindItemResult item) { private void ignite(BlockPos pos, FindItemResult item) {
InvUtils.swap(item.getSlot(), true); InvUtils.swap(item.getSlot(), true);
@@ -198,7 +211,9 @@ public class AutoTNT extends Module {
public int score; public int score;
public TntPos set(BlockPos blockPos, int score) { public TntPos set(BlockPos blockPos, int score) {
if (this.blockPos != null)
this.blockPos.set(blockPos); this.blockPos.set(blockPos);
this.score = score; this.score = score;
return this; return this;