Fix parrot hurtServer call, revert a bunch of comments

This commit is contained in:
Nassim Jahnke 2024-12-15 14:59:04 +01:00
parent b69631ba21
commit eec5ec406e
No known key found for this signature in database
GPG key ID: EF6771C01F6EF02F
7 changed files with 39 additions and 37 deletions

View file

@ -29,16 +29,18 @@
} }
@Override @Override
@@ -387,10 +_,11 @@ @@ -389,8 +_,13 @@
@Override
public boolean hurtServer(ServerLevel level, DamageSource damageSource, float amount) {
if (this.isInvulnerableTo(level, damageSource)) { if (this.isInvulnerableTo(level, damageSource)) {
+ if (!super.hurtServer(level, damageSource, amount)) return false; // CraftBukkit
return false; return false;
} else { } else {
+ // CraftBukkit start
+ if (!super.hurtServer(level, damageSource, amount)) {
+ return false;
+ }
this.setOrderedToSit(false); this.setOrderedToSit(false);
- return super.hurtServer(level, damageSource, amount); - return super.hurtServer(level, damageSource, amount);
+ return true; // CraftBukkit + return true;
+ // CraftBukkit
} }
} }

View file

@ -59,7 +59,7 @@
+ int eggCount = this.turtle.random.nextInt(4) + 1; + int eggCount = this.turtle.random.nextInt(4) + 1;
+ com.destroystokyo.paper.event.entity.TurtleLayEggEvent layEggEvent = new com.destroystokyo.paper.event.entity.TurtleLayEggEvent((org.bukkit.entity.Turtle) this.turtle.getBukkitEntity(), io.papermc.paper.util.MCUtil.toLocation(this.turtle.level(), this.blockPos.above()), eggCount); + com.destroystokyo.paper.event.entity.TurtleLayEggEvent layEggEvent = new com.destroystokyo.paper.event.entity.TurtleLayEggEvent((org.bukkit.entity.Turtle) this.turtle.getBukkitEntity(), io.papermc.paper.util.MCUtil.toLocation(this.turtle.level(), this.blockPos.above()), eggCount);
+ if (layEggEvent.callEvent() && org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.turtle, this.blockPos.above(), Blocks.TURTLE_EGG.defaultBlockState().setValue(TurtleEggBlock.EGGS, layEggEvent.getEggCount()))) { + if (layEggEvent.callEvent() && org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(this.turtle, this.blockPos.above(), Blocks.TURTLE_EGG.defaultBlockState().setValue(TurtleEggBlock.EGGS, layEggEvent.getEggCount()))) {
+ // Paper end + // Paper end - Turtle API
Level level = this.turtle.level(); Level level = this.turtle.level();
level.playSound(null, blockPos, SoundEvents.TURTLE_LAY_EGG, SoundSource.BLOCKS, 0.3F, 0.9F + level.random.nextFloat() * 0.2F); level.playSound(null, blockPos, SoundEvents.TURTLE_LAY_EGG, SoundSource.BLOCKS, 0.3F, 0.9F + level.random.nextFloat() * 0.2F);
BlockPos blockPos1 = this.blockPos.above(); BlockPos blockPos1 = this.blockPos.above();
@ -69,7 +69,7 @@
+ .setValue(TurtleEggBlock.EGGS, layEggEvent.getEggCount()); // Paper + .setValue(TurtleEggBlock.EGGS, layEggEvent.getEggCount()); // Paper
level.setBlock(blockPos1, blockState, 3); level.setBlock(blockPos1, blockState, 3);
level.gameEvent(GameEvent.BLOCK_PLACE, blockPos1, GameEvent.Context.of(this.turtle, blockState)); level.gameEvent(GameEvent.BLOCK_PLACE, blockPos1, GameEvent.Context.of(this.turtle, blockState));
+ } // Paper + } // CraftBukkit
this.turtle.setHasEgg(false); this.turtle.setHasEgg(false);
this.turtle.setLayingEgg(false); this.turtle.setLayingEgg(false);
this.turtle.setInLoveTime(600); this.turtle.setInLoveTime(600);

View file

@ -7,7 +7,7 @@
+ if (!super.hurtServer(level, damageSource, amount)) return false; // CraftBukkit + if (!super.hurtServer(level, damageSource, amount)) return false; // CraftBukkit
this.setOrderedToSit(false); this.setOrderedToSit(false);
- return super.hurtServer(level, damageSource, amount); - return super.hurtServer(level, damageSource, amount);
+ return true; // CraftBUkkit + return true; // CraftBukkit
} }
} }

