diff options
Diffstat (limited to 'src/main')
9 files changed, 96 insertions, 59 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java b/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java index 6361d20..5e63b2d 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java +++ b/src/main/java/com/anthonyhilyard/iceberg/IcebergClient.java @@ -1,5 +1,7 @@ package com.anthonyhilyard.iceberg; +import com.anthonyhilyard.iceberg.network.IcebergNetworkProtocol; + import net.fabricmc.api.ClientModInitializer; public class IcebergClient implements ClientModInitializer @@ -7,6 +9,6 @@ public class IcebergClient implements ClientModInitializer @Override public void onInitializeClient() { - + IcebergNetworkProtocol.registerHandlers(); } } 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..61353ec --- /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.client.multiplayer.ClientPacketListener; +import net.minecraft.network.protocol.game.ClientboundTakeItemEntityPacket; + +import com.anthonyhilyard.iceberg.events.NewItemPickupCallback; + +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 clientboundTakeItemEntityPacket, CallbackInfo info, Entity entity, LivingEntity livingEntity) + { + if (livingEntity instanceof Player) + { + Player player = (Player)livingEntity; + ItemEntity itemEntity = (ItemEntity)entity; + NewItemPickupCallback.EVENT.invoker().onItemPickup(player.getUUID(), itemEntity.getItem()); + } + } +} diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ItemEntityMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ItemEntityMixin.java deleted file mode 100644 index 05540c9..0000000 --- a/src/main/java/com/anthonyhilyard/iceberg/mixin/ItemEntityMixin.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.anthonyhilyard.iceberg.mixin; - -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.At.Shift; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.server.level.ServerPlayer; - -import com.anthonyhilyard.iceberg.network.IcebergNetworkProtocol; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -@Mixin(ItemEntity.class) -public class ItemEntityMixin -{ - @Inject(method = { "playerTouch" }, - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;take(Lnet/minecraft/world/entity/Entity;I)V", ordinal = 0, shift = Shift.AFTER)) - private void onPlayerTouch(Player player, CallbackInfo info) - { - if (player instanceof ServerPlayer) - { - IcebergNetworkProtocol.sendItemPickupEvent((ServerPlayer)player, ((ItemEntity)(Object)this).getItem()); - } - } -} diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/LivingEntityMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/LivingEntityMixin.java new file mode 100644 index 0000000..d01df84 --- /dev/null +++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/LivingEntityMixin.java @@ -0,0 +1,28 @@ +package com.anthonyhilyard.iceberg.mixin; + +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; + +import com.anthonyhilyard.iceberg.Loader; +import com.anthonyhilyard.iceberg.events.NewItemPickupCallback; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(LivingEntity.class) +public class LivingEntityMixin +{ + @Inject(method = { "onItemPickup" }, at = @At(value = "HEAD")) + private void onItemPickup(ItemEntity itemEntity, CallbackInfo info) + { + if ((LivingEntity)(Object)this instanceof Player) + { + Player player = (Player)(Object)this; + NewItemPickupCallback.EVENT.invoker().onItemPickup(player.getUUID(), itemEntity.getItem()); + } + } +} diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java index fdd3c9d..fd2abc0 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java +++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java @@ -6,7 +6,6 @@ import com.anthonyhilyard.iceberg.events.RenderTooltipEvents; import com.google.common.collect.Lists; import com.mojang.blaze3d.vertex.PoseStack; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -30,7 +29,6 @@ public class ScreenMixin extends AbstractContainerEventHandler @Shadow protected Font font = null; - @Final @Shadow private final List<GuiEventListener> children = Lists.newArrayList(); diff --git a/src/main/java/com/anthonyhilyard/iceberg/network/IcebergNetworkProtocol.java b/src/main/java/com/anthonyhilyard/iceberg/network/IcebergNetworkProtocol.java index 232ed7b..d82d0e5 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/network/IcebergNetworkProtocol.java +++ b/src/main/java/com/anthonyhilyard/iceberg/network/IcebergNetworkProtocol.java @@ -1,41 +1,28 @@ package com.anthonyhilyard.iceberg.network; import com.anthonyhilyard.iceberg.Loader; +import com.anthonyhilyard.iceberg.events.NewItemPickupCallback; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.item.ItemStack; -// import net.minecraftforge.fmllegacy.network.NetworkRegistry; -// import net.minecraftforge.fmllegacy.network.simple.SimpleChannel; public final class IcebergNetworkProtocol { - //private static final String NETWORK_PROTOCOL_VERSION = "1"; - private static final ResourceLocation IDENTIFIER = new ResourceLocation(Loader.MODID, "main"); - - // public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( - // new ResourceLocation(Loader.MODID, "main"), () -> NETWORK_PROTOCOL_VERSION, - // NETWORK_PROTOCOL_VERSION::equals, NETWORK_PROTOCOL_VERSION::equals - // ); - - // public static final void register() - // { - // int messageID = 0; - - // CHANNEL.registerMessage( - // messageID++, - // NewItemPickupEventPacket.class, - // NewItemPickupEventPacket::encode, - // NewItemPickupEventPacket::decode, - // NewItemPickupEventPacket::handle - // ); - // } + private static final String VERSION = "v1"; + private static final ResourceLocation SEND_ITEM_ID = new ResourceLocation(Loader.MODID, VERSION + '/' + String.valueOf(0)); + public static void sendItemPickupEvent(ServerPlayer player, ItemStack item) { + Loader.LOGGER.info("Sending item pickup event message!"); if (!player.level.isClientSide) { // Build buffer. @@ -44,7 +31,20 @@ public final class IcebergNetworkProtocol buffer.writeItem(item); // Send packet. - ServerPlayNetworking.send(player, IDENTIFIER, buffer); + ServerPlayNetworking.send(player, SEND_ITEM_ID, buffer); } } + + public static void handleItemPickupEvent(Minecraft client, ClientPacketListener handler, FriendlyByteBuf buf, PacketSender responseSender) + { + Loader.LOGGER.info("receiving item pickup event message!"); + client.execute(() -> { + NewItemPickupCallback.EVENT.invoker().onItemPickup(buf.readUUID(), buf.readItem()); + }); + } + + public static void registerHandlers() + { + ClientPlayNetworking.registerGlobalReceiver(SEND_ITEM_ID, IcebergNetworkProtocol::handleItemPickupEvent); + } } diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java b/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java index 9e7842f..de61b54 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java +++ b/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java @@ -21,6 +21,7 @@ public class GuiHelper Tesselator tessellator = Tesselator.getInstance(); BufferBuilder bufferBuilder = tessellator.getBuilder(); + bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); drawGradientRect(mat, bufferBuilder, left, top, right, bottom, zLevel, startColor, endColor); bufferBuilder.end(); BufferUploader.end(bufferBuilder); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index e365eea..13b9f03 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -17,7 +17,11 @@ "environment": "*", - "entrypoints": { }, + "entrypoints": { + "client": [ + "com.anthonyhilyard.iceberg.IcebergClient" + ] + }, "accessWidener": "iceberg.accesswidener", "mixins": [ "iceberg.mixins.json" diff --git a/src/main/resources/iceberg.mixins.json b/src/main/resources/iceberg.mixins.json index 25c3dd8..b5d3ac3 100644 --- a/src/main/resources/iceberg.mixins.json +++ b/src/main/resources/iceberg.mixins.json @@ -6,11 +6,10 @@ "EntityMixin", "PlayerAdvancementsMixin" ], - "server": [ - "ItemEntityMixin" - ], "client": [ - "ScreenMixin" + "ScreenMixin", + "ClientPacketListenerMixin", + "LivingEntityMixin" ], "injectors": { "defaultRequire": 1 |