Fixed Spawn Proofer

This commit is contained in:
StormyBytes
2021-06-04 05:23:01 +07:00
parent d0f7cb0d8a
commit 26dc135b7a
3 changed files with 119 additions and 111 deletions

View File

@@ -92,9 +92,6 @@ public class AutoTNT extends Module {
// If there isn't any tnt
if (blocks.size() <= 0) {
// Give a warning
error("No TNT in range");
// If we should just turn off after igniting
if (turnOff.get() && ignited) {
toggle();

View File

@@ -1,5 +1,7 @@
package cloudburst.rejects.modules;
import cloudburst.rejects.MeteorRejectsAddon;
import cloudburst.rejects.utils.WorldUtils;
import meteordevelopment.orbit.EventHandler;
import minegame159.meteorclient.events.render.RenderEvent;
import minegame159.meteorclient.events.world.TickEvent;
@@ -10,123 +12,132 @@ import minegame159.meteorclient.settings.*;
import minegame159.meteorclient.systems.modules.Module;
import minegame159.meteorclient.utils.player.InvUtils;
import minegame159.meteorclient.utils.render.color.SettingColor;
import minegame159.meteorclient.utils.world.BlockIterator;
import minegame159.meteorclient.utils.world.BlockUtils;
import net.minecraft.block.*;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.SlabType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.LightType;
import cloudburst.rejects.MeteorRejectsAddon;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class SpawnProofer extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup();
private final Setting<Integer> range = sgGeneral.add(new IntSetting.Builder()
.name("range")
.description("Range for block placement and rendering")
.min(1)
.max(4)
.sliderMin(1)
.sliderMax(1)
.defaultValue(3)
.build()
);
private final Setting<List<Block>> blocks = sgGeneral.add(new BlockListSetting.Builder()
.name("blocks")
.description("Blocks to use for spawn proofing")
.defaultValue(Collections.emptyList())
.build()
);
private final Setting<ShapeMode> shapeMode = sgGeneral.add(new EnumSetting.Builder<ShapeMode>()
.name("shape-mode")
.description("Shape mode")
.defaultValue(ShapeMode.Both)
.build()
);
private final Setting<SettingColor> sideColor = sgGeneral.add(new ColorSetting.Builder()
.name("side-color")
.description("Edge color")
.defaultValue(new SettingColor(255, 0, 0, 75))
.build()
);
private final Setting<SettingColor> lineColor = sgGeneral.add(new ColorSetting.Builder()
.name("line-color")
.description("Line color")
.defaultValue(new SettingColor(255, 0, 0, 255))
.build()
);
private final Setting<Boolean> rotate = sgGeneral.add(new BoolSetting.Builder()
.name("rotate")
.description("Rotates towards the blocks being placed.")
.defaultValue(true)
.build()
);
private final BlockPos.Mutable bp = new BlockPos.Mutable();
private final ArrayList<BlockPos> positions = new ArrayList<>();
private final MeshBuilder mb = new MeshBuilder();
public SpawnProofer() {
super(MeteorRejectsAddon.CATEGORY, "spawn-proofer", "Spawn proofs things using slabs.");
}
@EventHandler
private void onTick(TickEvent.Post event) {
// Clear and set positions
positions.clear();
BlockIterator.register(range.get(), range.get(), (blockPos, blockState) -> {
if (validSpawn(new BlockPos(blockPos.getX(), blockPos.getY()-1, blockPos.getZ()), blockState)) positions.add(blockPos);
});
for (BlockPos blockPos : positions) {
// Set slot
int slot = findSlot();
// Place blocks
BlockUtils.place(blockPos, Hand.MAIN_HAND, slot, rotate.get(), -50, false, true, true, true);
}
}
@EventHandler
private void onRender(RenderEvent event) {
// Render all positions
for (BlockPos blockPos : positions) {
Renderer.boxWithLines(Renderer.NORMAL, Renderer.LINES, blockPos, sideColor.get(), lineColor.get(), shapeMode.get(), 0);
}
}
private int findSlot() {
return InvUtils.findItemInHotbar(itemStack -> blocks.get().contains(Block.getBlockFromItem(itemStack.getItem())));
}
private boolean validSpawn(BlockPos blockPos, BlockState blockState) {
if (blockPos.getY() == 0) return false;
if (!(blockState.getBlock() instanceof AirBlock)) return false;
bp.set(blockPos).move(0, -1, 0);
if (!topSurface(mc.world.getBlockState(bp))) {
if (mc.world.getBlockState(bp).getCollisionShape(mc.world, bp) != VoxelShapes.fullCube()) return false;
if (mc.world.getBlockState(bp).isTranslucent(mc.world, bp)) return false;
}
if (mc.world.getLightLevel(blockPos, 0) <= 7) return false;
else return mc.world.getLightLevel(LightType.BLOCK, blockPos) <= 7;
}
private boolean topSurface(BlockState blockState) {
if (blockState.getBlock() instanceof SlabBlock && blockState.get(SlabBlock.TYPE) == SlabType.TOP) return true;
else return blockState.getBlock() instanceof StairsBlock && blockState.get(StairsBlock.HALF) == BlockHalf.TOP;
}
}
private final SettingGroup sgGeneral = settings.getDefaultGroup();
private final Setting<Integer> range = sgGeneral.add(new IntSetting.Builder()
.name("range")
.description("Range for block placement and rendering")
.min(1)
.max(4)
.sliderMin(1)
.sliderMax(1)
.defaultValue(3)
.build()
);
private final Setting<List<Block>> blocks = sgGeneral.add(new BlockListSetting.Builder()
.name("blocks")
.description("Blocks to use for spawn proofing")
.defaultValue(getDefaultBlocks())
.build()
);
private final Setting<ShapeMode> shapeMode = sgGeneral.add(new EnumSetting.Builder<ShapeMode>()
.name("shape-mode")
.description("Shape mode")
.defaultValue(ShapeMode.Both)
.build()
);
private final Setting<SettingColor> sideColor = sgGeneral.add(new ColorSetting.Builder()
.name("side-color")
.description("Edge color")
.defaultValue(new SettingColor(255, 0, 0, 75))
.build()
);
private final Setting<SettingColor> lineColor = sgGeneral.add(new ColorSetting.Builder()
.name("line-color")
.description("Line color")
.defaultValue(new SettingColor(255, 0, 0, 255))
.build()
);
private final Setting<Boolean> rotate = sgGeneral.add(new BoolSetting.Builder()
.name("rotate")
.description("Rotates towards the blocks being placed.")
.defaultValue(true)
.build()
);
private final ArrayList<BlockPos> positions = new ArrayList<>();
private final MeshBuilder mb = new MeshBuilder();
public SpawnProofer() {
super(MeteorRejectsAddon.CATEGORY, "spawn-proofer", "Spawn proofs things using slabs.");
}
@EventHandler
private void onTick(TickEvent.Post event) {
// Clear and set positions
positions.clear();
for (BlockPos blockPos : WorldUtils.getSphere(mc.player.getBlockPos(), range.get(), range.get())) {
if (validSpawn(blockPos)) positions.add(blockPos);
}
for (BlockPos blockPos : positions) {
// Set slot
int slot = findSlot();
// Place blocks
BlockUtils.place(blockPos, Hand.MAIN_HAND, slot, rotate.get(), -50, true);
}
}
@EventHandler
private void onRender(RenderEvent event) {
// Render all positions
for (BlockPos blockPos : positions) {
Renderer.boxWithLines(Renderer.NORMAL, Renderer.LINES, blockPos.down(), sideColor.get(), lineColor.get(), shapeMode.get(), 0);
}
}
private int findSlot() {
return InvUtils.findItemInHotbar(itemStack -> blocks.get().contains(Block.getBlockFromItem(itemStack.getItem())));
}
private boolean validSpawn(BlockPos blockPos) {
BlockState blockState = mc.world.getBlockState(blockPos);
if (blockPos.getY() == 0) return false;
if (!(blockState.getBlock() instanceof AirBlock)) return false;
if (!topSurface(mc.world.getBlockState(blockPos.down()))) {
if (mc.world.getBlockState(blockPos.down()).getCollisionShape(mc.world, blockPos.down()) != VoxelShapes.fullCube()) return false;
if (mc.world.getBlockState(blockPos.down()).isTranslucent(mc.world, blockPos.down())) return false;
}
if (mc.world.getLightLevel(blockPos, 0) <= 7) return false;
else return mc.world.getLightLevel(LightType.BLOCK, blockPos) <= 7;
}
private boolean topSurface(BlockState blockState) {
if (blockState.getBlock() instanceof SlabBlock && blockState.get(SlabBlock.TYPE) == SlabType.TOP) return true;
else return blockState.getBlock() instanceof StairsBlock && blockState.get(StairsBlock.HALF) == BlockHalf.TOP;
}
private List<Block> getDefaultBlocks() {
List<Block> defaultBlocks = new ArrayList<>();
for (Block block : Registry.BLOCK) {
if (block instanceof SlabBlock) defaultBlocks.add(block);
if (block instanceof AbstractButtonBlock) defaultBlocks.add(block);
if (block instanceof TorchBlock) defaultBlocks.add(block);
}
return defaultBlocks;
}
}