View file

@ -55,15 +55,15 @@
} else { } else {
if (!this.isRemoved()) { if (!this.isRemoved()) {
- this.remove(Entity.RemovalReason.KILLED); - this.remove(Entity.RemovalReason.KILLED);
+ // Paper start - All non-living entities need this + // CraftBukkit start - All non-living entities need this
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damageSource, amount, false)) { + if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damageSource, amount, false)) {
+ return false; + return false;
+ } + }
+ // Paper end + // CraftBukkit end
if (!damageSource.is(DamageTypeTags.IS_EXPLOSION)) { if (!damageSource.is(DamageTypeTags.IS_EXPLOSION)) {
DamageSource damageSource1 = damageSource.getEntity() != null ? this.damageSources().explosion(this, damageSource.getEntity()) : null; DamageSource damageSource1 = damageSource.getEntity() != null ? this.damageSources().explosion(this, damageSource.getEntity()) : null;
- level.explode(this, damageSource1, null, this.getX(), this.getY(), this.getZ(), 6.0F, false, Level.ExplosionInteraction.BLOCK); - level.explode(this, damageSource1, null, this.getX(), this.getY(), this.getZ(), 6.0F, false, Level.ExplosionInteraction.BLOCK);
+ // Paper start + // CraftBukkit start
+ org.bukkit.event.entity.ExplosionPrimeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callExplosionPrimeEvent(this, 6.0F, false); + org.bukkit.event.entity.ExplosionPrimeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callExplosionPrimeEvent(this, 6.0F, false);
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ return false; + return false;
@ -73,7 +73,7 @@
+ level.explode(this, damageSource1, null, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), Level.ExplosionInteraction.BLOCK); + level.explode(this, damageSource1, null, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), Level.ExplosionInteraction.BLOCK);
+ } else { + } else {
+ this.remove(Entity.RemovalReason.KILLED, org.bukkit.event.entity.EntityRemoveEvent.Cause.DEATH); // Paper - add Bukkit remove cause + this.remove(Entity.RemovalReason.KILLED, org.bukkit.event.entity.EntityRemoveEvent.Cause.DEATH); // Paper - add Bukkit remove cause
+ // Paper end + // CraftBukkit end
} }
this.onDestroyedBy(level, damageSource); this.onDestroyedBy(level, damageSource);

View file

