From 33b0e468ab16fd62b9b24c635a19a3075d586509 Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Sun, 22 Nov 2020 10:31:28 +0800 Subject: [PATCH] Tweak player death for Quark compatibility --- .../common/mixin/core/entity/LivingEntityMixin.java | 12 ++++++++---- .../core/entity/player/ServerPlayerEntityMixin.java | 10 +++++++--- .../mod/server/event/EntityEventDispatcher.java | 4 +--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/LivingEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/LivingEntityMixin.java index 3c7fee69..4ba7ffb0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/LivingEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/LivingEntityMixin.java @@ -68,7 +68,6 @@ import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -1022,9 +1021,14 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt return drops == null ? livingEntity.captureDrops(value) : drops; } - @ModifyArg(method = "spawnDrops", index = 0, at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Collection;forEach(Ljava/util/function/Consumer;)V")) - private Consumer arclight$cancelEvent(Consumer consumer) { - return this instanceof ServerPlayerEntityBridge ? itemEntity -> {} : consumer; + @Redirect(method = "spawnDrops", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Collection;forEach(Ljava/util/function/Consumer;)V")) + private void arclight$cancelEvent(Collection collection, Consumer action) { + if (this instanceof ServerPlayerEntityBridge) { + // recapture for ServerPlayerEntityMixin#onDeath + this.captureDrops(collection); + } else { + collection.forEach(action); + } } @Inject(method = "canEntityBeSeen", cancellable = true, at = @At("HEAD")) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/ServerPlayerEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/ServerPlayerEntityMixin.java index 8afc296d..23fa3259 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/ServerPlayerEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/ServerPlayerEntityMixin.java @@ -119,6 +119,7 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import javax.annotation.Nullable; import java.util.ArrayList; +import java.util.Collection; import java.util.EnumSet; import java.util.List; import java.util.Optional; @@ -332,9 +333,12 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen ITextComponent defaultMessage = this.getCombatTracker().getDeathMessage(); String deathmessage = defaultMessage.getString(); List loot = new ArrayList<>(); - for (ItemEntity entity : this.captureDrops(null)) { - CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(entity.getItem()); - loot.add(craftItemStack); + Collection drops = this.captureDrops(null); + if (drops != null) { + for (ItemEntity entity : drops) { + CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(entity.getItem()); + loot.add(craftItemStack); + } } if (!keepInventory) { this.inventory.copyInventory(copyInv); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/EntityEventDispatcher.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/EntityEventDispatcher.java index 63534b66..2f7d79b2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/EntityEventDispatcher.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/EntityEventDispatcher.java @@ -23,9 +23,7 @@ public class EntityEventDispatcher { @SubscribeEvent(receiveCanceled = true) public void onLivingDeath(LivingDropsEvent event) { if (event.getEntityLiving() instanceof ServerPlayerEntity) { - // recapture for ServerPlayerEntityMixin#onDeath - event.getEntityLiving().captureDrops(event.getDrops()); - // handled at ServerPlayerEntityMixin + // handled at ServerPlayerEntityMixin#onDeath // Cancelled at io.izzel.arclight.common.mixin.core.entity.LivingEntityMixin#arclight$cancelEvent // event.setCanceled(true); return;