improve autobedtrap closes #34
This commit is contained in:
@@ -6,8 +6,10 @@
|
|||||||
An addon to Meteor Client that adds modules and commands that were too useless to be added to Meteor directly.
|
An addon to Meteor Client that adds modules and commands that were too useless to be added to Meteor directly.
|
||||||
</p>
|
</p>
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<img src="https://img.shields.io/badge/spaghetti%20code-yes-success" alt="Spagetti code: yes">
|
<img src="https://img.shields.io/badge/spaghetti%20code-yes-success?logo=java" alt="Spagetti code: yes">
|
||||||
<img src="https://img.shields.io/github/last-commit/AntiCope/meteor-rejects" alt="Last commit">
|
<img src="https://img.shields.io/github/last-commit/AntiCope/meteor-rejects?logo=git" alt="Last commit">
|
||||||
|
<img src="https://img.shields.io/github/workflow/status/AntiCope/meteor-rejects/Java%20CI%20with%20Gradle?logo=github" alt="build status">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
# How to use
|
# How to use
|
||||||
|
|||||||
@@ -3,20 +3,32 @@ package cloudburst.rejects.modules;
|
|||||||
import cloudburst.rejects.MeteorRejectsAddon;
|
import cloudburst.rejects.MeteorRejectsAddon;
|
||||||
import meteordevelopment.orbit.EventHandler;
|
import meteordevelopment.orbit.EventHandler;
|
||||||
import meteordevelopment.meteorclient.events.world.TickEvent;
|
import meteordevelopment.meteorclient.events.world.TickEvent;
|
||||||
|
import meteordevelopment.meteorclient.settings.BlockListSetting;
|
||||||
import meteordevelopment.meteorclient.settings.BoolSetting;
|
import meteordevelopment.meteorclient.settings.BoolSetting;
|
||||||
|
import meteordevelopment.meteorclient.settings.DoubleSetting;
|
||||||
import meteordevelopment.meteorclient.settings.IntSetting;
|
import meteordevelopment.meteorclient.settings.IntSetting;
|
||||||
import meteordevelopment.meteorclient.settings.Setting;
|
import meteordevelopment.meteorclient.settings.Setting;
|
||||||
import meteordevelopment.meteorclient.settings.SettingGroup;
|
import meteordevelopment.meteorclient.settings.SettingGroup;
|
||||||
import meteordevelopment.meteorclient.systems.modules.Module;
|
import meteordevelopment.meteorclient.systems.modules.Module;
|
||||||
|
import meteordevelopment.meteorclient.utils.misc.Pool;
|
||||||
import meteordevelopment.meteorclient.utils.player.FindItemResult;
|
import meteordevelopment.meteorclient.utils.player.FindItemResult;
|
||||||
import meteordevelopment.meteorclient.utils.player.InvUtils;
|
import meteordevelopment.meteorclient.utils.player.InvUtils;
|
||||||
|
import meteordevelopment.meteorclient.utils.world.BlockIterator;
|
||||||
import meteordevelopment.meteorclient.utils.world.BlockUtils;
|
import meteordevelopment.meteorclient.utils.world.BlockUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.lwjgl.system.CallbackI.B;
|
||||||
|
import org.lwjgl.system.CallbackI.P;
|
||||||
|
|
||||||
import net.minecraft.block.BedBlock;
|
import net.minecraft.block.BedBlock;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
|
||||||
import net.minecraft.util.hit.HitResult;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
|
||||||
|
|
||||||
public class AutoBedTrap extends Module {
|
public class AutoBedTrap extends Module {
|
||||||
|
|
||||||
@@ -38,49 +50,62 @@ public class AutoBedTrap extends Module {
|
|||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
BlockPos bed1;
|
private final Setting<Double> range = sgGeneral.add(new DoubleSetting.Builder()
|
||||||
Direction bed2direction;
|
.name("range")
|
||||||
BlockPos bed2;
|
.description("The break range.")
|
||||||
|
.defaultValue(4)
|
||||||
|
.min(0)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
private final Setting<List<Block>> blockTypes = sgGeneral.add(new BlockListSetting.Builder()
|
||||||
|
.name("blocks")
|
||||||
|
.description("The blocks you bedtrap with.")
|
||||||
|
.defaultValue(Arrays.asList(Blocks.OBSIDIAN))
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
private final Pool<BlockPos.Mutable> blockPosPool = new Pool<>(BlockPos.Mutable::new);
|
||||||
|
private final List<BlockPos.Mutable> blocks = new ArrayList<>();
|
||||||
|
|
||||||
int cap = 0;
|
int cap = 0;
|
||||||
boolean bed;
|
|
||||||
|
|
||||||
public AutoBedTrap() {
|
public AutoBedTrap() {
|
||||||
super(MeteorRejectsAddon.CATEGORY, "auto-bed-trap", "Automatically places obsidian around bed");
|
super(MeteorRejectsAddon.CATEGORY, "auto-bed-trap", "Automatically places obsidian around beds");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivate() {
|
public void onDeactivate() {
|
||||||
cap = 0;
|
for (BlockPos.Mutable blockPos : blocks) blockPosPool.free(blockPos);
|
||||||
bed1 = null;
|
blocks.clear();
|
||||||
if (mc.crosshairTarget == null) {
|
|
||||||
error("Not looking at a bed. Disabling.");
|
|
||||||
toggle();
|
|
||||||
}
|
|
||||||
bed1 = mc.crosshairTarget.getType() == HitResult.Type.BLOCK ? ((BlockHitResult) mc.crosshairTarget).getBlockPos() : null;
|
|
||||||
if (bed1 == null || !(mc.world.getBlockState(bed1).getBlock() instanceof BedBlock)) {
|
|
||||||
error("Not looking at a bed. Disabling.");
|
|
||||||
toggle();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
private void onTick(TickEvent.Pre event) {
|
private void onTick(TickEvent.Pre event) {
|
||||||
bed2direction = BedBlock.getOppositePartDirection(mc.world.getBlockState(bed1));
|
|
||||||
if (bed2direction == Direction.EAST) {
|
BlockIterator.register((int) Math.ceil(range.get()), (int) Math.ceil(range.get()), (blockPos, blockState) -> {
|
||||||
bed2 = bed1.east(1);
|
if (!BlockUtils.canBreak(blockPos, blockState)) return;
|
||||||
} else if (bed2direction == Direction.NORTH) {
|
|
||||||
bed2 = bed1.north(1);
|
if (!(blockState.getBlock() instanceof BedBlock)) return;
|
||||||
} else if (bed2direction == Direction.SOUTH) {
|
|
||||||
bed2 = bed1.south(1);
|
blocks.add(blockPosPool.get().set(blockPos));
|
||||||
} else if (bed2direction == Direction.WEST) {
|
});
|
||||||
bed2 = bed1.west(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
placeTickAround(bed1);
|
@EventHandler
|
||||||
placeTickAround(bed2);
|
private void onTickPost(TickEvent.Post event) {
|
||||||
|
boolean noBlocks = false;
|
||||||
|
for (BlockPos blockPos : blocks) {
|
||||||
|
if (!placeTickAround(blockPos)) {
|
||||||
|
noBlocks = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (noBlocks && isActive()) toggle();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void placeTickAround(BlockPos block) {
|
public boolean placeTickAround(BlockPos block) {
|
||||||
for (BlockPos b : new BlockPos[]{
|
for (BlockPos b : new BlockPos[]{
|
||||||
block.up(), block.west(),
|
block.up(), block.west(),
|
||||||
block.north(), block.south(),
|
block.north(), block.south(),
|
||||||
@@ -88,23 +113,30 @@ public class AutoBedTrap extends Module {
|
|||||||
|
|
||||||
if (cap >= bpt.get()) {
|
if (cap >= bpt.get()) {
|
||||||
cap = 0;
|
cap = 0;
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FindItemResult findBlock = InvUtils.findInHotbar(Items.OBSIDIAN);
|
if (blockTypes.get().contains(mc.world.getBlockState(b).getBlock())) return true;
|
||||||
|
|
||||||
|
FindItemResult findBlock = InvUtils.findInHotbar((item) -> {
|
||||||
|
if (!(item.getItem() instanceof BlockItem)) return false;
|
||||||
|
BlockItem bitem = (BlockItem)item.getItem();
|
||||||
|
return blockTypes.get().contains(bitem.getBlock());
|
||||||
|
});
|
||||||
if (!findBlock.found()) {
|
if (!findBlock.found()) {
|
||||||
error("No specified blocks found. Disabling.");
|
error("No specified blocks found. Disabling.");
|
||||||
toggle();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (BlockUtils.place(b, findBlock, rotate.get(), 10, false)) {
|
if (BlockUtils.place(b, findBlock, rotate.get(), 10, false)) {
|
||||||
cap++;
|
cap++;
|
||||||
if (cap >= bpt.get()) {
|
if (cap >= bpt.get()) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
cap = 0;
|
cap = 0;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user