Skip to content

Commit

Permalink
optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nxyi committed Aug 5, 2023
1 parent ab3fdd8 commit 091036d
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions src/main/java/com/dark/zewo2/modules/SignGriefer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.SignBlock;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket;
import net.minecraft.network.packet.c2s.play.UpdateSignC2SPacket;
import net.minecraft.network.packet.s2c.play.SignEditorOpenS2CPacket;
Expand All @@ -19,6 +22,10 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class SignGriefer extends Module {
private final SettingGroup sgGeneral = this.settings.getDefaultGroup();
Expand Down Expand Up @@ -61,26 +68,38 @@ public void ontick(TickEvent.Pre event) {
for (int z = -range; z <= range; z++){
BlockPos sign = mc.player.getBlockPos().add(x,y,z);
Vec3d pos = mc.player.getBlockPos().add(x,y,z).toCenterPos();
SignBlockEntity block = (SignBlockEntity) mc.world.getBlockEntity(sign);



if (issign(sign)){
Rotations.rotate(Rotations.getYaw(pos), Rotations.getPitch(pos));

if (issign(sign)){
List<String> front = getNbt(sign, "front_text");
List<String> back = getNbt(sign, "back_text");
if (mode.get().equals(sides.front)) {
mc.player.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND ,new BlockHitResult(new Vec3d(sign.getX(), sign.getY(), sign.getZ()), mc.player.getHorizontalFacing(), sign, false), 1));

mc.player.networkHandler.sendPacket(new UpdateSignC2SPacket(sign, true, isempty(line1.get()), isempty(line2.get()), isempty(line3.get()), isempty(line4.get())));
if (!front.get(0).equals(line1.get()) || !front.get(1).equals(line2.get()) || !front.get(2).equals(line3.get()) || !front.get(3).equals(line4.get())) {
mc.player.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND ,new BlockHitResult(new Vec3d(sign.getX(), sign.getY(), sign.getZ()), mc.player.getHorizontalFacing(), sign, false), 1));

mc.player.networkHandler.sendPacket(new UpdateSignC2SPacket(sign, true, isempty(line1.get()), isempty(line2.get()), isempty(line3.get()), isempty(line4.get())));
}
}
if (mode.get().equals(sides.back)) {
mc.player.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND ,new BlockHitResult(new Vec3d(sign.getX(), sign.getY(), sign.getZ()), mc.player.getHorizontalFacing(), sign, false), 1));
if (!back.get(0).equals(line1.get()) || !back.get(1).equals(line2.get()) || !back.get(2).equals(line3.get()) || !back.get(3).equals(line4.get())) {
mc.player.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND, new BlockHitResult(new Vec3d(sign.getX(), sign.getY(), sign.getZ()), mc.player.getHorizontalFacing(), sign, false), 1));

mc.player.networkHandler.sendPacket(new UpdateSignC2SPacket(sign, false, isempty(line1.get()), isempty(line2.get()), isempty(line3.get()), isempty(line4.get())));
mc.player.networkHandler.sendPacket(new UpdateSignC2SPacket(sign, false, isempty(line1.get()), isempty(line2.get()), isempty(line3.get()), isempty(line4.get())));
}
}

if (mode.get().equals(sides.both)){
mc.player.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND ,new BlockHitResult(new Vec3d(sign.getX(), sign.getY(), sign.getZ()), mc.player.getHorizontalFacing(), sign, false), 1));
mc.player.networkHandler.sendPacket(new UpdateSignC2SPacket(sign, true, isempty(line1.get()), isempty(line2.get()), isempty(line3.get()), isempty(line4.get())));
mc.player.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND ,new BlockHitResult(new Vec3d(sign.getX(), sign.getY(), sign.getZ()), mc.player.getHorizontalFacing(), sign, false), 1));
mc.player.networkHandler.sendPacket(new UpdateSignC2SPacket(sign, false, isempty(line1.get()), isempty(line2.get()), isempty(line3.get()), isempty(line4.get())));
if (!front.get(0).equals(line1.get()) || !front.get(1).equals(line2.get()) || !front.get(2).equals(line3.get()) || !front.get(3).equals(line4.get())
|| !back.get(0).equals(line1.get()) || !back.get(1).equals(line2.get()) || !back.get(2).equals(line3.get()) || !back.get(3).equals(line4.get())){
mc.player.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND ,new BlockHitResult(new Vec3d(sign.getX(), sign.getY(), sign.getZ()), mc.player.getHorizontalFacing(), sign, false), 1));
mc.player.networkHandler.sendPacket(new UpdateSignC2SPacket(sign, true, isempty(line1.get()), isempty(line2.get()), isempty(line3.get()), isempty(line4.get())));
mc.player.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND ,new BlockHitResult(new Vec3d(sign.getX(), sign.getY(), sign.getZ()), mc.player.getHorizontalFacing(), sign, false), 1));
mc.player.networkHandler.sendPacket(new UpdateSignC2SPacket(sign, false, isempty(line1.get()), isempty(line2.get()), isempty(line3.get()), isempty(line4.get())));
}
}
}
}
Expand All @@ -100,11 +119,30 @@ private String isempty(String text){
}

private boolean issign(BlockPos pos){
// i know this is a bad way, but `block InstanceOf SignBlock` wasnt working
Block block = mc.world.getBlockState(pos).getBlock();

return block.getTranslationKey().contains("_sign");
}

private List<String> getNbt(BlockPos pos, String compound) {
// get the text on the sign to see if we should edit it
List<String> elements = new ArrayList<>();
BlockEntity block = mc.world.getBlockEntity(pos);
NbtCompound targetNbt = block.createNbt().getCompound(compound);
String text1 = targetNbt.toString().split(",")[2].split("\"")[3];
String text2 = targetNbt.toString().split(",")[3].split("\"")[3];
String text3 = targetNbt.toString().split(",")[4].split("\"")[3];
String text4 = targetNbt.toString().split(",")[5].split("\"")[3];

elements.add(text1);
elements.add(text2);
elements.add(text3);
elements.add(text4);

return elements;
}

public enum sides{
front,
back,
Expand Down

0 comments on commit 091036d

Please sign in to comment.