autotnt stuff

This commit is contained in:
Cloudburst
2021-05-30 17:54:43 +02:00
parent e22157f5e5
commit 3c2eb3cbf5

View File

@@ -25,126 +25,123 @@ import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
public class AutoTNT extends Module { public class AutoTNT extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup(); private final SettingGroup sgGeneral = settings.getDefaultGroup();
// General // General
private final Setting<Integer> delay = sgGeneral.add(new IntSetting.Builder() private final Setting<Integer> delay = sgGeneral.add(new IntSetting.Builder()
.name("delay") .name("delay")
.description("Delay in ticks between ignition") .description("Delay in ticks between ignition")
.defaultValue(1) .defaultValue(1)
.build() .build()
); );
private final Setting<Integer> range = sgGeneral.add(new IntSetting.Builder() private final Setting<Integer> range = sgGeneral.add(new IntSetting.Builder()
.name("range") .name("range")
.description("Range of ignition") .description("Range of ignition")
.defaultValue(4) .defaultValue(4)
.build() .build()
); );
private final Setting<Boolean> turnOff = sgGeneral.add(new BoolSetting.Builder() private final Setting<Boolean> turnOff = sgGeneral.add(new BoolSetting.Builder()
.name("turn-off") .name("turn-off")
.description("Turns of after igniting tnt") .description("Turns of after igniting tnt")
.defaultValue(true) .defaultValue(true)
.build() .build()
); );
private final Setting<Boolean> antiBreak = sgGeneral.add(new BoolSetting.Builder() private final Setting<Boolean> antiBreak = sgGeneral.add(new BoolSetting.Builder()
.name("anti-break") .name("anti-break")
.description("Whether or not to save flint and steel from breaking.") .description("Whether or not to save flint and steel from breaking.")
.defaultValue(true) .defaultValue(true)
.build() .build()
); );
private final ArrayList<BlockPos> blocks = new ArrayList<>(); private final ArrayList<BlockPos> blocks = new ArrayList<>();
private BlockPos.Mutable bp = new BlockPos.Mutable(); private final BlockPos.Mutable bp = new BlockPos.Mutable();
private boolean ignited, messaged; private boolean ignited, messaged;
private int ticks = 0; private int ticks = 0;
private int preSlot, slot; private int preSlot, slot;
@Override public AutoTNT() {
public void onActivate() { super(MeteorRejectsAddon.CATEGORY, "auto-tnt", "Ignites TNT for you");
ignited = false; }
messaged = false;
} @Override
public void onActivate() {
@Override ignited = false;
public void onDeactivate() { messaged = false;
ticks = 0; }
}
@Override
public AutoTNT() { public void onDeactivate() {
super(MeteorRejectsAddon.CATEGORY, "auto-tnt", "Ignites TNT for you"); ticks = 0;
} }
@EventHandler @EventHandler
private void onTick(TickEvent.Post event) { private void onTick(TickEvent.Post event) {
if (ticks <= 0) { if (ticks <= 0) {
// Clear and get tnt blocks // Clear and get tnt blocks
blocks.clear(); blocks.clear();
for (BlockPos vec3d : BlockUtils.getSphere(mc.player.getBlockPos(), range.get(), range.get())) { for (BlockPos blockPos : BlockUtils.getSphere(mc.player.getBlockPos(), range.get(), range.get())) {
setBpToVec3d(vec3d); bp.set(blockPos);
if (mc.world.getBlockState(blockPos).getBlock() instanceof TntBlock) blocks.add(bp);
if (mc.world.getBlockState(bp).getBlock() instanceof TntBlock) blocks.add(bp.toImmutable()); }
}
// Make sure there are TNTs around us
// Make sure there are TNTs around us if (blocks.size() <= 0) {
if (blocks.size() <= 0) {
// If already ignited and turnOff.get()
// If already ignited and turnOff.get() if (turnOff.get() && ignited) {
if (turnOff.get() && ignited) { toggle();
toggle(); return;
return; }
}
// If we haven't warned yet
// If we haven't warned yet if (!messaged) {
if (!messaged) { error("No TNT in range");
error("No TNT in range"); messaged = true;
messaged = true; }
} return;
return; } else messaged = false;
}
else messaged = false; // Sort based on closest tnt
blocks.sort(Comparator.comparingDouble(PlayerUtils::distanceTo));
// Sort based on closest tnt
blocks.sort(Comparator.comparingDouble(PlayerUtils::distanceTo)); // Get slot
slot = getSlot();
// Get slot if (slot == -1) {
slot = getSlot(); error("No flint and steel in hotbar");
if (slot == -1) { return;
error("No flint and steel in hotbar"); }
return;
} // Ignition
bp.set(blocks.get(0));
// Ignition ignite(bp, slot);
bp.set(blocks.get(0));
ignite(bp, slot); // Reset ticks
ticks = delay.get();
// Reset ticks } else ticks--;
ticks = delay.get(); }
} else ticks--;
} private void ignite(BlockPos pos, int slot) {
// Set slots
private void ignite(BlockPos pos, int slot) { preSlot = mc.player.inventory.selectedSlot;
// Set slots mc.player.inventory.selectedSlot = slot;
preSlot = mc.player.inventory.selectedSlot;
mc.player.inventory.selectedSlot = slot; // Ignited the tnt
ActionResult result = mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true));
// Ignited the tnt if (result == ActionResult.CONSUME || result == ActionResult.SUCCESS) ignited = true;
ActionResult result = mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true));
if (result == ActionResult.CONSUME || result == ActionResult.SUCCESS) ignited = true; // Reset slot
mc.player.inventory.selectedSlot = preSlot;
// Reset slot }
mc.player.inventory.selectedSlot = preSlot;
} private int getSlot() {
return InvUtils.findItemInHotbar(item -> item.getItem() instanceof FlintAndSteelItem && (antiBreak.get() && (item.getMaxDamage() - item.getDamage()) > 10));
private int getSlot() { }
return InvUtils.findItemInHotbar(item -> item.getItem() instanceof FlintAndSteelItem && (antiBreak.get() && (item.getMaxDamage() - item.getDamage()) > 10));
} private void setBpToVec3d(Vec3d pos) {
bp.set(pos.getX(), pos.getY(), pos.getZ());
private void setBpToVec3d(BlockPos pos) { }
bp.set(pos.getX(), pos.getY(), pos.getZ()); }
}
}