From 42a0da8be8621c8b79c45d6915e9c83ab10db733 Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Sat, 5 Feb 2022 18:45:23 +0800 Subject: [PATCH] Update upstream (#470) --- .../bridge/core/entity/EntityBridge.java | 10 +++---- .../network/ServerPlayNetHandlerMixin.java | 8 +++-- .../management/ServerPlayerGameModeMixin.java | 3 +- .../mixin/core/world/ExplosionMixin.java | 30 +++++++++++++++---- .../mixin/core/world/entity/EntityMixin.java | 10 +++---- .../core/world/entity/LivingEntityMixin.java | 1 - .../core/world/entity/player/PlayerMixin.java | 1 - 7 files changed, 43 insertions(+), 20 deletions(-) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/EntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/EntityBridge.java index a79a9c34..d3afe892 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/EntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/EntityBridge.java @@ -1,13 +1,13 @@ package io.izzel.arclight.common.bridge.core.entity; import io.izzel.arclight.common.bridge.core.command.ICommandSourceBridge; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; import org.bukkit.craftbukkit.v.entity.CraftEntity; import org.bukkit.projectiles.ProjectileSource; import java.util.List; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.entity.Entity; public interface EntityBridge extends ICommandSourceBridge { @@ -35,9 +35,9 @@ public interface EntityBridge extends ICommandSourceBridge { boolean bridge$isChunkLoaded(); - boolean bridge$isForceExplosionKnockback(); + boolean bridge$isLastDamageCancelled(); - void bridge$setForceExplosionKnockback(boolean forceExplosionKnockback); + void bridge$setLastDamageCancelled(boolean cancelled); void bridge$postTick(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerPlayNetHandlerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerPlayNetHandlerMixin.java index f2b9e64e..4e7ad3d4 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerPlayNetHandlerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerPlayNetHandlerMixin.java @@ -401,9 +401,13 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } - @Inject(method = "handleSelectTrade", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/MerchantMenu;setSelectionHint(I)V")) + @Inject(method = "handleSelectTrade", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/MerchantMenu;setSelectionHint(I)V")) private void arclight$tradeSelect(ServerboundSelectTradePacket packetIn, CallbackInfo ci, int i, AbstractContainerMenu container) { - CraftEventFactory.callTradeSelectEvent(this.player, i, (MerchantMenu) container); + var event = CraftEventFactory.callTradeSelectEvent(this.player, i, (MerchantMenu) container); + if (event.isCancelled()) { + ((ServerPlayerEntityBridge) this.player).bridge$getBukkitEntity().updateInventory(); + ci.cancel(); + } } @Inject(method = "handleEditBook", at = @At("HEAD")) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/ServerPlayerGameModeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/ServerPlayerGameModeMixin.java index 132f94df..66d19b7f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/ServerPlayerGameModeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/ServerPlayerGameModeMixin.java @@ -158,7 +158,7 @@ public abstract class ServerPlayerGameModeMixin implements PlayerInteractionMana } return; } - BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, blockPos.getX(), blockPos.getY(), blockPos.getZ(), this.player.getInventory().getSelected(), f >= 1.0f); + BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, blockPos, this.player.getInventory().getSelected(), f >= 1.0f); if (blockEvent.isCancelled()) { this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, blockPos)); return; @@ -177,6 +177,7 @@ public abstract class ServerPlayerGameModeMixin implements PlayerInteractionMana int j = (int) (f * 10.0f); this.level.destroyBlockProgress(this.player.getId(), blockPos, j); this.player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, this.level.getBlockState(blockPos), action, true, "actual start of destroying")); + CraftEventFactory.callBlockDamageAbortEvent(this.player, blockPos, this.player.getInventory().getSelected()); this.lastSentState = j; } } else if (action == ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/ExplosionMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/ExplosionMixin.java index 90faac91..752c0718 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/ExplosionMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/ExplosionMixin.java @@ -16,8 +16,6 @@ import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.item.FallingBlockEntity; -import net.minecraft.world.entity.item.PrimedTnt; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.ProtectionEnchantment; @@ -34,6 +32,7 @@ import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; +import net.minecraftforge.entity.PartEntity; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.craftbukkit.v.event.CraftEventFactory; @@ -172,10 +171,31 @@ public abstract class ExplosionMixin implements ExplosionBridge { double d10 = (1.0D - d12) * d14; CraftEventFactory.entityDamage = this.source; - ((EntityBridge) entity).bridge$setForceExplosionKnockback(false); - boolean wasDamaged = entity.hurt(this.getDamageSource(), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D))); + ((EntityBridge) entity).bridge$setLastDamageCancelled(false); + + // Special case ender dragon only give knockback if no damage is cancelled + // Thinks to note: + // - Setting a velocity to a ComplexEntityPart is ignored (and therefore not needed) + // - Damaging ComplexEntityPart while forward the damage to EntityEnderDragon + // - Damaging EntityEnderDragon does nothing + // - EntityEnderDragon hitbock always covers the other parts and is therefore always present + if (entity instanceof PartEntity) { + continue; + } + + var parts = entity.getParts(); + if (parts != null) { + for (var part : parts) { + if (list.contains(part)) { + part.hurt(this.getDamageSource(), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D))); + } + } + } else { + entity.hurt(this.getDamageSource(), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D))); + } + CraftEventFactory.entityDamage = null; - if (!wasDamaged && !(entity instanceof PrimedTnt || entity instanceof FallingBlockEntity) && !((EntityBridge) entity).bridge$isForceExplosionKnockback()) { + if (((EntityBridge) entity).bridge$isLastDamageCancelled()) { continue; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java index 6455b6ed..96e8aed1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java @@ -222,7 +222,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, public boolean generation; public boolean valid; public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only - public boolean forceExplosionKnockback; // SPIGOT-949 + public boolean lastDamageCancelled; // SPIGOT-949 public boolean persistentInvisibility = false; public BlockPos lastLavaContact; public int maxAirTicks = getDefaultMaxAirSupply(); @@ -362,13 +362,13 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } @Override - public boolean bridge$isForceExplosionKnockback() { - return forceExplosionKnockback; + public boolean bridge$isLastDamageCancelled() { + return lastDamageCancelled; } @Override - public void bridge$setForceExplosionKnockback(boolean forceExplosionKnockback) { - this.forceExplosionKnockback = forceExplosionKnockback; + public void bridge$setLastDamageCancelled(boolean cancelled) { + this.lastDamageCancelled = cancelled; } public void postTick() { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java index 544ca84d..354ea786 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java @@ -534,7 +534,6 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt boolean flag1 = true; if ((float) this.invulnerableTime > 10.0F) { if (amount <= this.lastHurt) { - this.forceExplosionKnockback = true; return false; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java index d609c7c2..acacaaf2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java @@ -189,7 +189,6 @@ public abstract class PlayerMixin extends LivingEntityMixin implements PlayerEnt if (this.isInvulnerableTo(source)) { return false; } else if (this.abilities.invulnerable && !source.isBypassInvul()) { - this.forceExplosionKnockback = true; return false; } else { this.noActionTime = 0;