From 345f4669d32cb98164f231497f11811ae8a15699 Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Thu, 8 Oct 2020 13:59:39 +0800 Subject: [PATCH] Port fix for #55 #60 from 1.15 --- .../common/mixin/core/entity/LivingEntityMixin.java | 8 ++++++++ .../core/entity/player/ServerPlayerEntityMixin.java | 11 +++++++++++ .../mod/server/event/EntityEventDispatcher.java | 3 ++- 3 files changed, 21 insertions(+), 1 deletion(-) 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 ccc3d26a..5d942648 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,6 +68,7 @@ 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; @@ -83,6 +84,7 @@ import java.util.Optional; import java.util.Random; import java.util.Set; import java.util.UUID; +import java.util.function.Consumer; @SuppressWarnings({"ConstantConditions", "Guava"}) @Mixin(LivingEntity.class) @@ -679,6 +681,7 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt final boolean human = (Object) this instanceof PlayerEntity; f = net.minecraftforge.common.ForgeHooks.onLivingHurt((LivingEntity) (Object) this, damagesource, f); + if (f <= 0) return true; float originalDamage = f; Function hardHat = f12 -> { @@ -1019,6 +1022,11 @@ 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; + } + @Inject(method = "canEntityBeSeen", cancellable = true, at = @At("HEAD")) private void arclight$seeNoEvil(Entity entityIn, CallbackInfoReturnable cir) { if (this.world != entityIn.world) { 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 718b2945..9a945754 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 @@ -20,6 +20,7 @@ import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.monster.MonsterEntity; import net.minecraft.entity.passive.horse.AbstractHorseEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.SpawnLocationHelper; import net.minecraft.inventory.IInventory; @@ -319,6 +320,13 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen return; } boolean keepInventory = this.world.getGameRules().getBoolean(GameRules.KEEP_INVENTORY) || this.isSpectator(); + PlayerInventory copyInv; + if (keepInventory) { + copyInv = this.inventory; + } else { + copyInv = new PlayerInventory((ServerPlayerEntity) (Object) this); + copyInv.copyInventory(this.inventory); + } this.spawnDrops(damagesource); ITextComponent defaultMessage = this.getCombatTracker().getDeathMessage(); @@ -328,6 +336,9 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(entity.getItem()); loot.add(craftItemStack); } + if (!keepInventory) { + this.inventory.copyInventory(copyInv); + } PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent((ServerPlayerEntity) (Object) this, loot, deathmessage, keepInventory); if (this.openContainer != this.container) { this.closeScreen(); 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 914017f0..63534b66 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 @@ -26,7 +26,8 @@ public class EntityEventDispatcher { // recapture for ServerPlayerEntityMixin#onDeath event.getEntityLiving().captureDrops(event.getDrops()); // handled at ServerPlayerEntityMixin - event.setCanceled(true); + // Cancelled at io.izzel.arclight.common.mixin.core.entity.LivingEntityMixin#arclight$cancelEvent + // event.setCanceled(true); return; } LivingEntity livingEntity = event.getEntityLiving();