@ -34,7 +34,7 @@
+ public void setPodium(@Nullable BlockPos blockPos) { + public void setPodium(@Nullable BlockPos blockPos) {
+ this.podium = blockPos; + this.podium = blockPos;
+ } + }
+ // Paper end + // Paper end - Allow changing the EnderDragon podium
+ +
@Override @Override
public boolean isFlapping() { public boolean isFlapping() {
@ -44,7 +44,7 @@
Vec3 flyTargetLocation = currentPhase.getFlyTargetLocation(); Vec3 flyTargetLocation = currentPhase.getFlyTargetLocation();
- if (flyTargetLocation != null) { - if (flyTargetLocation != null) {
+ if (flyTargetLocation != null && currentPhase.getPhase() != EnderDragonPhase.HOVERING) { // Paper - Don't move when hovering + if (flyTargetLocation != null && currentPhase.getPhase() != EnderDragonPhase.HOVERING) { // CraftBukkit - Don't move when hovering
double d = flyTargetLocation.x - this.getX(); double d = flyTargetLocation.x - this.getX();
double d1 = flyTargetLocation.y - this.getY(); double d1 = flyTargetLocation.y - this.getY();
double d2 = flyTargetLocation.z - this.getZ(); double d2 = flyTargetLocation.z - this.getZ();
@ -53,14 +53,14 @@
this.nearestCrystal = null; this.nearestCrystal = null;
} else if (this.tickCount % 10 == 0 && this.getHealth() < this.getMaxHealth()) { } else if (this.tickCount % 10 == 0 && this.getHealth() < this.getMaxHealth()) {
- this.setHealth(this.getHealth() + 1.0F); - this.setHealth(this.getHealth() + 1.0F);
+ // Paper start + // CraftBukkit start
+ org.bukkit.event.entity.EntityRegainHealthEvent event = new org.bukkit.event.entity.EntityRegainHealthEvent(this.getBukkitEntity(), 1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL); + org.bukkit.event.entity.EntityRegainHealthEvent event = new org.bukkit.event.entity.EntityRegainHealthEvent(this.getBukkitEntity(), 1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL);
+ this.level().getCraftServer().getPluginManager().callEvent(event); + this.level().getCraftServer().getPluginManager().callEvent(event);
+ +
+ if (!event.isCancelled()) { + if (!event.isCancelled()) {
+ this.setHealth((float) (this.getHealth() + event.getAmount())); + this.setHealth((float) (this.getHealth() + event.getAmount()));
+ } + }
+ // Paper end + // CraftBukkit end
} }
} }
@ -86,11 +86,11 @@
if (!blockState.isAir() && !blockState.is(BlockTags.DRAGON_TRANSPARENT)) { if (!blockState.isAir() && !blockState.is(BlockTags.DRAGON_TRANSPARENT)) {
if (level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) && !blockState.is(BlockTags.DRAGON_IMMUNE)) { if (level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) && !blockState.is(BlockTags.DRAGON_IMMUNE)) {
- flag1 = level.removeBlock(blockPos, false) || flag1; - flag1 = level.removeBlock(blockPos, false) || flag1;
+ // Paper start - Add blocks to list rather than destroying them + // CraftBukkit start - Add blocks to list rather than destroying them
+ //flag1 = level.removeBlock(blockPos, false) || flag1; + //flag1 = level.removeBlock(blockPos, false) || flag1;
+ flag1 = true; + flag1 = true;
+ destroyedBlocks.add(org.bukkit.craftbukkit.block.CraftBlock.at(level, blockPos)); + destroyedBlocks.add(org.bukkit.craftbukkit.block.CraftBlock.at(level, blockPos));
+ // Paper end + // CraftBukkit end
} else { } else {
flag = true; flag = true;
} }
@ -98,7 +98,7 @@
} }
} }
+ // Paper start - Set off an EntityExplodeEvent for the dragon exploding all these blocks + // CraftBukkit start - Set off an EntityExplodeEvent for the dragon exploding all these blocks
+ // SPIGOT-4882: don't fire event if nothing hit + // SPIGOT-4882: don't fire event if nothing hit
+ if (!flag1) { + if (!flag1) {
+ return flag; + return flag;
@ -144,7 +144,7 @@
+ this.level().removeBlock(blockposition, false); + this.level().removeBlock(blockposition, false);
+ } + }
+ } + }
+ // Paper end + // CraftBukkit end
+ +
if (flag1) { if (flag1) {
BlockPos blockPos1 = new BlockPos( BlockPos blockPos1 = new BlockPos(
@ -161,7 +161,7 @@
+ this.silentDeath = false; // Reset to default if event was cancelled + this.silentDeath = false; // Reset to default if event was cancelled
+ return; + return;
+ } + }
+ this.remove(Entity.RemovalReason.KILLED, org.bukkit.event.entity.EntityRemoveEvent.Cause.DEATH); // Paper - add Bukkit remove cause + this.remove(Entity.RemovalReason.KILLED, org.bukkit.event.entity.EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause
+ // Paper end - Fire entity death event + // Paper end - Fire entity death event
this.gameEvent(GameEvent.ENTITY_DIE); this.gameEvent(GameEvent.ENTITY_DIE);
if (this.dragonFight != null) { if (this.dragonFight != null) {
@ -170,7 +170,7 @@
this.level().addParticle(ParticleTypes.EXPLOSION_EMITTER, this.getX() + f, this.getY() + 2.0 + f1, this.getZ() + f2, 0.0, 0.0, 0.0); this.level().addParticle(ParticleTypes.EXPLOSION_EMITTER, this.getX() + f, this.getY() + 2.0 + f1, this.getZ() + f2, 0.0, 0.0, 0.0);
} }
+ // Paper start - SPIGOT-2420: Moved up to #getExpReward method + // CraftBukkit start - SPIGOT-2420: Moved up to #getExpReward method
+ /* + /*
int i = 500; int i = 500;
if (this.dragonFight != null && !this.dragonFight.hasPreviouslyKilledDragon()) { if (this.dragonFight != null && !this.dragonFight.hasPreviouslyKilledDragon()) {
@ -178,18 +178,18 @@
} }
+ */ + */
+ int i = this.expToDrop; + int i = this.expToDrop;
+ // Paper end + // CraftBukkit end
if (this.level() instanceof ServerLevel serverLevel) { if (this.level() instanceof ServerLevel serverLevel) {
- if (this.dragonDeathTime > 150 && this.dragonDeathTime % 5 == 0 && serverLevel.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { - if (this.dragonDeathTime > 150 && this.dragonDeathTime % 5 == 0 && serverLevel.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
- ExperienceOrb.award(serverLevel, this.position(), Mth.floor(i * 0.08F)); - ExperienceOrb.award(serverLevel, this.position(), Mth.floor(i * 0.08F));
+ if (this.dragonDeathTime > 150 && this.dragonDeathTime % 5 == 0) { // Paper - SPIGOT-2420: Already checked for the game rule when calculating the xp + if (this.dragonDeathTime > 150 && this.dragonDeathTime % 5 == 0) { // CraftBukkit - SPIGOT-2420: Already checked for the game rule when calculating the xp
+ ExperienceOrb.award(serverLevel, this.position(), Mth.floor(i * 0.08F), org.bukkit.entity.ExperienceOrb.SpawnReason.ENTITY_DEATH, this.lastHurtByPlayer, this); // Paper + ExperienceOrb.award(serverLevel, this.position(), Mth.floor(i * 0.08F), org.bukkit.entity.ExperienceOrb.SpawnReason.ENTITY_DEATH, this.lastHurtByPlayer, this); // Paper
} }
if (this.dragonDeathTime == 1 && !this.isSilent()) { if (this.dragonDeathTime == 1 && !this.isSilent()) {
- serverLevel.globalLevelEvent(1028, this.blockPosition(), 0); - serverLevel.globalLevelEvent(1028, this.blockPosition(), 0);
+ // Paper start - Use relative location for far away sounds + // CraftBukkit start - Use relative location for far away sounds
+ // serverLevel.globalLevelEvent(1028, this.blockPosition(), 0); + // serverLevel.globalLevelEvent(1028, this.blockPosition(), 0);
+ int viewDistance = serverLevel.getCraftServer().getViewDistance() * 16; + int viewDistance = serverLevel.getCraftServer().getViewDistance() * 16;
+ for (net.minecraft.server.level.ServerPlayer player : serverLevel.getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule + for (net.minecraft.server.level.ServerPlayer player : serverLevel.getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule
@ -207,7 +207,7 @@
+ player.connection.send(new net.minecraft.network.protocol.game.ClientboundLevelEventPacket(1028, new BlockPos((int) this.getX(), (int) this.getY(), (int) this.getZ()), 0, true)); + player.connection.send(new net.minecraft.network.protocol.game.ClientboundLevelEventPacket(1028, new BlockPos((int) this.getX(), (int) this.getY(), (int) this.getZ()), 0, true));
+ } + }
+ } + }
+ // Paper end + // CraftBukkit end
} }
} }
@ -226,7 +226,7 @@
} }
- this.remove(Entity.RemovalReason.KILLED); - this.remove(Entity.RemovalReason.KILLED);
+ this.remove(Entity.RemovalReason.KILLED, org.bukkit.event.entity.EntityRemoveEvent.Cause.DEATH); // Paper - add Bukkit remove cause + this.remove(Entity.RemovalReason.KILLED, org.bukkit.event.entity.EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause
this.gameEvent(GameEvent.ENTITY_DIE); this.gameEvent(GameEvent.ENTITY_DIE);
} }
} }
@ -234,7 +234,7 @@
super.addAdditionalSaveData(compound); super.addAdditionalSaveData(compound);
compound.putInt("DragonPhase", this.phaseManager.getCurrentPhase().getPhase().getId()); compound.putInt("DragonPhase", this.phaseManager.getCurrentPhase().getPhase().getId());
compound.putInt("DragonDeathTime", this.dragonDeathTime); compound.putInt("DragonDeathTime", this.dragonDeathTime);
+ compound.putInt("Bukkit.expToDrop", this.expToDrop); // Paper - SPIGOT-2420: The ender dragon drops xp over time which can also happen between server starts + compound.putInt("Bukkit.expToDrop", this.expToDrop); // CraftBukkit - SPIGOT-2420: The ender dragon drops xp over time which can also happen between server starts
} }
@Override @Override
@ -243,11 +243,11 @@
this.dragonDeathTime = compound.getInt("DragonDeathTime"); this.dragonDeathTime = compound.getInt("DragonDeathTime");
} }
+ +
+ // Paper start - SPIGOT-2420: The ender dragon drops xp over time which can also happen between server starts + // CraftBukkit start - SPIGOT-2420: The ender dragon drops xp over time which can also happen between server starts
+ if (compound.contains("Bukkit.expToDrop")) { + if (compound.contains("Bukkit.expToDrop")) {
+ this.expToDrop = compound.getInt("Bukkit.expToDrop"); + this.expToDrop = compound.getInt("Bukkit.expToDrop");
+ } + }
+ // Paper end + // CraftBukkit end
} }
@Override @Override
@ -265,7 +265,7 @@
return 1.0F; return 1.0F;
} }
+ +
+ // Paper start - SPIGOT-2420: Special case, the ender dragon drops 12000 xp for the first kill and 500 xp for every other kill and this over time. + // CraftBukkit start - SPIGOT-2420: Special case, the ender dragon drops 12000 xp for the first kill and 500 xp for every other kill and this over time.
+ @Override + @Override
+ public int getExpReward(ServerLevel worldserver, Entity entity) { + public int getExpReward(ServerLevel worldserver, Entity entity) {
+ // CraftBukkit - Moved from #tickDeath method + // CraftBukkit - Moved from #tickDeath method
@ -278,6 +278,6 @@
+ +
+ return flag ? short0 : 0; + return flag ? short0 : 0;
+ } + }
+ // Paper end + // CraftBukkit end
+ +
} }

