aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/anthonyhilyard/iceberg/mixin
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/mixin')
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/mixin/EntityMixin.java11
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/mixin/ForgeEventFactoryMixin.java31
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/mixin/ItemEntityMixin.java28
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/mixin/PlayerAdvancementsMixin.java5
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java23
5 files changed, 44 insertions, 54 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/EntityMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/EntityMixin.java
index ba3a69e..5d02156 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/mixin/EntityMixin.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/EntityMixin.java
@@ -2,7 +2,7 @@ package com.anthonyhilyard.iceberg.mixin;
import java.util.Objects;
-import com.anthonyhilyard.iceberg.events.EntityFluidEvent;
+import com.anthonyhilyard.iceberg.events.EntityFluidEvents;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -14,18 +14,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.tags.Tag;
-import net.minecraftforge.common.MinecraftForge;
@Mixin(Entity.class)
-public class EntityMixin extends net.minecraftforge.common.capabilities.CapabilityProvider<Entity>
+public class EntityMixin
{
private Fluid previousFluidOnEyes = null;
@Shadow
protected Tag<Fluid> fluidOnEyes;
- protected EntityMixin(Class<Entity> baseClass) { super(baseClass); }
-
@Inject(method = "updateFluidOnEyes", at = @At(value = "RETURN"))
public void onUpdateFluidOnEyes(CallbackInfo callbackInfo)
{
@@ -38,7 +35,7 @@ public class EntityMixin extends net.minecraftforge.common.capabilities.Capabili
// We were submerged in a fluid that we no longer are.
if (previousFluidOnEyes != null)
{
- MinecraftForge.EVENT_BUS.post(new EntityFluidEvent.Exited((Entity)(Object)this, previousFluidOnEyes));
+ EntityFluidEvents.EXITED.invoker().onExited((Entity)(Object)this, previousFluidOnEyes);
}
previousFluidOnEyes = null;
}
@@ -59,7 +56,7 @@ public class EntityMixin extends net.minecraftforge.common.capabilities.Capabili
// We are now submerged in a fluid that doesn't match the previous one.
if (currentFluid != null)
{
- MinecraftForge.EVENT_BUS.post(new EntityFluidEvent.Entered((Entity)(Object)this, currentFluid));
+ EntityFluidEvents.ENTERED.invoker().onEntered((Entity)(Object)this, currentFluid);
}
}
}
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()));
- }
- }
-}
diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ItemEntityMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ItemEntityMixin.java
new file mode 100644
index 0000000..05540c9
--- /dev/null
+++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/ItemEntityMixin.java
@@ -0,0 +1,28 @@
+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/PlayerAdvancementsMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/PlayerAdvancementsMixin.java
index ad52b94..568036e 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/mixin/PlayerAdvancementsMixin.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/PlayerAdvancementsMixin.java
@@ -1,6 +1,6 @@
package com.anthonyhilyard.iceberg.mixin;
-import com.anthonyhilyard.iceberg.events.CriterionEvent;
+import com.anthonyhilyard.iceberg.events.CriterionCallback;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -12,7 +12,6 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import net.minecraft.advancements.Advancement;
import net.minecraft.server.PlayerAdvancements;
import net.minecraft.server.level.ServerPlayer;
-import net.minecraftforge.common.MinecraftForge;
@Mixin(PlayerAdvancements.class)
public class PlayerAdvancementsMixin
@@ -25,7 +24,7 @@ public class PlayerAdvancementsMixin
{
if (success)
{
- MinecraftForge.EVENT_BUS.post(new CriterionEvent(player, advancement, criterionKey));
+ CriterionCallback.EVENT.invoker().awardCriterion(player, advancement, criterionKey);
}
}
}
diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java
index bbd2d6b..225499f 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java
@@ -2,7 +2,7 @@ package com.anthonyhilyard.iceberg.mixin;
import java.util.List;
-import com.anthonyhilyard.iceberg.util.StringRecomposer;
+import com.anthonyhilyard.iceberg.events.RenderTooltipEvents;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.vertex.PoseStack;
@@ -19,11 +19,10 @@ import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.events.AbstractContainerEventHandler;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
+import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
-import net.minecraftforge.client.ForgeHooksClient;
-import net.minecraftforge.client.event.RenderTooltipEvent;
-import net.minecraftforge.common.MinecraftForge;
@Mixin(Screen.class)
public class ScreenMixin extends AbstractContainerEventHandler
@@ -31,25 +30,23 @@ public class ScreenMixin extends AbstractContainerEventHandler
@Shadow
protected Font font = null;
- @Shadow(remap = false)
- private Font tooltipFont = null;
-
- @Shadow(remap = false)
- private ItemStack tooltipStack = ItemStack.EMPTY;
-
@Final
@Shadow
private final List<GuiEventListener> children = Lists.newArrayList();
- @SuppressWarnings("removal")
+ @SuppressWarnings("unchecked")
@Inject(method = "renderTooltipInternal",
at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/entity/ItemRenderer;blitOffset:F", ordinal = 2, shift = Shift.AFTER),
locals = LocalCapture.CAPTURE_FAILEXCEPTION)
- private void renderTooltipInternal(PoseStack poseStack, List<ClientTooltipComponent> components, int x, int y, CallbackInfo info, RenderTooltipEvent.Pre pre, int tooltipWidth, int tooltipHeight, int postX, int postY)
+ private void renderTooltipInternal(PoseStack poseStack, List<ClientTooltipComponent> components, int x, int y, CallbackInfo info, int tooltipWidth, int tooltipHeight, int postX, int postY)
{
if (!components.isEmpty())
{
- MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(tooltipStack, StringRecomposer.recompose(components), poseStack, postX, postY, ForgeHooksClient.getTooltipFont(tooltipFont, tooltipStack, font), tooltipWidth, tooltipHeight));
+ if ((Screen)(Object)this instanceof AbstractContainerScreen)
+ {
+ ItemStack tooltipStack = ((AbstractContainerScreen<AbstractContainerMenu>)(Object)this).hoveredSlot.getItem();
+ RenderTooltipEvents.POST.invoker().onPost(tooltipStack, components, poseStack, x, y, font, tooltipWidth, tooltipHeight, false);
+ }
}
}