#1209: Clean up various patches

By: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
This commit is contained in:
CraftBukkit/Spigot
2023-06-24 17:15:05 +10:00
parent 0f9e7a497e
commit b97cc9b99f
71 changed files with 662 additions and 719 deletions

View File

@@ -11,23 +11,21 @@
public class PathfinderGoalEatTile extends PathfinderGoal {
private static final int EAT_ANIMATION_TICKS = 40;
@@ -64,7 +68,8 @@
@@ -64,7 +68,7 @@
BlockPosition blockposition = this.mob.blockPosition();
if (PathfinderGoalEatTile.IS_TALL_GRASS.test(this.level.getBlockState(blockposition))) {
- if (this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) {
+ // CraftBukkit
+ if (!CraftEventFactory.callEntityChangeBlockEvent(this.mob, blockposition, Blocks.AIR.defaultBlockState(), !this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)).isCancelled()) {
+ if (CraftEventFactory.callEntityChangeBlockEvent(this.mob, blockposition, Blocks.AIR.defaultBlockState(), !this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) { // CraftBukkit
this.level.destroyBlock(blockposition, false);
}
@@ -73,7 +78,8 @@
@@ -73,7 +77,7 @@
BlockPosition blockposition1 = blockposition.below();
if (this.level.getBlockState(blockposition1).is(Blocks.GRASS_BLOCK)) {
- if (this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) {
+ // CraftBukkit
+ if (!CraftEventFactory.callEntityChangeBlockEvent(this.mob, blockposition1, Blocks.AIR.defaultBlockState(), !this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)).isCancelled()) {
+ if (CraftEventFactory.callEntityChangeBlockEvent(this.mob, blockposition1, Blocks.AIR.defaultBlockState(), !this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) { // CraftBukkit
this.level.levelEvent(2001, blockposition1, Block.getId(Blocks.GRASS_BLOCK.defaultBlockState()));
this.level.setBlock(blockposition1, Blocks.DIRT.defaultBlockState(), 2);
}

View File

@@ -6,28 +6,24 @@
+// CraftBukkit start
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.entity.CraftEntity;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityTeleportEvent;
+// CraftBukkit end
+
public class PathfinderGoalFollowOwner extends PathfinderGoal {
public static final int TELEPORT_WHEN_DISTANCE_IS = 12;
@@ -122,7 +128,18 @@
@@ -122,7 +128,14 @@
} else if (!this.canTeleportTo(new BlockPosition(i, j, k))) {
return false;
} else {
- this.tamable.moveTo((double) i + 0.5D, (double) j, (double) k + 0.5D, this.tamable.getYRot(), this.tamable.getXRot());
+ // CraftBukkit start
+ CraftEntity entity = this.tamable.getBukkitEntity();
+ Location to = new Location(entity.getWorld(), (double) i + 0.5D, (double) j, (double) k + 0.5D, this.tamable.getYRot(), this.tamable.getXRot());
+ EntityTeleportEvent event = new EntityTeleportEvent(entity, entity.getLocation(), to);
+ this.tamable.level().getCraftServer().getPluginManager().callEvent(event);
+ EntityTeleportEvent event = CraftEventFactory.callEntityTeleportEvent(this.tamable, (double) i + 0.5D, (double) j, (double) k + 0.5D);
+ if (event.isCancelled()) {
+ return false;
+ }
+ to = event.getTo();
+
+ Location to = event.getTo();
+ this.tamable.moveTo(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch());
+ // CraftBukkit end
this.navigation.stop();

View File

@@ -1,34 +0,0 @@
--- a/net/minecraft/world/entity/ai/goal/PathfinderGoalPanic.java
+++ b/net/minecraft/world/entity/ai/goal/PathfinderGoalPanic.java
@@ -10,6 +10,10 @@
import net.minecraft.world.level.IBlockAccess;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import net.minecraft.world.entity.EntityLiving;
+// CraftBukkit end
+
public class PathfinderGoalPanic extends PathfinderGoal {
public static final int WATER_CHECK_DISTANCE_VERTICAL = 1;
@@ -80,6 +84,12 @@
@Override
public boolean canContinueToUse() {
+ // CraftBukkit start - introduce a temporary timeout hack until this is fixed properly
+ if ((this.mob.tickCount - this.mob.lastHurtByMobTimestamp) > 100) {
+ this.mob.setLastHurtByMob((EntityLiving) null);
+ return false;
+ }
+ // CraftBukkit end
return !this.mob.getNavigation().isDone();
}
@@ -89,6 +99,6 @@
return !iblockaccess.getBlockState(blockposition).getCollisionShape(iblockaccess, blockposition).isEmpty() ? null : (BlockPosition) BlockPosition.findClosestMatch(entity.blockPosition(), i, 1, (blockposition1) -> {
return iblockaccess.getFluidState(blockposition1).is(TagsFluid.WATER);
- }).orElse((Object) null);
+ }).orElse(null); // CraftBukkit - decompile error
}
}

View File

@@ -6,21 +6,18 @@
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.event.entity.EntityInteractEvent;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+// CraftBukkit end
+
public class PathfinderGoalRemoveBlock extends PathfinderGoalGotoTarget {
private final Block blockToRemove;
@@ -96,6 +101,14 @@
@@ -96,6 +101,11 @@
}
if (this.ticksSinceReachedGoal > 60) {
+ // CraftBukkit start - Step on eggs
+ EntityInteractEvent event = new EntityInteractEvent(this.removerMob.getBukkitEntity(), CraftBlock.at(world, blockposition1));
+ world.getCraftServer().getPluginManager().callEvent((EntityInteractEvent) event);
+
+ if (event.isCancelled()) {
+ if (!CraftEventFactory.callEntityInteractEvent(this.removerMob, CraftBlock.at(world, blockposition1))) {
+ return;
+ }
+ // CraftBukkit end

View File

@@ -1,11 +1,11 @@
--- a/net/minecraft/world/entity/ai/goal/PathfinderGoalSit.java
+++ b/net/minecraft/world/entity/ai/goal/PathfinderGoalSit.java
@@ -22,7 +22,7 @@
@@ -21,7 +21,7 @@
@Override
public boolean canUse() {
if (!this.mob.isTame()) {
- return false;
+ return this.mob.isOrderedToSit() && this.mob.getTarget() == null; // CraftBukkit - Allow sitting for wild animals
- if (!this.mob.isTame()) {
+ if (false && !this.mob.isTame()) { // CraftBukkit - Allow sitting for wild animals
return false;
} else if (this.mob.isInWaterOrBubble()) {
return false;
} else if (!this.mob.onGround()) {

View File

@@ -1,12 +1,23 @@
--- a/net/minecraft/world/entity/ai/goal/PathfinderGoalTame.java
+++ b/net/minecraft/world/entity/ai/goal/PathfinderGoalTame.java
@@ -62,7 +62,8 @@
@@ -7,6 +7,11 @@
import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+// CraftBukkit end
+
public class PathfinderGoalTame extends PathfinderGoal {
private final EntityHorseAbstract horse;
@@ -62,7 +67,7 @@
int i = this.horse.getTemper();
int j = this.horse.getMaxTemper();
- if (j > 0 && this.horse.getRandom().nextInt(j) < i) {
+ // CraftBukkit - fire EntityTameEvent
+ if (j > 0 && this.horse.getRandom().nextInt(j) < i && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this.horse, ((org.bukkit.craftbukkit.entity.CraftHumanEntity) this.horse.getBukkitEntity().getPassenger()).getHandle()).isCancelled()) {
+ if (j > 0 && this.horse.getRandom().nextInt(j) < i && !CraftEventFactory.callEntityTameEvent(this.horse, ((CraftHumanEntity) this.horse.getBukkitEntity().getPassenger()).getHandle()).isCancelled()) { // CraftBukkit - fire EntityTameEvent
this.horse.tameWithName((EntityHuman) entity);
return;
}

View File

@@ -1,15 +1,17 @@
--- a/net/minecraft/world/entity/ai/goal/target/PathfinderGoalTarget.java
+++ b/net/minecraft/world/entity/ai/goal/target/PathfinderGoalTarget.java
@@ -11,6 +11,8 @@
@@ -11,6 +11,10 @@
import net.minecraft.world.level.pathfinder.PathPoint;
import net.minecraft.world.scores.ScoreboardTeamBase;
+import org.bukkit.event.entity.EntityTargetEvent; // CraftBukkit
+// CraftBukkit start
+import org.bukkit.event.entity.EntityTargetEvent;
+// CraftBukkit end
+
public abstract class PathfinderGoalTarget extends PathfinderGoal {
private static final int EMPTY_REACH_CACHE = 0;
@@ -69,7 +71,7 @@
@@ -69,7 +73,7 @@
}
}
@@ -18,7 +20,7 @@
return true;
}
}
@@ -89,7 +91,7 @@
@@ -89,7 +93,7 @@
@Override
public void stop() {