View file

@ -6,11 +6,11 @@
this.flame.addEffect(new MobEffectInstance(MobEffects.HARM)); this.flame.addEffect(new MobEffectInstance(MobEffects.HARM));
+ if (new com.destroystokyo.paper.event.entity.EnderDragonFlameEvent((org.bukkit.entity.EnderDragon) this.dragon.getBukkitEntity(), (org.bukkit.entity.AreaEffectCloud) this.flame.getBukkitEntity()).callEvent()) { // Paper - EnderDragon Events + if (new com.destroystokyo.paper.event.entity.EnderDragonFlameEvent((org.bukkit.entity.EnderDragon) this.dragon.getBukkitEntity(), (org.bukkit.entity.AreaEffectCloud) this.flame.getBukkitEntity()).callEvent()) { // Paper - EnderDragon Events
level.addFreshEntity(this.flame); level.addFreshEntity(this.flame);
+ // Paper start + // Paper start - EnderDragon Events
+ } else { + } else {
+ this.end(); + this.end();
+ } + }
+ // Paper end + // Paper end - EnderDragon Events
} }
} }
@ -19,7 +19,7 @@
public void end() { public void end() {
if (this.flame != null) { if (this.flame != null) {
- this.flame.discard(); - this.flame.discard();
+ this.flame.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DESPAWN); // Paper- add Bukkit remove cause + this.flame.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
this.flame = null; this.flame = null;
} }
} }

