forked from aleksilassila/litematica-printer
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
115 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...java/me/aleksilassila/litematica/printer/v1_21/implementation/actions/AirPlaceAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package me.aleksilassila.litematica.printer.v1_21.implementation.actions; | ||
|
||
import me.aleksilassila.litematica.printer.v1_21.actions.InteractAction; | ||
import me.aleksilassila.litematica.printer.v1_21.config.PrinterConfig; | ||
import me.aleksilassila.litematica.printer.v1_21.implementation.PrinterPlacementContext; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.ClientPlayNetworkHandler; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import net.minecraft.client.network.ClientPlayerInteractionManager; | ||
import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket; | ||
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.math.Vec3d; | ||
|
||
public class AirPlaceAction extends InteractAction { | ||
private final MinecraftClient mc = MinecraftClient.getInstance(); | ||
public AirPlaceAction(PrinterPlacementContext context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
protected ActionResult interact(MinecraftClient client, ClientPlayerEntity player, Hand hand, BlockHitResult hitResult) { | ||
if (!mc.world.getBlockState(hitResult.getBlockPos().offset(hitResult.getSide())).isAir()) { | ||
if (PrinterConfig.PRINTER_DEBUG_LOG.getBooleanValue()) System.out.println("InteractActionImpl.interact: block is not air"); | ||
return ActionResult.FAIL; | ||
} | ||
if (PrinterConfig.PRINTER_DEBUG_LOG.getBooleanValue()) System.out.println("InteractActionImpl.interact: attempting to air place block"); | ||
airPlace(hitResult.getBlockPos().offset(hitResult.getSide())); | ||
return ActionResult.PASS; | ||
} | ||
|
||
private void airPlace(BlockPos pos) { | ||
ClientPlayNetworkHandler connection = mc.getNetworkHandler(); | ||
ClientPlayerInteractionManager interactionManager = mc.interactionManager; | ||
if (mc.player == null || connection == null || interactionManager == null) return; | ||
connection.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.UP)); | ||
|
||
Hand hand = Hand.OFF_HAND; | ||
|
||
BlockHitResult hit = new BlockHitResult(Vec3d.ofCenter(pos), Direction.UP, pos, true); | ||
interactionManager.interactBlock(mc.player, hand, hit); | ||
mc.player.swingHand(Hand.MAIN_HAND, false); | ||
connection.sendPacket(new HandSwingC2SPacket(hand)); | ||
connection.sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.UP)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
.../src/main/java/me/aleksilassila/litematica/printer/v1_21/mixin/MixinClientConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package me.aleksilassila.litematica.printer.v1_21.mixin; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import me.aleksilassila.litematica.printer.v1_21.LitematicaMixinMod; | ||
import me.aleksilassila.litematica.printer.v1_21.Printer; | ||
import me.aleksilassila.litematica.printer.v1_21.config.PrinterConfig; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.network.ClientConnection; | ||
import net.minecraft.network.packet.Packet; | ||
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; | ||
import net.minecraft.screen.PlayerScreenHandler; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(ClientConnection.class) | ||
public class MixinClientConnection { | ||
@Inject(method = "channelRead0*", at = @At("HEAD"), cancellable = true) | ||
private void channelReadPre(ChannelHandlerContext channelHandlerContext, Packet<?> packet, CallbackInfo callback) { | ||
if (!LitematicaMixinMod.PRINT_MODE.getBooleanValue() && !LitematicaMixinMod.PRINT.getKeybind().isPressed()) { | ||
return; | ||
} | ||
if (!PrinterConfig.PRINTER_AIRPLACE.getBooleanValue() || !PrinterConfig.PRINTER_AIRPLACE_OFFHAND_SLOT_SUPPRESS.getBooleanValue()) { | ||
return; | ||
} | ||
if (Printer.inactivityCounter > 20) { | ||
return; | ||
} | ||
if (packet instanceof ScreenHandlerSlotUpdateS2CPacket packet1) { | ||
if (packet1.getSyncId() == -2 && packet1.getSlot() == PlayerInventory.OFF_HAND_SLOT) { | ||
callback.cancel(); | ||
} else if (packet1.getSyncId() == 0 && PlayerScreenHandler.isInHotbar(packet1.getSyncId())) { | ||
if (packet1.getSlot() == PlayerScreenHandler.OFFHAND_ID) { | ||
callback.cancel(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters