autotnt stuff
This commit is contained in:
@@ -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
|
@Override
|
||||||
public void onDeactivate() {
|
public void onActivate() {
|
||||||
ticks = 0;
|
ignited = false;
|
||||||
}
|
messaged = false;
|
||||||
|
}
|
||||||
|
|
||||||
public AutoTNT() {
|
@Override
|
||||||
super(MeteorRejectsAddon.CATEGORY, "auto-tnt", "Ignites TNT for you");
|
public void onDeactivate() {
|
||||||
}
|
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
|
||||||
}
|
if (blocks.size() <= 0) {
|
||||||
|
|
||||||
// Make sure there are TNTs around us
|
// If already ignited and turnOff.get()
|
||||||
if (blocks.size() <= 0) {
|
if (turnOff.get() && ignited) {
|
||||||
|
toggle();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If already ignited and turnOff.get()
|
// If we haven't warned yet
|
||||||
if (turnOff.get() && ignited) {
|
if (!messaged) {
|
||||||
toggle();
|
error("No TNT in range");
|
||||||
return;
|
messaged = true;
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
} else messaged = false;
|
||||||
|
|
||||||
// If we haven't warned yet
|
// Sort based on closest tnt
|
||||||
if (!messaged) {
|
blocks.sort(Comparator.comparingDouble(PlayerUtils::distanceTo));
|
||||||
error("No TNT in range");
|
|
||||||
messaged = true;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else messaged = false;
|
|
||||||
|
|
||||||
// Sort based on closest tnt
|
// Get slot
|
||||||
blocks.sort(Comparator.comparingDouble(PlayerUtils::distanceTo));
|
slot = getSlot();
|
||||||
|
if (slot == -1) {
|
||||||
|
error("No flint and steel in hotbar");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Get slot
|
// Ignition
|
||||||
slot = getSlot();
|
bp.set(blocks.get(0));
|
||||||
if (slot == -1) {
|
ignite(bp, slot);
|
||||||
error("No flint and steel in hotbar");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ignition
|
// Reset ticks
|
||||||
bp.set(blocks.get(0));
|
ticks = delay.get();
|
||||||
ignite(bp, slot);
|
} else ticks--;
|
||||||
|
}
|
||||||
|
|
||||||
// Reset ticks
|
private void ignite(BlockPos pos, int slot) {
|
||||||
ticks = delay.get();
|
// Set slots
|
||||||
} else ticks--;
|
preSlot = mc.player.inventory.selectedSlot;
|
||||||
}
|
mc.player.inventory.selectedSlot = slot;
|
||||||
|
|
||||||
private void ignite(BlockPos pos, int slot) {
|
// Ignited the tnt
|
||||||
// Set slots
|
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));
|
||||||
preSlot = mc.player.inventory.selectedSlot;
|
if (result == ActionResult.CONSUME || result == ActionResult.SUCCESS) ignited = true;
|
||||||
mc.player.inventory.selectedSlot = slot;
|
|
||||||
|
|
||||||
// Ignited the tnt
|
// Reset slot
|
||||||
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));
|
mc.player.inventory.selectedSlot = preSlot;
|
||||||
if (result == ActionResult.CONSUME || result == ActionResult.SUCCESS) ignited = true;
|
}
|
||||||
|
|
||||||
// Reset slot
|
private int getSlot() {
|
||||||
mc.player.inventory.selectedSlot = preSlot;
|
return InvUtils.findItemInHotbar(item -> item.getItem() instanceof FlintAndSteelItem && (antiBreak.get() && (item.getMaxDamage() - item.getDamage()) > 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getSlot() {
|
private void setBpToVec3d(Vec3d pos) {
|
||||||
return InvUtils.findItemInHotbar(item -> item.getItem() instanceof FlintAndSteelItem && (antiBreak.get() && (item.getMaxDamage() - item.getDamage()) > 10));
|
bp.set(pos.getX(), pos.getY(), pos.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBpToVec3d(BlockPos pos) {
|
|
||||||
bp.set(pos.getX(), pos.getY(), pos.getZ());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user