diff --git a/gradle.properties b/gradle.properties index 5a46db3e..875965af 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.11.3 # Mod Properties - mod_version = 0.1.0-pre7+1.17.1 + mod_version = 0.1.0-pre8+1.17.1 maven_group = eu.pb4 archives_base_name = polymer diff --git a/src/main/java/eu/pb4/polymer/item/ItemHelper.java b/src/main/java/eu/pb4/polymer/item/ItemHelper.java index a6795777..70fc965a 100644 --- a/src/main/java/eu/pb4/polymer/item/ItemHelper.java +++ b/src/main/java/eu/pb4/polymer/item/ItemHelper.java @@ -39,8 +39,7 @@ public class ItemHelper { public static final BooleanEvent VIRTUAL_ITEM_CHECK = new BooleanEvent<>(); public static ItemStack getVirtualItemStack(ItemStack itemStack, ServerPlayerEntity player) { - if (itemStack.getItem() instanceof VirtualItem) { - VirtualItem item = (VirtualItem) itemStack.getItem(); + if (itemStack.getItem() instanceof VirtualItem item) { return item.getVirtualItemStack(itemStack, player); } else if (itemStack.hasEnchantments()) { for (NbtElement enchantment : itemStack.getEnchantments()) { @@ -62,7 +61,9 @@ public static ItemStack getVirtualItemStack(ItemStack itemStack, ServerPlayerEnt return createBasicVirtualItemStack(itemStack, player); } } - } else if (VIRTUAL_ITEM_CHECK.invoke(itemStack)) { + } + + if (VIRTUAL_ITEM_CHECK.invoke(itemStack)) { return createBasicVirtualItemStack(itemStack, player); } diff --git a/src/main/java/eu/pb4/polymer/mixin/block/ServerPlayerInteractionManagerMixin.java b/src/main/java/eu/pb4/polymer/mixin/block/ServerPlayerInteractionManagerMixin.java index 81f2161f..48b04d0d 100644 --- a/src/main/java/eu/pb4/polymer/mixin/block/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/eu/pb4/polymer/mixin/block/ServerPlayerInteractionManagerMixin.java @@ -23,7 +23,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -// Modified version of PolyMC mixin - https://github.com/TheEpicBlock/PolyMc/blob/master/src/main/java/io/github/theepicblock/polymc/mixins/block/BlockBreakingPatch.java +// Part of this mixin is based on https://github.com/TheEpicBlock/PolyMc/blob/master/src/main/java/io/github/theepicblock/polymc/mixins/block/BlockBreakingPatch.java @Mixin(ServerPlayerInteractionManager.class) public abstract class ServerPlayerInteractionManagerMixin { diff --git a/src/main/java/eu/pb4/polymer/mixin/item/ServerPlayNetworkHandlerMixin.java b/src/main/java/eu/pb4/polymer/mixin/item/ServerPlayNetworkHandlerMixin.java index 1de57e04..8b4777af 100644 --- a/src/main/java/eu/pb4/polymer/mixin/item/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/eu/pb4/polymer/mixin/item/ServerPlayNetworkHandlerMixin.java @@ -3,10 +3,12 @@ import eu.pb4.polymer.item.VirtualItem; import net.minecraft.item.BlockItem; import net.minecraft.item.BucketItem; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.network.Packet; import net.minecraft.network.packet.c2s.play.ClickSlotC2SPacket; import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket; +import net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; import net.minecraft.server.network.ServerPlayNetworkHandler; @@ -34,6 +36,8 @@ public abstract class ServerPlayNetworkHandlerMixin { @Shadow public abstract void sendPacket(Packet packet); + @Shadow public abstract void onPlayerInteractItem(PlayerInteractItemC2SPacket packet); + @Inject(method = "onPlayerInteractBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/server/world/ServerWorld;)V", shift = At.Shift.AFTER)) private void resendToolIfItsBlockClientSide(PlayerInteractBlockC2SPacket packet, CallbackInfo ci) { ItemStack itemStack = this.player.getStackInHand(packet.getHand()); @@ -44,13 +48,7 @@ private void resendToolIfItsBlockClientSide(PlayerInteractBlockC2SPacket packet, } @Redirect(method = "onPlayerInteractBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 0)) - private void replaceOriginalCall1(ServerPlayNetworkHandler serverPlayNetworkHandler, Packet packet) { - } - - @Redirect(method = "onPlayerInteractBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 1)) - private void replaceOriginalCall2(ServerPlayNetworkHandler serverPlayNetworkHandler, Packet packet) { - } - + private void replaceOriginalCall(ServerPlayNetworkHandler serverPlayNetworkHandler, Packet packet) {} @Inject(method = "onPlayerInteractBlock", at = @At("TAIL")) private void updateMoreBlocks(PlayerInteractBlockC2SPacket packet, CallbackInfo ci) { @@ -59,6 +57,13 @@ private void updateMoreBlocks(PlayerInteractBlockC2SPacket packet, CallbackInfo for (Direction direction : Direction.values()) { this.player.networkHandler.sendPacket(new BlockUpdateS2CPacket(this.player.world, base.offset(direction))); } + + ItemStack stack = this.player.getStackInHand(packet.getHand()); + Item item = stack.getItem(); + + if (stack.getItem() instanceof VirtualItem && !(item instanceof BlockItem || item instanceof BucketItem)) { + this.onPlayerInteractItem(new PlayerInteractItemC2SPacket(packet.getHand())); + } } @Unique