Port fix for #55 #60 from 1.15

This commit is contained in:
IzzelAliz 2020-10-08 13:59:39 +08:00
parent f9499a729a
commit 345f4669d3
3 changed files with 21 additions and 1 deletions

View File

@ -68,6 +68,7 @@ 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;
@ -83,6 +84,7 @@ import java.util.Optional;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer;
@SuppressWarnings({"ConstantConditions", "Guava"}) @SuppressWarnings({"ConstantConditions", "Guava"})
@Mixin(LivingEntity.class) @Mixin(LivingEntity.class)
@ -679,6 +681,7 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt
final boolean human = (Object) this instanceof PlayerEntity; final boolean human = (Object) this instanceof PlayerEntity;
f = net.minecraftforge.common.ForgeHooks.onLivingHurt((LivingEntity) (Object) this, damagesource, f); f = net.minecraftforge.common.ForgeHooks.onLivingHurt((LivingEntity) (Object) this, damagesource, f);
if (f <= 0) return true;
float originalDamage = f; float originalDamage = f;
Function<Double, Double> hardHat = f12 -> { Function<Double, Double> hardHat = f12 -> {
@ -1019,6 +1022,11 @@ 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"))
private Consumer<ItemEntity> arclight$cancelEvent(Consumer<ItemEntity> consumer) {
return this instanceof ServerPlayerEntityBridge ? itemEntity -> {} : consumer;
}
@Inject(method = "canEntityBeSeen", cancellable = true, at = @At("HEAD")) @Inject(method = "canEntityBeSeen", cancellable = true, at = @At("HEAD"))
private void arclight$seeNoEvil(Entity entityIn, CallbackInfoReturnable<Boolean> cir) { private void arclight$seeNoEvil(Entity entityIn, CallbackInfoReturnable<Boolean> cir) {
if (this.world != entityIn.world) { if (this.world != entityIn.world) {

View File

@ -20,6 +20,7 @@ import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.monster.MonsterEntity; import net.minecraft.entity.monster.MonsterEntity;
import net.minecraft.entity.passive.horse.AbstractHorseEntity; import net.minecraft.entity.passive.horse.AbstractHorseEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.player.SpawnLocationHelper; import net.minecraft.entity.player.SpawnLocationHelper;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
@ -319,6 +320,13 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen
return; return;
} }
boolean keepInventory = this.world.getGameRules().getBoolean(GameRules.KEEP_INVENTORY) || this.isSpectator(); 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); this.spawnDrops(damagesource);
ITextComponent defaultMessage = this.getCombatTracker().getDeathMessage(); ITextComponent defaultMessage = this.getCombatTracker().getDeathMessage();
@ -328,6 +336,9 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen
CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(entity.getItem()); CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(entity.getItem());
loot.add(craftItemStack); loot.add(craftItemStack);
} }
if (!keepInventory) {
this.inventory.copyInventory(copyInv);
}
PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent((ServerPlayerEntity) (Object) this, loot, deathmessage, keepInventory); PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent((ServerPlayerEntity) (Object) this, loot, deathmessage, keepInventory);
if (this.openContainer != this.container) { if (this.openContainer != this.container) {
this.closeScreen(); this.closeScreen();

View File

@ -26,7 +26,8 @@ public class EntityEventDispatcher {
// recapture for ServerPlayerEntityMixin#onDeath // recapture for ServerPlayerEntityMixin#onDeath
event.getEntityLiving().captureDrops(event.getDrops()); event.getEntityLiving().captureDrops(event.getDrops());
// handled at ServerPlayerEntityMixin // handled at ServerPlayerEntityMixin
event.setCanceled(true); // Cancelled at io.izzel.arclight.common.mixin.core.entity.LivingEntityMixin#arclight$cancelEvent
// event.setCanceled(true);
return; return;
} }
LivingEntity livingEntity = event.getEntityLiving(); LivingEntity livingEntity = event.getEntityLiving();