1010import net .minecraft .block .Block ;
1111import net .minecraft .block .Blocks ;
1212import net .minecraft .block .SignBlock ;
13+ import net .minecraft .block .entity .BlockEntity ;
14+ import net .minecraft .block .entity .SignBlockEntity ;
15+ import net .minecraft .nbt .NbtCompound ;
1316import net .minecraft .network .packet .c2s .play .PlayerInteractBlockC2SPacket ;
1417import net .minecraft .network .packet .c2s .play .UpdateSignC2SPacket ;
1518import net .minecraft .network .packet .s2c .play .SignEditorOpenS2CPacket ;
1922import net .minecraft .util .math .BlockPos ;
2023import net .minecraft .util .math .Direction ;
2124import net .minecraft .util .math .Vec3d ;
25+ import org .apache .commons .lang3 .StringUtils ;
26+
27+ import java .util .ArrayList ;
28+ import java .util .List ;
2229
2330public class SignGriefer extends Module {
2431 private final SettingGroup sgGeneral = this .settings .getDefaultGroup ();
@@ -61,26 +68,38 @@ public void ontick(TickEvent.Pre event) {
6168 for (int z = -range ; z <= range ; z ++){
6269 BlockPos sign = mc .player .getBlockPos ().add (x ,y ,z );
6370 Vec3d pos = mc .player .getBlockPos ().add (x ,y ,z ).toCenterPos ();
71+ SignBlockEntity block = (SignBlockEntity ) mc .world .getBlockEntity (sign );
72+
73+
6474
65- if (issign (sign )){
66- Rotations .rotate (Rotations .getYaw (pos ), Rotations .getPitch (pos ));
6775
76+ if (issign (sign )){
77+ List <String > front = getNbt (sign , "front_text" );
78+ List <String > back = getNbt (sign , "back_text" );
6879 if (mode .get ().equals (sides .front )) {
69- 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 ));
7080
71- mc .player .networkHandler .sendPacket (new UpdateSignC2SPacket (sign , true , isempty (line1 .get ()), isempty (line2 .get ()), isempty (line3 .get ()), isempty (line4 .get ())));
81+ 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 ())) {
82+ 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 ));
83+
84+ mc .player .networkHandler .sendPacket (new UpdateSignC2SPacket (sign , true , isempty (line1 .get ()), isempty (line2 .get ()), isempty (line3 .get ()), isempty (line4 .get ())));
85+ }
7286 }
7387 if (mode .get ().equals (sides .back )) {
74- 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 ));
88+ 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 ())) {
89+ 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 ));
7590
76- mc .player .networkHandler .sendPacket (new UpdateSignC2SPacket (sign , false , isempty (line1 .get ()), isempty (line2 .get ()), isempty (line3 .get ()), isempty (line4 .get ())));
91+ mc .player .networkHandler .sendPacket (new UpdateSignC2SPacket (sign , false , isempty (line1 .get ()), isempty (line2 .get ()), isempty (line3 .get ()), isempty (line4 .get ())));
92+ }
7793 }
7894
7995 if (mode .get ().equals (sides .both )){
80- 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 ));
81- mc .player .networkHandler .sendPacket (new UpdateSignC2SPacket (sign , true , isempty (line1 .get ()), isempty (line2 .get ()), isempty (line3 .get ()), isempty (line4 .get ())));
82- 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 ));
83- mc .player .networkHandler .sendPacket (new UpdateSignC2SPacket (sign , false , isempty (line1 .get ()), isempty (line2 .get ()), isempty (line3 .get ()), isempty (line4 .get ())));
96+ 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 ())
97+ || !back .get (0 ).equals (line1 .get ()) || !back .get (1 ).equals (line2 .get ()) || !back .get (2 ).equals (line3 .get ()) || !back .get (3 ).equals (line4 .get ())){
98+ 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 ));
99+ mc .player .networkHandler .sendPacket (new UpdateSignC2SPacket (sign , true , isempty (line1 .get ()), isempty (line2 .get ()), isempty (line3 .get ()), isempty (line4 .get ())));
100+ 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 ));
101+ mc .player .networkHandler .sendPacket (new UpdateSignC2SPacket (sign , false , isempty (line1 .get ()), isempty (line2 .get ()), isempty (line3 .get ()), isempty (line4 .get ())));
102+ }
84103 }
85104 }
86105 }
@@ -100,11 +119,30 @@ private String isempty(String text){
100119 }
101120
102121 private boolean issign (BlockPos pos ){
122+ // i know this is a bad way, but `block InstanceOf SignBlock` wasnt working
103123 Block block = mc .world .getBlockState (pos ).getBlock ();
104124
105125 return block .getTranslationKey ().contains ("_sign" );
106126 }
107127
128+ private List <String > getNbt (BlockPos pos , String compound ) {
129+ // get the text on the sign to see if we should edit it
130+ List <String > elements = new ArrayList <>();
131+ BlockEntity block = mc .world .getBlockEntity (pos );
132+ NbtCompound targetNbt = block .createNbt ().getCompound (compound );
133+ String text1 = targetNbt .toString ().split ("," )[2 ].split ("\" " )[3 ];
134+ String text2 = targetNbt .toString ().split ("," )[3 ].split ("\" " )[3 ];
135+ String text3 = targetNbt .toString ().split ("," )[4 ].split ("\" " )[3 ];
136+ String text4 = targetNbt .toString ().split ("," )[5 ].split ("\" " )[3 ];
137+
138+ elements .add (text1 );
139+ elements .add (text2 );
140+ elements .add (text3 );
141+ elements .add (text4 );
142+
143+ return elements ;
144+ }
145+
108146 public enum sides {
109147 front ,
110148 back ,
0 commit comments