Tweak player death for Quark compatibility

This commit is contained in:
IzzelAliz 2020-11-22 10:31:28 +08:00
parent 3af14dee6e
commit 33b0e468ab
3 changed files with 16 additions and 10 deletions

View File

@ -68,7 +68,6 @@ import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; 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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 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; 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")) @Redirect(method = "spawnDrops", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Collection;forEach(Ljava/util/function/Consumer;)V"))
private Consumer<ItemEntity> arclight$cancelEvent(Consumer<ItemEntity> consumer) { private void arclight$cancelEvent(Collection<ItemEntity> collection, Consumer<ItemEntity> action) {
return this instanceof ServerPlayerEntityBridge ? itemEntity -> {} : consumer; if (this instanceof ServerPlayerEntityBridge) {
// recapture for ServerPlayerEntityMixin#onDeath
this.captureDrops(collection);
} else {
collection.forEach(action);
}
} }
@Inject(method = "canEntityBeSeen", cancellable = true, at = @At("HEAD")) @Inject(method = "canEntityBeSeen", cancellable = true, at = @At("HEAD"))

View File

@ -119,6 +119,7 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -332,9 +333,12 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen
ITextComponent defaultMessage = this.getCombatTracker().getDeathMessage(); ITextComponent defaultMessage = this.getCombatTracker().getDeathMessage();
String deathmessage = defaultMessage.getString(); String deathmessage = defaultMessage.getString();
List<org.bukkit.inventory.ItemStack> loot = new ArrayList<>(); List<org.bukkit.inventory.ItemStack> loot = new ArrayList<>();
for (ItemEntity entity : this.captureDrops(null)) { Collection<ItemEntity> drops = this.captureDrops(null);
CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(entity.getItem()); if (drops != null) {
loot.add(craftItemStack); for (ItemEntity entity : drops) {
CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(entity.getItem());
loot.add(craftItemStack);
}
} }
if (!keepInventory) { if (!keepInventory) {
this.inventory.copyInventory(copyInv); this.inventory.copyInventory(copyInv);

View File

@ -23,9 +23,7 @@ public class EntityEventDispatcher {
@SubscribeEvent(receiveCanceled = true) @SubscribeEvent(receiveCanceled = true)
public void onLivingDeath(LivingDropsEvent event) { public void onLivingDeath(LivingDropsEvent event) {
if (event.getEntityLiving() instanceof ServerPlayerEntity) { if (event.getEntityLiving() instanceof ServerPlayerEntity) {
// recapture for ServerPlayerEntityMixin#onDeath // handled at ServerPlayerEntityMixin#onDeath
event.getEntityLiving().captureDrops(event.getDrops());
// handled at ServerPlayerEntityMixin
// Cancelled at io.izzel.arclight.common.mixin.core.entity.LivingEntityMixin#arclight$cancelEvent // Cancelled at io.izzel.arclight.common.mixin.core.entity.LivingEntityMixin#arclight$cancelEvent
// event.setCanceled(true); // event.setCanceled(true);
return; return;