View file

@ -4,7 +4,7 @@
this.currentPhase.end(); this.currentPhase.end();
} }
+ // Paper start - Call EnderDragonChangePhaseEvent + // CraftBukkit start - Call EnderDragonChangePhaseEvent
+ org.bukkit.event.entity.EnderDragonChangePhaseEvent event = new org.bukkit.event.entity.EnderDragonChangePhaseEvent( + org.bukkit.event.entity.EnderDragonChangePhaseEvent event = new org.bukkit.event.entity.EnderDragonChangePhaseEvent(
+ (org.bukkit.craftbukkit.entity.CraftEnderDragon) this.dragon.getBukkitEntity(), + (org.bukkit.craftbukkit.entity.CraftEnderDragon) this.dragon.getBukkitEntity(),
+ (this.currentPhase == null) ? null : org.bukkit.craftbukkit.entity.CraftEnderDragon.getBukkitPhase(this.currentPhase.getPhase()), + (this.currentPhase == null) ? null : org.bukkit.craftbukkit.entity.CraftEnderDragon.getBukkitPhase(this.currentPhase.getPhase()),
@ -15,7 +15,7 @@
+ return; + return;
+ } + }
+ phase = org.bukkit.craftbukkit.entity.CraftEnderDragon.getMinecraftPhase(event.getNewPhase()); + phase = org.bukkit.craftbukkit.entity.CraftEnderDragon.getMinecraftPhase(event.getNewPhase());
+ // Paper end + // CraftBukkit end
+ +
this.currentPhase = this.getPhase((EnderDragonPhase<DragonPhaseInstance>)phase); this.currentPhase = this.getPhase((EnderDragonPhase<DragonPhaseInstance>)phase);
if (!this.dragon.level().isClientSide) { if (!this.dragon.level().isClientSide) {