66import dev .dfonline .codeclient .dev .NoClip ;
77import dev .dfonline .codeclient .location .Dev ;
88import net .minecraft .client .network .ClientPlayNetworkHandler ;
9+ import net .minecraft .client .network .ClientPlayerEntity ;
910import net .minecraft .client .network .ClientPlayerInteractionManager ;
1011import net .minecraft .entity .player .PlayerEntity ;
12+ import net .minecraft .item .ItemStack ;
13+ import net .minecraft .item .Items ;
14+ import net .minecraft .nbt .NbtElement ;
1115import net .minecraft .network .packet .Packet ;
16+ import net .minecraft .network .packet .c2s .play .CreativeInventoryActionC2SPacket ;
1217import net .minecraft .screen .ScreenHandler ;
1318import net .minecraft .screen .slot .SlotActionType ;
19+ import net .minecraft .util .ActionResult ;
20+ import net .minecraft .util .Hand ;
1421import net .minecraft .util .hit .BlockHitResult ;
1522import net .minecraft .util .math .BlockPos ;
1623import org .spongepowered .asm .mixin .Mixin ;
2330
2431@ Mixin (ClientPlayerInteractionManager .class )
2532public abstract class MClientPlayerInteractionManager {
33+ private static ItemStack item = null ;
34+
2635 @ Inject (method = "breakBlock" , at = @ At ("HEAD" ), cancellable = true )
2736 public void onAttackBlock (BlockPos pos , CallbackInfoReturnable <Boolean > cir ) {
2837 if (InteractionManager .onBreakBlock (pos )) cir .setReturnValue (false );
@@ -35,6 +44,26 @@ private BlockHitResult onBlockInteract(BlockHitResult hitResult) {
3544 }
3645 return hitResult ;
3746 }
47+
48+ @ Inject (method = "interactBlock" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;sendSequencedPacket(Lnet/minecraft/client/world/ClientWorld;Lnet/minecraft/client/network/SequencedPacketCreator;)V" ))
49+ public void beforeSendPlace (ClientPlayerEntity player , Hand hand , BlockHitResult hitResult , CallbackInfoReturnable <ActionResult > cir ) {
50+ ItemStack handItem = player .getStackInHand (hand );
51+ boolean isTemplate = handItem .hasNbt () && handItem .getNbt () != null && handItem .getNbt ().contains ("PublicBukkitValues" , NbtElement .COMPOUND_TYPE ) && handItem .getNbt ().getCompound ("PublicBukkitValues" ).contains ("hypercube:codetemplatedata" , NbtElement .STRING_TYPE );
52+ if (!isTemplate ) return ;
53+ ItemStack template = Items .ENDER_CHEST .getDefaultStack ();
54+ template .setNbt (handItem .getNbt ());
55+ CodeClient .MC .getNetworkHandler ().sendPacket (new CreativeInventoryActionC2SPacket (36 + player .getInventory ().selectedSlot , template ));
56+ item = handItem ;
57+ }
58+
59+ @ Inject (method = "interactBlock" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;sendSequencedPacket(Lnet/minecraft/client/world/ClientWorld;Lnet/minecraft/client/network/SequencedPacketCreator;)V" , shift = At .Shift .AFTER ))
60+ public void afterSendPlace (ClientPlayerEntity player , Hand hand , BlockHitResult hitResult , CallbackInfoReturnable <ActionResult > cir ) {
61+ if (item != null ) {
62+ CodeClient .MC .getNetworkHandler ().sendPacket (new CreativeInventoryActionC2SPacket (36 + player .getInventory ().selectedSlot , item ));
63+ item = null ;
64+ }
65+ }
66+
3867 @ Redirect (method = "interactItem" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V" ))
3968 public void interactItemMovement (ClientPlayNetworkHandler instance , Packet <?> packet ) {
4069 if (!NoClip .isIgnoringWalls ()) {
0 commit comments