diff options
author | Anthony Hilyard <anthony.hilyard@gmail.com> | 2021-11-02 11:20:54 -0700 |
---|---|---|
committer | Anthony Hilyard <anthony.hilyard@gmail.com> | 2021-11-02 11:20:54 -0700 |
commit | f0b99d099fdbfe372b01f40dee32d686940c210b (patch) | |
tree | 1793edde03cb55fb541bade0e49aea29a4ba1d6d /src/main/java/com/anthonyhilyard/iceberg/mixin | |
parent | 2b38fda32d059303bed929b7ae634efa4dffc706 (diff) | |
download | Iceberg-f0b99d099fdbfe372b01f40dee32d686940c210b.tar.gz Iceberg-f0b99d099fdbfe372b01f40dee32d686940c210b.tar.bz2 Iceberg-f0b99d099fdbfe372b01f40dee32d686940c210b.zip |
Consolidate item selectors. NewItemPickupEvent is now entirely
client-side.
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/mixin')
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/mixin/ClientPacketListenerMixin.java | 33 | ||||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/mixin/ForgeEventFactoryMixin.java | 31 |
2 files changed, 33 insertions, 31 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ClientPacketListenerMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ClientPacketListenerMixin.java new file mode 100644 index 0000000..bef0407 --- /dev/null +++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/ClientPacketListenerMixin.java @@ -0,0 +1,33 @@ +package com.anthonyhilyard.iceberg.mixin; + +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.network.protocol.game.ClientboundTakeItemEntityPacket; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraftforge.common.MinecraftForge; + +import com.anthonyhilyard.iceberg.events.NewItemPickupEvent; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(ClientPacketListener.class) +public class ClientPacketListenerMixin +{ + @Inject(method = "handleTakeItemEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;shrink(I)V"), + locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private void handleTakeItemEntity(ClientboundTakeItemEntityPacket packet, CallbackInfo info, Entity entity, LivingEntity livingEntity, ItemEntity itemEntity, ItemStack itemStack) + { + if (livingEntity instanceof Player) + { + MinecraftForge.EVENT_BUS.post(new NewItemPickupEvent(livingEntity.getUUID(), itemStack)); + } + } +} diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ForgeEventFactoryMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ForgeEventFactoryMixin.java deleted file mode 100644 index 2dbc247..0000000 --- a/src/main/java/com/anthonyhilyard/iceberg/mixin/ForgeEventFactoryMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.anthonyhilyard.iceberg.mixin; - -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.server.level.ServerPlayer; -import net.minecraftforge.event.ForgeEventFactory; -import net.minecraftforge.fml.loading.FMLEnvironment; -import net.minecraftforge.fmllegacy.network.PacketDistributor; - -import com.anthonyhilyard.iceberg.network.IcebergNetworkProtocol; -import com.anthonyhilyard.iceberg.network.NewItemPickupEventPacket; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -@Mixin(ForgeEventFactory.class) -public class ForgeEventFactoryMixin -{ - @Inject(method = { "onItemPickup(Lnet/minecraft/world/entity/item/ItemEntity;Lnet/minecraft/world/entity/player/Player;)I" }, - at = { @At("HEAD") }, remap = false) - private static void onItemPickup(ItemEntity entityItem, Player player, CallbackInfoReturnable<Integer> info) - { - if (player instanceof ServerPlayer && FMLEnvironment.dist.isDedicatedServer()) - { - IcebergNetworkProtocol.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer)player), new NewItemPickupEventPacket(player.getUUID(), entityItem.getItem())); - } - } -} |