diff --git a/docs/README.md b/docs/README.md
index 1a243d39ef..65896acd98 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -14,7 +14,7 @@ that enables the use of Bukkit plugins on Forge servers.
Ketting is still in development and is not ready for production use.
### PATCHES DONE
-Bukkit: 251 / 530
+Bukkit: 260 / 530
CraftBukkit: 0 / 685
diff --git a/patches/minecraft/net/minecraft/server/commands/SpreadPlayersCommand.java.patch b/patches/minecraft/net/minecraft/server/commands/SpreadPlayersCommand.java.patch
index ec2ab57d8c..8ce7e7a153 100644
--- a/patches/minecraft/net/minecraft/server/commands/SpreadPlayersCommand.java.patch
+++ b/patches/minecraft/net/minecraft/server/commands/SpreadPlayersCommand.java.patch
@@ -6,7 +6,7 @@
- entity.teleportTo(p_138731_, (double)Mth.floor(spreadplayerscommand$position.x) + 0.5D, (double)spreadplayerscommand$position.getSpawnY(p_138731_, p_138733_), (double)Mth.floor(spreadplayerscommand$position.z) + 0.5D, Set.of(), entity.getYRot(), entity.getXRot());
+ net.minecraftforge.event.entity.EntityTeleportEvent.SpreadPlayersCommand event = net.minecraftforge.event.ForgeEventFactory.onEntityTeleportSpreadPlayersCommand(entity, (double)Mth.floor(spreadplayerscommand$position.x) + 0.5D, (double)spreadplayerscommand$position.getSpawnY(p_138731_, p_138733_), (double)Mth.floor(spreadplayerscommand$position.z) + 0.5D);
-+ if (!event.isCanceled()) entity.teleportToWithTicket(event.getTargetX(), event.getTargetY(), event.getTargetZ(), org.bukkit.event.player.PlayerSpawnChangeEvent.Cause.COMMAND); // CraftBukkit - handle teleport reason //Ketting - modified for forge compat
++ if (!event.isCanceled()) entity.teleportTo(p_138731_, event.getTargetX(), event.getTargetY(), event.getTargetZ(), Set.of(), entity.getYRot(), entity.getXRot(), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.COMMAND); // CraftBukkit - handle teleport reason //Ketting - modified for forge compat
double d2 = Double.MAX_VALUE;
for(SpreadPlayersCommand.Position spreadplayerscommand$position1 : p_138732_) {
diff --git a/patches/minecraft/net/minecraft/world/entity/AreaEffectCloud.java.patch b/patches/minecraft/net/minecraft/world/entity/AreaEffectCloud.java.patch
new file mode 100644
index 0000000000..b63e1978a0
--- /dev/null
+++ b/patches/minecraft/net/minecraft/world/entity/AreaEffectCloud.java.patch
@@ -0,0 +1,110 @@
+--- a/net/minecraft/world/entity/AreaEffectCloud.java
++++ b/net/minecraft/world/entity/AreaEffectCloud.java
+@@ -5,6 +_,8 @@
+ import com.mojang.brigadier.StringReader;
+ import com.mojang.brigadier.exceptions.CommandSyntaxException;
+ import com.mojang.logging.LogUtils;
++
++import java.util.Iterator;
+ import java.util.List;
+ import java.util.Map;
+ import java.util.UUID;
+@@ -20,12 +_,14 @@
+ import net.minecraft.network.syncher.SynchedEntityData;
+ import net.minecraft.server.level.ServerLevel;
+ import net.minecraft.util.Mth;
++import net.minecraft.world.effect.MobEffect;
+ import net.minecraft.world.effect.MobEffectInstance;
+ import net.minecraft.world.item.alchemy.Potion;
+ import net.minecraft.world.item.alchemy.PotionUtils;
+ import net.minecraft.world.item.alchemy.Potions;
+ import net.minecraft.world.level.Level;
+ import net.minecraft.world.level.material.PushReaction;
++import org.bukkit.craftbukkit.v1_20_R2.entity.CraftLivingEntity;
+ import org.slf4j.Logger;
+
+ public class AreaEffectCloud extends Entity implements TraceableEntity {
+@@ -41,16 +_,16 @@
+ public static final float DEFAULT_WIDTH = 6.0F;
+ public static final float HEIGHT = 0.5F;
+ private static final String TAG_EFFECTS = "effects";
+- private Potion potion = Potions.EMPTY;
+- private final List effects = Lists.newArrayList();
++ public Potion potion = Potions.EMPTY;
++ public final List effects = Lists.newArrayList();
+ private final Map victims = Maps.newHashMap();
+ private int duration = 600;
+ private int waitTime = 20;
+- private int reapplicationDelay = 20;
++ public int reapplicationDelay = 20;
+ private boolean fixedColor;
+- private int durationOnUse;
+- private float radiusOnUse;
+- private float radiusPerTick;
++ public int durationOnUse;
++ public float radiusOnUse;
++ public float radiusPerTick;
+ @Nullable
+ private LivingEntity owner;
+ @Nullable
+@@ -150,6 +_,18 @@
+ this.duration = p_19735_;
+ }
+
++ // Spigot start - copied from below
++ @Override
++ public void inactiveTick() {
++ super.inactiveTick();
++
++ if (this.tickCount >= this.waitTime + this.duration) {
++ this.discard();
++ return;
++ }
++ }
++ // Spigot end
++
+ public void tick() {
+ super.tick();
+ boolean flag = this.isWaiting();
+@@ -239,19 +_,35 @@
+ } else {
+ List list1 = this.level().getEntitiesOfClass(LivingEntity.class, this.getBoundingBox());
+ if (!list1.isEmpty()) {
++ List entities = new java.util.ArrayList(); // CraftBukkit
+ for(LivingEntity livingentity : list1) {
+ if (!this.victims.containsKey(livingentity) && livingentity.isAffectedByPotions()) {
+ double d8 = livingentity.getX() - this.getX();
+ double d1 = livingentity.getZ() - this.getZ();
+ double d3 = d8 * d8 + d1 * d1;
+ if (d3 <= (double)(f * f)) {
+- this.victims.put(livingentity, this.tickCount + this.reapplicationDelay);
+-
+- for(MobEffectInstance mobeffectinstance1 : list) {
+- if (mobeffectinstance1.getEffect().isInstantenous()) {
+- mobeffectinstance1.getEffect().applyInstantenousEffect(this, this.getOwner(), livingentity, mobeffectinstance1.getAmplifier(), 0.5D);
++ // CraftBukkit start
++ entities.add((org.bukkit.entity.LivingEntity) livingentity.getBukkitEntity());
++ }
++ }
++ }
++
++ org.bukkit.event.entity.AreaEffectCloudApplyEvent event = org.bukkit.craftbukkit.v1_20_R2.event.CraftEventFactory.callAreaEffectCloudApplyEvent(this, entities);
++ if (!event.isCancelled()) {
++ for (org.bukkit.entity.LivingEntity entity : event.getAffectedEntities()) {
++ if (entity instanceof CraftLivingEntity) {
++ LivingEntity entityliving = ((CraftLivingEntity) entity).getHandle();
++ // CraftBukkit end
++ this.victims.put(entityliving, this.tickCount + this.reapplicationDelay);
++ Iterator iterator2 = list.iterator();
++
++ while (iterator2.hasNext()) {
++ MobEffectInstance mobeffect1 = (MobEffectInstance) iterator2.next();
++
++ if (mobeffect1.getEffect().isInstantenous()) {
++ mobeffect1.getEffect().applyInstantenousEffect(this, this.getOwner(), entityliving, mobeffect1.getAmplifier(), 0.5D);
+ } else {
+- livingentity.addEffect(new MobEffectInstance(mobeffectinstance1), this);
++ entityliving.addEffect(new MobEffectInstance(mobeffect1), this, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.AREA_EFFECT_CLOUD); // CraftBukkit
+ }
+ }
+
diff --git a/patches/minecraft/net/minecraft/world/entity/Entity.java.patch b/patches/minecraft/net/minecraft/world/entity/Entity.java.patch
index a7914bc072..68fd857f42 100644
--- a/patches/minecraft/net/minecraft/world/entity/Entity.java.patch
+++ b/patches/minecraft/net/minecraft/world/entity/Entity.java.patch
@@ -1,15 +1,75 @@
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
-@@ -122,7 +_,7 @@
+@@ -98,6 +_,7 @@
+ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
+ import net.minecraft.world.level.border.WorldBorder;
+ import net.minecraft.world.level.dimension.DimensionType;
++import net.minecraft.world.level.dimension.LevelStem;
+ import net.minecraft.world.level.entity.EntityAccess;
+ import net.minecraft.world.level.entity.EntityInLevelCallback;
+ import net.minecraft.world.level.gameevent.DynamicGameEventListener;
+@@ -119,10 +_,58 @@
+ import net.minecraft.world.phys.shapes.VoxelShape;
+ import net.minecraft.world.scores.PlayerTeam;
+ import net.minecraft.world.scores.Team;
++import org.bukkit.Bukkit;
++import org.bukkit.Location;
++import org.bukkit.Server;
++import org.bukkit.block.BlockFace;
++import org.bukkit.command.CommandSender;
++import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
++import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity;
++import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
++import org.bukkit.craftbukkit.v1_20_R2.event.CraftEventFactory;
++import org.bukkit.craftbukkit.v1_20_R2.event.CraftPortalEvent;
++import org.bukkit.craftbukkit.v1_20_R2.util.CraftLocation;
++import org.bukkit.entity.Hanging;
++import org.bukkit.entity.Vehicle;
++import org.bukkit.event.entity.*;
++import org.bukkit.event.hanging.HangingBreakByEntityEvent;
++import org.bukkit.event.player.PlayerTeleportEvent;
++import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
++import org.bukkit.event.vehicle.VehicleEnterEvent;
++import org.bukkit.event.vehicle.VehicleExitEvent;
++import org.bukkit.plugin.PluginManager;
import org.joml.Vector3f;
import org.slf4j.Logger;
-
+-
-public abstract class Entity implements Nameable, EntityAccess, CommandSource {
++import org.spigotmc.CustomTimingsHandler;
++
+public abstract class Entity extends net.minecraftforge.common.capabilities.CapabilityProvider implements Nameable, EntityAccess, CommandSource, net.minecraftforge.common.extensions.IForgeEntity {
++
++ // CraftBukkit start
++ private static final int CURRENT_LEVEL = 2;
++ static boolean isLevelAtLeast(CompoundTag tag, int level) {
++ return tag.contains("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
++ }
++
++ private CraftEntity bukkitEntity;
++
++ public CraftEntity getBukkitEntity() {
++ if (bukkitEntity == null) {
++ bukkitEntity = CraftEntity.getEntity(level.getCraftServer(), this);
++ }
++ return bukkitEntity;
++ }
++
++ @Override
++ public CommandSender getBukkitSender(CommandSourceStack wrapper) {
++ return getBukkitEntity();
++ }
++
++ // CraftBukkit - SPIGOT-6907: re-implement LivingEntity#setMaximumAir()
++ public int getDefaultMaxAirSupply() {
++ return TOTAL_AIR_SUPPLY;
++ }
++ // CraftBukkit end
++
private static final Logger LOGGER = LogUtils.getLogger();
public static final String ID_TAG = "id";
public static final String PASSENGERS_TAG = "Passengers";
-@@ -143,6 +_,7 @@
+@@ -143,10 +_,11 @@
private static final double LAVA_SLOW_FLOW_SCALE = 0.0023333333333333335D;
public static final String UUID_TAG = "UUID";
private static double viewScale = 1.0D;
@@ -17,6 +77,11 @@
private final EntityType> type;
private int id = ENTITY_COUNTER.incrementAndGet();
public boolean blocksBuilding;
+- private ImmutableList passengers = ImmutableList.of();
++ public ImmutableList passengers = ImmutableList.of();
+ protected int boardingCooldown;
+ @Nullable
+ private Entity vehicle;
@@ -163,7 +_,7 @@
public float yRotO;
public float xRotO;
@@ -26,10 +91,12 @@
public boolean horizontalCollision;
public boolean verticalCollision;
public boolean verticalCollisionBelow;
-@@ -189,8 +_,10 @@
+@@ -188,9 +_,11 @@
+ protected final RandomSource random = RandomSource.create();
public int tickCount;
private int remainingFireTicks = -this.getFireImmuneTicks();
- protected boolean wasTouchingWater;
+- protected boolean wasTouchingWater;
++ public boolean wasTouchingWater;
+ @Deprecated // Forge: Use forgeFluidTypeHeight instead
protected Object2DoubleMap> fluidHeight = new Object2DoubleArrayMap<>(2);
protected boolean wasEyeInWater;
@@ -37,16 +104,73 @@
private final Set> fluidOnEyes = new HashSet<>();
public int invulnerableTime;
protected boolean firstTick = true;
-@@ -239,6 +_,7 @@
+@@ -214,7 +_,7 @@
+ private final VecDeltaCodec packetPositionCodec = new VecDeltaCodec();
+ public boolean noCulling;
+ public boolean hasImpulse;
+- private int portalCooldown;
++ public int portalCooldown;
+ protected boolean isInsidePortal;
+ protected int portalTime;
+ protected BlockPos portalEntrancePos;
+@@ -234,17 +_,51 @@
+ private boolean onGroundNoBlocks = false;
+ private float crystalSoundIntensity;
+ private int lastCrystalSoundPlayTick;
+- private boolean hasVisualFire;
++ public boolean hasVisualFire;
+ @Nullable
private BlockState feetBlockState = null;
++ // CraftBukkit start
++ public boolean persist = true;
++ public boolean visibleByDefault = true;
++ public boolean valid;
++ public boolean generation;
++ public int maxAirTicks = getDefaultMaxAirSupply(); // CraftBukkit - SPIGOT-6907: re-implement LivingEntity#setMaximumAir()
++ public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only
++ public boolean lastDamageCancelled; // SPIGOT-5339, SPIGOT-6252, SPIGOT-6777: Keep track if the event was canceled
++ public boolean persistentInvisibility = false;
++ public BlockPos lastLavaContact;
++ public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.v1_20_R2.SpigotTimings.getEntityTimings(this); // Spigot
++ // Spigot start
++ public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
++ public final boolean defaultActivationState;
++ public long activatedTick = Integer.MIN_VALUE;
++ public void inactiveTick() { }
++ // Spigot end
++
++ public float getBukkitYaw() {
++ return this.yRot;
++ }
++
++ public boolean isChunkLoaded() {
++ return level.hasChunk((int) Math.floor(this.getX()) >> 4, (int) Math.floor(this.getZ()) >> 4);
++ }
++ // CraftBukkit end
public Entity(EntityType> p_19870_, Level p_19871_) {
+ super(Entity.class);
this.type = p_19870_;
this.level = p_19871_;
this.dimensions = p_19870_.getDimensions();
-@@ -257,6 +_,8 @@
+ this.position = Vec3.ZERO;
+ this.blockPosition = BlockPos.ZERO;
+ this.chunkPosition = ChunkPos.ZERO;
++ // Spigot start
++ if (p_19871_ != null) {
++ this.defaultActivationState = org.spigotmc.ActivationRange.initializeEntityActivationState(this, p_19871_.spigotConfig);
++ } else {
++ this.defaultActivationState = false;
++ }
++ // Spigot end
+ this.entityData = new SynchedEntityData(this);
+ this.entityData.define(DATA_SHARED_FLAGS_ID, (byte)0);
+ this.entityData.define(DATA_AIR_SUPPLY_ID, this.getMaxAirSupply());
+@@ -255,8 +_,11 @@
+ this.entityData.define(DATA_POSE, Pose.STANDING);
+ this.entityData.define(DATA_TICKS_FROZEN, 0);
this.defineSynchedData();
++ this.getEntityData().registrationLocked = true; // Spigot
this.setPos(0.0D, 0.0D, 0.0D);
this.eyeHeight = this.getEyeHeight(Pose.STANDING, this.dimensions);
+ net.minecraftforge.event.ForgeEventFactory.onEntityConstructing(this);
@@ -54,7 +178,7 @@
}
public boolean isColliding(BlockPos p_20040_, BlockState p_20041_) {
-@@ -346,6 +_,7 @@
+@@ -346,12 +_,19 @@
public void remove(Entity.RemovalReason p_146834_) {
this.setRemoved(p_146834_);
@@ -62,15 +186,185 @@
}
public void onClientRemoval() {
-@@ -463,7 +_,7 @@
+ }
+
+ public void setPose(Pose p_20125_) {
++ // CraftBukkit start
++ if (p_20125_ == this.getPose()) {
++ return;
++ }
++ this.level.getCraftServer().getPluginManager().callEvent(new EntityPoseChangeEvent(this.getBukkitEntity(), org.bukkit.entity.Pose.values()[p_20125_.ordinal()]));
++ // CraftBukkit end
+ this.entityData.set(DATA_POSE, p_20125_);
+ }
+
+@@ -375,6 +_,33 @@
+ }
+
+ protected void setRot(float p_19916_, float p_19917_) {
++ // CraftBukkit start - yaw was sometimes set to NaN, so we need to set it back to 0
++ if (Float.isNaN(p_19916_)) {
++ p_19916_ = 0;
++ }
++
++ if (p_19916_ == Float.POSITIVE_INFINITY || p_19916_ == Float.NEGATIVE_INFINITY) {
++ if (this instanceof ServerPlayer) {
++ this.level.getCraftServer().getLogger().warning(this.getScoreboardName() + " was caught trying to crash the server with an invalid yaw");
++ ((CraftPlayer) this.getBukkitEntity()).kickPlayer("Infinite yaw (Hacking?)");
++ }
++ p_19916_ = 0;
++ }
++
++ // pitch was sometimes set to NaN, so we need to set it back to 0
++ if (Float.isNaN(p_19917_)) {
++ p_19917_ = 0;
++ }
++
++ if (p_19917_ == Float.POSITIVE_INFINITY || p_19917_ == Float.NEGATIVE_INFINITY) {
++ if (this instanceof ServerPlayer) {
++ this.level.getCraftServer().getLogger().warning(this.getScoreboardName() + " was caught trying to crash the server with an invalid pitch");
++ ((CraftPlayer) this.getBukkitEntity()).kickPlayer("Infinite pitch (Hacking?)");
++ }
++ p_19917_ = 0;
++ }
++ // CraftBukkit end
++
+ this.setYRot(p_19916_ % 360.0F);
+ this.setXRot(p_19917_ % 360.0F);
+ }
+@@ -415,6 +_,15 @@
+ this.baseTick();
+ }
+
++ // CraftBukkit start
++ public void postTick() {
++ // No clean way to break out of ticking once the entity has been copied to a new world, so instead we move the portalling later in the tick cycle
++ if (!(this instanceof ServerPlayer)) {
++ this.handleNetherPortal();
++ }
++ }
++ // CraftBukkit end
++
+ public void baseTick() {
+ this.level().getProfiler().push("entityBaseTick");
+ this.feetBlockState = null;
+@@ -429,7 +_,7 @@
+ this.walkDistO = this.walkDist;
+ this.xRotO = this.getXRot();
+ this.yRotO = this.getYRot();
+- this.handleNetherPortal();
++ if (this instanceof ServerPlayer) this.handleNetherPortal(); // CraftBukkit - // Moved up to postTick
+ if (this.canSpawnSprintParticle()) {
+ this.spawnSprintParticle();
+ }
+@@ -463,7 +_,11 @@
if (this.isInLava()) {
this.lavaHurt();
- this.fallDistance *= 0.5F;
+ this.fallDistance *= this.getFluidFallDistanceModifier(net.minecraftforge.common.ForgeMod.LAVA_TYPE.get());
++ // CraftBukkit start
++ } else {
++ this.lastLavaContact = null;
++ // CraftBukkit end
}
this.checkBelowWorld();
+@@ -515,15 +_,48 @@
+
+ public void lavaHurt() {
+ if (!this.fireImmune()) {
+- this.setSecondsOnFire(15);
++ // CraftBukkit start - Fallen in lava TODO: this event spams!
++ if (this instanceof LivingEntity && remainingFireTicks <= 0) {
++ // not on fire yet
++ org.bukkit.block.Block damager = (lastLavaContact == null) ? null : org.bukkit.craftbukkit.v1_20_R2.block.CraftBlock.at(level, lastLavaContact);
++ org.bukkit.entity.Entity damagee = this.getBukkitEntity();
++ EntityCombustEvent combustEvent = new org.bukkit.event.entity.EntityCombustByBlockEvent(damager, damagee, 15);
++ this.level.getCraftServer().getPluginManager().callEvent(combustEvent);
++
++ if (!combustEvent.isCancelled()) {
++ this.setSecondsOnFire(combustEvent.getDuration(), false);
++ }
++ } else {
++ // This will be called every single tick the entity is in lava, so don't throw an event
++ this.setSecondsOnFire(15, false);
++ }
++ CraftEventFactory.blockDamage = (lastLavaContact) == null ? null : org.bukkit.craftbukkit.v1_20_R2.block.CraftBlock.at(level, lastLavaContact);
+ if (this.hurt(this.damageSources().lava(), 4.0F)) {
+ this.playSound(SoundEvents.GENERIC_BURN, 0.4F, 2.0F + this.random.nextFloat() * 0.4F);
+ }
++ CraftEventFactory.blockDamage = null;
++ // CraftBukkit end - we also don't throw an event unless the object in lava is living, to save on some event calls
+
+ }
+ }
+
+ public void setSecondsOnFire(int p_20255_) {
++ // CraftBukkit start
++ this.setSecondsOnFire(p_20255_, true);
++ }
++
++ public void setSecondsOnFire(int p_20255_, boolean callEvent) {
++ if (callEvent) {
++ EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity(), p_20255_);
++ this.level.getCraftServer().getPluginManager().callEvent(event);
++
++ if (event.isCancelled()) {
++ return;
++ }
++
++ p_20255_ = event.getDuration();
++ }
++ // CraftBukkit end
+ int i = p_20255_ * 20;
+ if (this instanceof LivingEntity) {
+ i = ProtectionEnchantment.getFireAfterDampener((LivingEntity)this, i);
+@@ -603,6 +_,7 @@
+ }
+
+ public void move(MoverType p_19973_, Vec3 p_19974_) {
++ org.bukkit.craftbukkit.v1_20_R2.SpigotTimings.entityMoveTimer.startTiming(); // Spigot
+ if (this.noPhysics) {
+ this.setPos(this.getX() + p_19974_.x, this.getY() + p_19974_.y, this.getZ() + p_19974_.z);
+ } else {
+@@ -651,6 +_,7 @@
+ this.setOnGroundWithKnownMovement(this.verticalCollisionBelow, vec3);
+ BlockPos blockpos = this.getOnPosLegacy();
+ BlockState blockstate = this.level().getBlockState(blockpos);
++
+ this.checkFallDamage(vec3.y, this.onGround(), blockstate, blockpos);
+ if (this.isRemoved()) {
+ this.level().getProfiler().pop();
+@@ -665,6 +_,28 @@
+ block.updateEntityAfterFallOn(this.level(), this);
+ }
+
++ // CraftBukkit start
++ if (horizontalCollision && getBukkitEntity() instanceof Vehicle) {
++ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
++ org.bukkit.block.Block bl = this.level.getWorld().getBlockAt(Mth.floor(this.getX()), Mth.floor(this.getY()), Mth.floor(this.getZ()));
++
++ if (p_19974_.x > vec3.x) {
++ bl = bl.getRelative(BlockFace.EAST);
++ } else if (p_19974_.x < vec3.x) {
++ bl = bl.getRelative(BlockFace.WEST);
++ } else if (p_19974_.z > vec3.z) {
++ bl = bl.getRelative(BlockFace.SOUTH);
++ } else if (p_19974_.z < vec3.z) {
++ bl = bl.getRelative(BlockFace.NORTH);
++ }
++
++ if (!bl.getType().isAir()) {
++ VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl);
++ level.getCraftServer().getPluginManager().callEvent(event);
++ }
++ }
++ // CraftBukkit end
++
+ if (this.onGround()) {
+ block.stepOn(this.level(), blockpos, blockstate, this);
+ }
@@ -674,7 +_,7 @@
double d1 = vec3.x;
double d2 = vec3.y;
@@ -80,7 +374,7 @@
BlockPos blockpos1 = this.getOnPos();
BlockState blockstate1 = this.level().getBlockState(blockpos1);
boolean flag1 = this.isStateClimbable(blockstate1);
-@@ -718,16 +_,16 @@
+@@ -718,18 +_,19 @@
this.setRemainingFireTicks(-this.getFireImmuneTicks());
}
@@ -99,7 +393,10 @@
+ this.level.getProfiler().pop();
}
}
++ org.bukkit.craftbukkit.v1_20_R2.SpigotTimings.entityMoveTimer.stopTiming(); // Spigot
}
+
+ private boolean isStateClimbable(BlockState p_286733_) {
@@ -815,7 +_,7 @@
return blockpos;
} else {
@@ -125,6 +422,27 @@
Vec3 vec33 = collideBoundingBox(this, new Vec3(p_20273_.x, 0.0D, p_20273_.z), aabb.move(vec32), this.level(), list).add(vec32);
if (vec33.horizontalDistanceSqr() > vec31.horizontalDistanceSqr()) {
vec31 = vec33;
+@@ -973,6 +_,20 @@
+ return SoundEvents.GENERIC_SPLASH;
+ }
+
++ // CraftBukkit start - Add delegate methods
++ public SoundEvent getSwimSound0() {
++ return getSwimSound();
++ }
++
++ public SoundEvent getSwimSplashSound0() {
++ return getSwimSplashSound();
++ }
++
++ public SoundEvent getSwimHighSpeedSplashSound0() {
++ return getSwimHighSpeedSplashSound();
++ }
++ // CraftBukkit end
++
+ protected void checkInsideBlocks() {
+ AABB aabb = this.getBoundingBox();
+ BlockPos blockpos = BlockPos.containing(aabb.minX + 1.0E-7D, aabb.minY + 1.0E-7D, aabb.minZ + 1.0E-7D);
@@ -1039,19 +_,20 @@
return !blockstate.is(BlockTags.INSIDE_STEP_SOUND_BLOCKS) && !blockstate.is(BlockTags.COMBINATION_STEP_SOUND_BLOCKS) ? p_278049_ : blockpos;
}
@@ -253,6 +571,87 @@
}
public void moveRelative(float p_19921_, Vec3 p_19922_) {
+@@ -1349,10 +_,12 @@
+ public void absMoveTo(double p_20249_, double p_20250_, double p_20251_) {
+ double d0 = Mth.clamp(p_20249_, -3.0E7D, 3.0E7D);
+ double d1 = Mth.clamp(p_20251_, -3.0E7D, 3.0E7D);
++
+ this.xo = d0;
+ this.yo = p_20250_;
+ this.zo = d1;
+ this.setPos(d0, p_20250_, d1);
++ if (valid) level.getChunk((int) Math.floor(this.getX()) >> 4, (int) Math.floor(this.getZ()) >> 4); // CraftBukkit
+ }
+
+ public void moveTo(Vec3 p_20220_) {
+@@ -1538,6 +_,12 @@
+ return false;
+ }
+
++ // CraftBukkit start - collidable API
++ public boolean canCollideWithBukkit(Entity entity) {
++ return isPushable();
++ }
++ // CraftBukkit end
++
+ public void awardKillScore(Entity p_19953_, int p_19954_, DamageSource p_19955_) {
+ if (p_19953_ instanceof ServerPlayer) {
+ CriteriaTriggers.ENTITY_KILLED_PLAYER.trigger((ServerPlayer)p_19953_, this, p_19955_);
+@@ -1568,7 +_,7 @@
+ return false;
+ } else {
+ String s = this.getEncodeId();
+- if (s == null) {
++ if (!this.persist || s == null) { // CraftBukkit - persist flag
+ return false;
+ } else {
+ p_20087_.putString("id", s);
+@@ -1592,6 +_,18 @@
+
+ Vec3 vec3 = this.getDeltaMovement();
+ p_20241_.put("Motion", this.newDoubleList(vec3.x, vec3.y, vec3.z));
++
++ // CraftBukkit start - Checking for NaN pitch/yaw and resetting to zero
++ // TODO: make sure this is the best way to address this.
++ if (Float.isNaN(this.yRot)) {
++ this.yRot = 0;
++ }
++
++ if (Float.isNaN(this.xRot)) {
++ this.xRot = 0;
++ }
++ // CraftBukkit end
++
+ p_20241_.put("Rotation", this.newFloatList(this.getYRot(), this.getXRot()));
+ p_20241_.putFloat("FallDistance", this.fallDistance);
+ p_20241_.putShort("Fire", (short)this.remainingFireTicks);
+@@ -1600,6 +_,26 @@
+ p_20241_.putBoolean("Invulnerable", this.invulnerable);
+ p_20241_.putInt("PortalCooldown", this.portalCooldown);
+ p_20241_.putUUID("UUID", this.getUUID());
++ // CraftBukkit start
++ // PAIL: Check above UUID reads 1.8 properly, ie: UUIDMost / UUIDLeast
++ p_20241_.putLong("WorldUUIDLeast", this.level.getWorld().getUID().getLeastSignificantBits());
++ p_20241_.putLong("WorldUUIDMost", this.level.getWorld().getUID().getMostSignificantBits());
++ p_20241_.putInt("Bukkit.updateLevel", CURRENT_LEVEL);
++ if (!this.persist) {
++ p_20241_.putBoolean("Bukkit.persist", this.persist);
++ }
++ if (!this.visibleByDefault) {
++ p_20241_.putBoolean("Bukkit.visibleByDefault", this.visibleByDefault);
++ }
++ if (this.persistentInvisibility) {
++ p_20241_.putBoolean("Bukkit.invisible", this.persistentInvisibility);
++ }
++ // SPIGOT-6907: re-implement LivingEntity#setMaximumAir()
++ if (maxAirTicks != getDefaultMaxAirSupply()) {
++ p_20241_.putInt("Bukkit.MaxAirSupply", getMaxAirSupply());
++ }
++ p_20241_.putInt("Spigot.ticksLived", this.tickCount);
++ // CraftBukkit end
+ Component component = this.getCustomName();
+ if (component != null) {
+ p_20241_.putString("CustomName", Component.Serializer.toJson(component));
@@ -1630,6 +_,8 @@
p_20241_.putBoolean("HasVisualFire", this.hasVisualFire);
}
@@ -273,6 +672,18 @@
this.addAdditionalSaveData(p_20241_);
if (this.isVehicle()) {
ListTag listtag1 = new ListTag();
+@@ -1656,6 +_,11 @@
+ }
+ }
+
++ // CraftBukkit start - stores eventually existing bukkit values
++ if (this.bukkitEntity != null) {
++ this.bukkitEntity.storeBukkitValues(p_20241_);
++ }
++ // CraftBukkit end
+ return p_20241_;
+ } catch (Throwable throwable) {
+ CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
@@ -1715,6 +_,9 @@
this.setGlowingTag(p_20259_.getBoolean("Glowing"));
this.setTicksFrozen(p_20259_.getInt("TicksFrozen"));
@@ -283,10 +694,75 @@
if (p_20259_.contains("Tags", 9)) {
this.tags.clear();
ListTag listtag3 = p_20259_.getList("Tags", 8);
-@@ -1803,6 +_,8 @@
+@@ -1736,6 +_,49 @@
+ } else {
+ throw new IllegalStateException("Entity has invalid position");
+ }
++
++ // CraftBukkit start
++ // Spigot start
++ if (this instanceof LivingEntity) {
++ this.tickCount = p_20259_.getInt("Spigot.ticksLived");
++ }
++ // Spigot end
++ this.persist = !p_20259_.contains("Bukkit.persist") || p_20259_.getBoolean("Bukkit.persist");
++ this.visibleByDefault = !p_20259_.contains("Bukkit.visibleByDefault") || p_20259_.getBoolean("Bukkit.visibleByDefault");
++ // SPIGOT-6907: re-implement LivingEntity#setMaximumAir()
++ if (p_20259_.contains("Bukkit.MaxAirSupply")) {
++ maxAirTicks = p_20259_.getInt("Bukkit.MaxAirSupply");
++ }
++ // CraftBukkit end
++
++ // CraftBukkit start - Reset world
++ if (this instanceof ServerPlayer) {
++ Server server = Bukkit.getServer();
++ org.bukkit.World bworld = null;
++
++ // TODO: Remove World related checks, replaced with WorldUID
++ String worldName = p_20259_.getString("world");
++
++ if (p_20259_.contains("WorldUUIDMost") && p_20259_.contains("WorldUUIDLeast")) {
++ UUID uid = new UUID(p_20259_.getLong("WorldUUIDMost"), p_20259_.getLong("WorldUUIDLeast"));
++ bworld = server.getWorld(uid);
++ } else {
++ bworld = server.getWorld(worldName);
++ }
++
++ if (bworld == null) {
++ bworld = ((org.bukkit.craftbukkit.v1_20_R2.CraftServer) server).getServer().getLevel(Level.OVERWORLD).getWorld();
++ }
++
++ this.setLevel(bworld == null ? null : ((CraftWorld) bworld).getHandle());
++ }
++ this.getBukkitEntity().readBukkitValues(p_20259_);
++ if (p_20259_.contains("Bukkit.invisible")) {
++ boolean bukkitInvisible = p_20259_.getBoolean("Bukkit.invisible");
++ this.setInvisible(bukkitInvisible);
++ this.persistentInvisibility = bukkitInvisible;
++ }
++ // CraftBukkit end
+ } catch (Throwable throwable) {
+ CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
+ CrashReportCategory crashreportcategory = crashreport.addCategory("Entity being loaded");
+@@ -1801,8 +_,23 @@
+ } else if (this.level().isClientSide) {
+ return null;
} else {
++ // CraftBukkit start - Capture drops for death event
++ if (this instanceof LivingEntity && !((LivingEntity) this).forceDrops) {
++ ((LivingEntity) this).drops.add(org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack.asBukkitCopy(p_19985_));
++ return null;
++ }
++ // CraftBukkit end
ItemEntity itementity = new ItemEntity(this.level(), this.getX(), this.getY() + (double)p_19986_, this.getZ(), p_19985_);
itementity.setDefaultPickUpDelay();
++ // CraftBukkit start
++ EntityDropItemEvent event = new EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) itementity.getBukkitEntity());
++ Bukkit.getPluginManager().callEvent(event);
++ if (event.isCancelled()) {
++ return null;
++ }
++ // CraftBukkit end
+ if (captureDrops() != null) captureDrops().add(itementity);
+ else
this.level().addFreshEntity(itementity);
@@ -300,23 +776,97 @@
this.tick();
if (this.isPassenger()) {
this.getVehicle().positionRider(this);
-@@ -1895,6 +_,7 @@
+@@ -1895,7 +_,30 @@
}
}
-+ if (!net.minecraftforge.event.ForgeEventFactory.canMountEntity(this, p_19966_, true)) return false;
++ if (!net.minecraftforge.event.ForgeEventFactory.canMountEntity(this, p_19966_, true)) return false;
if (p_19967_ || this.canRide(p_19966_) && p_19966_.canAddPassenger(this)) {
++ // CraftBukkit start
++ if (p_19966_.getBukkitEntity() instanceof Vehicle && this.getBukkitEntity() instanceof org.bukkit.entity.LivingEntity) {
++ VehicleEnterEvent event = new VehicleEnterEvent((Vehicle) p_19966_.getBukkitEntity(), this.getBukkitEntity());
++ // Suppress during worldgen
++ if (this.valid) {
++ Bukkit.getPluginManager().callEvent(event);
++ }
++ if (event.isCancelled()) {
++ return false;
++ }
++ }
++ // CraftBukkit end
++ // Spigot start
++ org.spigotmc.event.entity.EntityMountEvent event = new org.spigotmc.event.entity.EntityMountEvent(this.getBukkitEntity(), p_19966_.getBukkitEntity());
++ // Suppress during worldgen
++ if (this.valid) {
++ Bukkit.getPluginManager().callEvent(event);
++ }
++ if (event.isCancelled()) {
++ return false;
++ }
++ // Spigot end
if (this.isPassenger()) {
this.stopRiding();
-@@ -1929,6 +_,7 @@
+ }
+@@ -1929,8 +_,9 @@
public void removeVehicle() {
if (this.vehicle != null) {
Entity entity = this.vehicle;
+ if (!net.minecraftforge.event.ForgeEventFactory.canMountEntity(this, entity, false)) return;
this.vehicle = null;
- entity.removePassenger(this);
+- entity.removePassenger(this);
++ if (!entity.removePassenger(this)) this.vehicle = entity; // CraftBukkit
}
-@@ -1981,6 +_,8 @@
+
+ }
+@@ -1960,10 +_,39 @@
+ }
+ }
+
+- protected void removePassenger(Entity p_20352_) {
++ protected boolean removePassenger(Entity p_20352_) { // CraftBukkit
+ if (p_20352_.getVehicle() == this) {
+ throw new IllegalStateException("Use x.stopRiding(y), not y.removePassenger(x)");
+ } else {
++ // CraftBukkit start
++ CraftEntity craft = (CraftEntity) p_20352_.getBukkitEntity().getVehicle();
++ Entity orig = craft == null ? null : craft.getHandle();
++ if (getBukkitEntity() instanceof Vehicle && p_20352_.getBukkitEntity() instanceof org.bukkit.entity.LivingEntity) {
++ VehicleExitEvent event = new VehicleExitEvent(
++ (Vehicle) getBukkitEntity(),
++ (org.bukkit.entity.LivingEntity) p_20352_.getBukkitEntity()
++ );
++ // Suppress during worldgen
++ if (this.valid) {
++ Bukkit.getPluginManager().callEvent(event);
++ }
++ CraftEntity craftn = (CraftEntity) p_20352_.getBukkitEntity().getVehicle();
++ Entity n = craftn == null ? null : craftn.getHandle();
++ if (event.isCancelled() || n != orig) {
++ return false;
++ }
++ }
++ // CraftBukkit end
++ // Spigot start
++ org.spigotmc.event.entity.EntityDismountEvent event = new org.spigotmc.event.entity.EntityDismountEvent(p_20352_.getBukkitEntity(), this.getBukkitEntity());
++ // Suppress during worldgen
++ if (this.valid) {
++ Bukkit.getPluginManager().callEvent(event);
++ }
++ if (event.isCancelled()) {
++ return false;
++ }
++ // Spigot end
+ if (this.passengers.size() == 1 && this.passengers.get(0) == p_20352_) {
+ this.passengers = ImmutableList.of();
+ } else {
+@@ -1975,12 +_,15 @@
+ p_20352_.boardingCooldown = 60;
+ this.gameEvent(GameEvent.ENTITY_DISMOUNT, p_20352_);
+ }
++ return true; // CraftBukkit
+ }
+
+ protected boolean canAddPassenger(Entity p_20354_) {
return this.passengers.isEmpty();
}
@@ -325,7 +875,31 @@
protected boolean couldAcceptPassenger() {
return true;
}
-@@ -2186,7 +_,7 @@
+@@ -2058,13 +_,20 @@
+ ServerLevel serverlevel = (ServerLevel)this.level();
+ if (this.isInsidePortal) {
+ MinecraftServer minecraftserver = serverlevel.getServer();
+- ResourceKey resourcekey = this.level().dimension() == Level.NETHER ? Level.OVERWORLD : Level.NETHER;
++ ResourceKey resourcekey = this.level().getTypeKey() == LevelStem.NETHER ? Level.OVERWORLD : Level.NETHER; // CraftBukkit
+ ServerLevel serverlevel1 = minecraftserver.getLevel(resourcekey);
+- if (serverlevel1 != null && minecraftserver.isNetherEnabled() && !this.isPassenger() && this.portalTime++ >= i) {
++
++ if (!this.isPassenger() && this.portalTime++ >= i) { // CraftBukkit
+ this.level().getProfiler().push("portal");
+ this.portalTime = i;
+ this.setPortalCooldown();
+- this.changeDimension(serverlevel1);
++ // CraftBukkit start
++ if (this instanceof ServerPlayer) {
++ ((ServerPlayer) this).changeDimension(serverlevel1, PlayerTeleportEvent.TeleportCause.NETHER_PORTAL);
++ } else {
++ this.changeDimension(serverlevel1);
++ }
++ // CraftBukkit end
+ this.level().getProfiler().pop();
+ }
+
+@@ -2186,10 +_,17 @@
}
public boolean isVisuallyCrawling() {
@@ -334,12 +908,102 @@
}
public void setSwimming(boolean p_20283_) {
-@@ -2296,7 +_,7 @@
- this.setSecondsOnFire(8);
- }
++ // CraftBukkit start
++ if (valid && this.isSwimming() != p_20283_ && this instanceof LivingEntity) {
++ if (CraftEventFactory.callToggleSwimEvent((LivingEntity) this, p_20283_).isCancelled()) {
++ return;
++ }
++ }
++ // CraftBukkit end
+ this.setSharedFlag(4, p_20283_);
+ }
+
+@@ -2239,8 +_,12 @@
+ return this.getTeam() != null ? this.getTeam().isAlliedTo(p_20032_) : false;
+ }
++ // CraftBukkit - start
+ public void setInvisible(boolean p_20304_) {
+- this.setSharedFlag(5, p_20304_);
++ if (!this.persistentInvisibility) { // Prevent Minecraft from removing our invisibility flag
++ this.setSharedFlag(5, p_20304_);
++ }
++ // CraftBukkit - end
+ }
+
+ protected boolean getSharedFlag(int p_20292_) {
+@@ -2258,7 +_,7 @@
+ }
+
+ public int getMaxAirSupply() {
+- return 300;
++ return maxAirTicks; // CraftBukkit - SPIGOT-6907: re-implement LivingEntity#setMaximumAir()
+ }
+
+ public int getAirSupply() {
+@@ -2266,7 +_,18 @@
+ }
+
+ public void setAirSupply(int p_20302_) {
+- this.entityData.set(DATA_AIR_SUPPLY_ID, p_20302_);
++ // CraftBukkit start
++ EntityAirChangeEvent event = new EntityAirChangeEvent(this.getBukkitEntity(), p_20302_);
++ // Suppress during worldgen
++ if (this.valid) {
++ event.getEntity().getServer().getPluginManager().callEvent(event);
++ }
++ if (event.isCancelled() && this.getAirSupply() != p_20302_) {
++ this.entityData.markDirty(Entity.DATA_AIR_SUPPLY_ID);
++ return;
++ }
++ this.entityData.set(Entity.DATA_AIR_SUPPLY_ID, event.getAmount());
++ // CraftBukkit end
+ }
+
+ public int getTicksFrozen() {
+@@ -2292,11 +_,41 @@
+
+ public void thunderHit(ServerLevel p_19927_, LightningBolt p_19928_) {
+ this.setRemainingFireTicks(this.remainingFireTicks + 1);
++ // CraftBukkit start
++ final org.bukkit.entity.Entity thisBukkitEntity = this.getBukkitEntity();
++ final org.bukkit.entity.Entity stormBukkitEntity = p_19928_.getBukkitEntity();
++ final PluginManager pluginManager = Bukkit.getPluginManager();
++ // CraftBukkit end
++
+ if (this.remainingFireTicks == 0) {
+- this.setSecondsOnFire(8);
+- }
+-
- this.hurt(this.damageSources().lightningBolt(), 5.0F);
-+ this.hurt(this.damageSources().lightningBolt(), p_19928_.getDamage());
++ // CraftBukkit start - Call a combust event when lightning strikes
++ EntityCombustByEntityEvent entityCombustEvent = new EntityCombustByEntityEvent(stormBukkitEntity, thisBukkitEntity, 8);
++ pluginManager.callEvent(entityCombustEvent);
++ if (!entityCombustEvent.isCancelled()) {
++ this.setSecondsOnFire(entityCombustEvent.getDuration(), false);
++ }
++ // CraftBukkit end
++ }
++
++ // CraftBukkit start
++ if (thisBukkitEntity instanceof Hanging) {
++ HangingBreakByEntityEvent hangingEvent = new HangingBreakByEntityEvent((Hanging) thisBukkitEntity, stormBukkitEntity);
++ pluginManager.callEvent(hangingEvent);
++
++ if (hangingEvent.isCancelled()) {
++ return;
++ }
++ }
++
++ if (this.fireImmune()) {
++ return;
++ }
++ CraftEventFactory.entityDamage = p_19928_;
++ if (!this.hurt(this.damageSources().lightningBolt(), p_19928_.getDamage())) {
++ CraftEventFactory.entityDamage = null;
++ return;
++ }
++ // CraftBukkit end
}
public void onAboveBubbleCol(boolean p_20313_) {
@@ -352,50 +1016,196 @@
}
public boolean is(Entity p_20356_) {
-@@ -2448,14 +_,20 @@
+@@ -2448,32 +_,82 @@
@Nullable
public Entity changeDimension(ServerLevel p_20118_) {
+ return this.changeDimension(p_20118_, p_20118_.getPortalForcer());
+ }
++
++ //Ketting start - bukkit function
++ private Vec3 teleportTo$location;
++ @Nullable
++ public Entity teleportTo(ServerLevel worldserver, Vec3 location) {
++ try {
++ this.teleportTo$location = location;
++ return this.changeDimension(worldserver, worldserver.getPortalForcer());
++ } finally {
++ this.teleportTo$location = null;
++ }
++ }
++ //Ketting end
++
+ @Nullable
+ public Entity changeDimension(ServerLevel p_20118_, net.minecraftforge.common.util.ITeleporter teleporter) {
+ if (net.minecraftforge.event.ForgeEventFactory.onTravelToDimension(this, p_20118_.dimension())) return null;
if (this.level() instanceof ServerLevel && !this.isRemoved()) {
this.level().getProfiler().push("changeDimension");
- this.unRide();
+- this.unRide();
++ // CraftBukkit start
++ // this.unRide();
++ if (p_20118_ == null) {
++ return null;
++ }
++ // CraftBukkit end
this.level().getProfiler().push("reposition");
- PortalInfo portalinfo = this.findDimensionEntryPoint(p_20118_);
-+ PortalInfo portalinfo = teleporter.getPortalInfo(this, p_20118_, this::findDimensionEntryPoint);
++ PortalInfo portalinfo = (teleportTo$location == null) ? teleporter.getPortalInfo(this, p_20118_, this::findDimensionEntryPoint) : new PortalInfo(new Vec3(teleportTo$location.x(), teleportTo$location.y(), teleportTo$location.z()), Vec3.ZERO, this.yRot, this.xRot, p_20118_, null);
++
if (portalinfo == null) {
return null;
} else {
-+ Entity transportedEntity = teleporter.placeEntity(this, (ServerLevel) this.level, p_20118_, this.yRot, spawnPortal -> { //Forge: Start vanilla logic
- this.level().getProfiler().popPush("reloading");
- Entity entity = this.getType().create(p_20118_);
- if (entity != null) {
-@@ -2463,17 +_,19 @@
- entity.moveTo(portalinfo.pos.x, portalinfo.pos.y, portalinfo.pos.z, portalinfo.yRot, entity.getXRot());
- entity.setDeltaMovement(portalinfo.speed);
- p_20118_.addDuringTeleport(entity);
+- this.level().getProfiler().popPush("reloading");
+- Entity entity = this.getType().create(p_20118_);
+- if (entity != null) {
+- entity.restoreFrom(this);
+- entity.moveTo(portalinfo.pos.x, portalinfo.pos.y, portalinfo.pos.z, portalinfo.yRot, entity.getXRot());
+- entity.setDeltaMovement(portalinfo.speed);
+- p_20118_.addDuringTeleport(entity);
- if (p_20118_.dimension() == Level.END) {
-+ if (spawnPortal && p_20118_.dimension() == Level.END) {
- ServerLevel.makeObsidianPlatform(p_20118_);
- }
+- ServerLevel.makeObsidianPlatform(p_20118_);
+- }
++ // CraftBukkit start
++ p_20118_ = portalinfo.world;
++ if (p_20118_ == level) {
++ // SPIGOT-6782: Just move the entity if a plugin changed the world to the one the entity is already in
++ moveTo(portalinfo.pos.x, portalinfo.pos.y, portalinfo.pos.z, portalinfo.yRot, portalinfo.xRot);
++ setDeltaMovement(portalinfo.speed);
++ return this;
}
-+ return entity;
++ this.unRide();
++ // CraftBukkit end
++
++ final ServerLevel finalLevel = p_20118_; //Ketting
++
++ Entity transportedEntity = teleporter.placeEntity(this, (ServerLevel) this.level, finalLevel, this.yRot, spawnPortal -> { //Forge: Start vanilla logic
++ this.level().getProfiler().popPush("reloading");
++ Entity entity = this.getType().create(finalLevel);
++ if (entity != null) {
++ entity.restoreFrom(this);
++ entity.moveTo(portalinfo.pos.x, portalinfo.pos.y, portalinfo.pos.z, portalinfo.yRot, entity.getXRot());
++ entity.setDeltaMovement(portalinfo.speed);
++ finalLevel.addDuringTeleport(entity);
++ if (spawnPortal && finalLevel.getTypeKey() == LevelStem.END) { // CraftBukkit
++ ServerLevel.makeObsidianPlatform(finalLevel, this); // CraftBukkit
++ }
++
++ // CraftBukkit start - Forward the CraftEntity to the new entity
++ this.getBukkitEntity().setHandle(entity);
++ entity.bukkitEntity = this.getBukkitEntity();
++
++ if (this instanceof Mob) {
++ ((Mob) this).dropLeash(true, false); // Unleash to prevent duping of leads.
++ }
++ // CraftBukkit end
++ }
++ return entity;
+ }); //Forge: End vanilla logic
this.removeAfterChangingDimensions();
this.level().getProfiler().pop();
((ServerLevel)this.level()).resetEmptyTime();
- p_20118_.resetEmptyTime();
+- p_20118_.resetEmptyTime();
++ finalLevel.resetEmptyTime();
this.level().getProfiler().pop();
- return entity;
+ return transportedEntity;
}
} else {
return null;
+@@ -2486,17 +_,34 @@
+
+ @Nullable
+ protected PortalInfo findDimensionEntryPoint(ServerLevel p_19923_) {
+- boolean flag = this.level().dimension() == Level.END && p_19923_.dimension() == Level.OVERWORLD;
+- boolean flag1 = p_19923_.dimension() == Level.END;
++ // CraftBukkit start
++ if (p_19923_ == null) {
++ return null;
++ }
++ boolean flag = this.level().getTypeKey() == LevelStem.END && p_19923_.getTypeKey() == LevelStem.OVERWORLD; // fromEndToOverworld
++ boolean flag1 = p_19923_.getTypeKey() == LevelStem.END; // targetIsEnd
++ // CraftBukkit end
++
+ if (!flag && !flag1) {
+- boolean flag2 = p_19923_.dimension() == Level.NETHER;
+- if (this.level().dimension() != Level.NETHER && !flag2) {
++ boolean flag2 = p_19923_.getTypeKey() == LevelStem.NETHER; // CraftBukkit
++
++ if (this.level().getTypeKey() != LevelStem.NETHER && !flag2) { // CraftBukkit
+ return null;
+ } else {
+ WorldBorder worldborder = p_19923_.getWorldBorder();
+ double d0 = DimensionType.getTeleportationScale(this.level().dimensionType(), p_19923_.dimensionType());
+ BlockPos blockpos1 = worldborder.clampToBounds(this.getX() * d0, this.getY(), this.getZ() * d0);
+- return this.getExitPortal(p_19923_, blockpos1, flag2, worldborder).map((p_258249_) -> {
++ // CraftBukkit start
++ CraftPortalEvent event = callPortalEvent(this, p_19923_, new Vec3(blockpos1.getX(), blockpos1.getY(), blockpos1.getZ()), PlayerTeleportEvent.TeleportCause.NETHER_PORTAL, flag2 ? 16 : 128, 16);
++ if (event == null) {
++ return null;
++ }
++ final ServerLevel worldserverFinal = p_19923_ = ((CraftWorld) event.getTo().getWorld()).getHandle();
++ worldborder = worldserverFinal.getWorldBorder();
++ blockpos1 = worldborder.clampToBounds(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ());
++
++ return this.getExitPortal(p_19923_, blockpos1, flag2, worldborder, event.getSearchRadius(), event.getCanCreatePortal(), event.getCreationRadius()).map((p_258249_) -> {
++ // CraftBukkit end
+ BlockState blockstate = this.level().getBlockState(this.portalEntrancePos);
+ Direction.Axis direction$axis;
+ Vec3 vec3;
+@@ -2511,8 +_,8 @@
+ vec3 = new Vec3(0.5D, 0.0D, 0.0D);
+ }
+
+- return PortalShape.createPortalInfo(p_19923_, p_258249_, direction$axis, vec3, this, this.getDeltaMovement(), this.getYRot(), this.getXRot());
+- }).orElse((PortalInfo)null);
++ return PortalShape.createPortalInfo(worldserverFinal, p_258249_, direction$axis, vec3, this, this.getDeltaMovement(), this.getYRot(), this.getXRot(), event); // CraftBukkit
++ }).orElse(null);
+ }
+ } else {
+ BlockPos blockpos;
+@@ -2522,7 +_,14 @@
+ blockpos = p_19923_.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, p_19923_.getSharedSpawnPos());
+ }
+
+- return new PortalInfo(new Vec3((double)blockpos.getX() + 0.5D, (double)blockpos.getY(), (double)blockpos.getZ() + 0.5D), this.getDeltaMovement(), this.getYRot(), this.getXRot());
++ // CraftBukkit start
++ CraftPortalEvent event = callPortalEvent(this, p_19923_, new Vec3(blockpos.getX() + 0.5D, blockpos.getY(), blockpos.getZ() + 0.5D), PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0);
++ if (event == null) {
++ return null;
++ }
++
++ return new PortalInfo(new Vec3(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()), this.getDeltaMovement(), this.getYRot(), this.getXRot(), ((CraftWorld) event.getTo().getWorld()).getHandle(), event);
++ // CraftBukkit end
+ }
+ }
+
+@@ -2530,8 +_,23 @@
+ return PortalShape.getRelativePosition(p_20046_, p_20045_, this.position(), this.getDimensions(this.getPose()));
+ }
+
+- protected Optional getExitPortal(ServerLevel p_185935_, BlockPos p_185936_, boolean p_185937_, WorldBorder p_185938_) {
+- return p_185935_.getPortalForcer().findPortalAround(p_185936_, p_185937_, p_185938_);
++ // CraftBukkit start
++ protected CraftPortalEvent callPortalEvent(Entity entity, ServerLevel exitWorldServer, Vec3 exitPosition, PlayerTeleportEvent.TeleportCause cause, int searchRadius, int creationRadius) {
++ org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity();
++ Location enter = bukkitEntity.getLocation();
++ Location exit = CraftLocation.toBukkit(exitPosition, exitWorldServer.getWorld());
++
++ EntityPortalEvent event = new EntityPortalEvent(bukkitEntity, enter, exit, searchRadius);
++ event.getEntity().getServer().getPluginManager().callEvent(event);
++ if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null || !entity.isAlive()) {
++ return null;
++ }
++ return new CraftPortalEvent(event);
++ }
++
++ protected Optional getExitPortal(ServerLevel p_185935_, BlockPos p_185936_, boolean p_185937_, WorldBorder p_185938_, int searchRadius, boolean canCreatePortal, int createRadius) {
++ return p_185935_.getPortalForcer().findPortalAround(p_185936_, p_185938_, searchRadius);
++ // CraftBukkit end
+ }
+
+ public boolean canChangeDimensions() {
@@ -2595,6 +_,7 @@
return this.stringUUID;
}
@@ -412,6 +1222,47 @@
public final void teleportToWithTicket(double p_20325_, double p_20326_, double p_20327_) {
if (this.level() instanceof ServerLevel) {
ChunkPos chunkpos = new ChunkPos(BlockPos.containing(p_20325_, p_20326_, p_20327_));
+@@ -2643,6 +_,12 @@
+ }
+ }
+
++ // CraftBukkit start
++ public boolean teleportTo(ServerLevel worldserver, double d0, double d1, double d2, Set set, float f, float f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
++ return this.teleportTo(worldserver, d0, d1, d2, set, f, f1);
++ }
++ // CraftBukkit end
++
+ public boolean teleportTo(ServerLevel p_265257_, double p_265407_, double p_265727_, double p_265410_, Set p_265083_, float p_265573_, float p_265094_) {
+ float f = Mth.clamp(p_265094_, -90.0F, 90.0F);
+ if (p_265257_ == this.level()) {
+@@ -2758,7 +_,26 @@
+ }
+
+ public final void setBoundingBox(AABB p_20012_) {
+- this.bb = p_20012_;
++ // CraftBukkit start - block invalid bounding boxes
++ double minX = p_20012_.minX,
++ minY = p_20012_.minY,
++ minZ = p_20012_.minZ,
++ maxX = p_20012_.maxX,
++ maxY = p_20012_.maxY,
++ maxZ = p_20012_.maxZ;
++ double len = p_20012_.maxX - p_20012_.minX;
++ if (len < 0) maxX = minX;
++ if (len > 64) maxX = minX + 64.0;
++
++ len = p_20012_.maxY - p_20012_.minY;
++ if (len < 0) maxY = minY;
++ if (len > 64) maxY = minY + 64.0;
++
++ len = p_20012_.maxZ - p_20012_.minZ;
++ if (len < 0) maxZ = minZ;
++ if (len > 64) maxZ = minZ + 64.0;
++ this.bb = new AABB(minX, minY, minZ, maxX, maxY, maxZ);
++ // CraftBukkit end
+ }
+
+ protected float getEyeHeight(Pose p_19976_, EntityDimensions p_19977_) {
@@ -3010,9 +_,22 @@
this.yRotO = this.getYRot();
}
@@ -436,7 +1287,7 @@
} else {
AABB aabb = this.getBoundingBox().deflate(0.001D);
int i = Mth.floor(aabb.minX);
-@@ -3027,25 +_,28 @@
+@@ -3027,53 +_,63 @@
Vec3 vec3 = Vec3.ZERO;
int k1 = 0;
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
@@ -467,12 +1318,19 @@
- vec3 = vec3.add(vec31);
- ++k1;
+- }
+ interim.setMiddle(interim.getMiddle().add(vec31));
+ interim.setRight(interim.getRight() + 1);
- }
++ }
++
++ // CraftBukkit start - store last lava contact location
++ if (fluidstate.is(FluidTags.LAVA)) {
++ this.lastLavaContact = blockpos$mutableblockpos.immutable();
++ }
++ // CraftBukkit end
}
}
-@@ -3053,27 +_,28 @@
+ }
}
}
diff --git a/patches/minecraft/net/minecraft/world/entity/EntitySelector.java.patch b/patches/minecraft/net/minecraft/world/entity/EntitySelector.java.patch
new file mode 100644
index 0000000000..2622a3a70e
--- /dev/null
+++ b/patches/minecraft/net/minecraft/world/entity/EntitySelector.java.patch
@@ -0,0 +1,11 @@
+--- a/net/minecraft/world/entity/EntitySelector.java
++++ b/net/minecraft/world/entity/EntitySelector.java
+@@ -41,7 +_,7 @@
+ Team team = p_20422_.getTeam();
+ Team.CollisionRule team$collisionrule = team == null ? Team.CollisionRule.ALWAYS : team.getCollisionRule();
+ return (Predicate)(team$collisionrule == Team.CollisionRule.NEVER ? Predicates.alwaysFalse() : NO_SPECTATORS.and((p_20430_) -> {
+- if (!p_20430_.isPushable()) {
++ if (!p_20430_.canCollideWithBukkit(p_20422_) || !p_20422_.canCollideWithBukkit(p_20430_)) { // CraftBukkit - collidable API
+ return false;
+ } else if (!p_20422_.level().isClientSide || p_20430_ instanceof Player && ((Player)p_20430_).isLocalPlayer()) {
+ Team team1 = p_20430_.getTeam();
diff --git a/patches/minecraft/net/minecraft/world/entity/EntityType.java.patch b/patches/minecraft/net/minecraft/world/entity/EntityType.java.patch
index 83129609ec..9d0ba9e9b7 100644
--- a/patches/minecraft/net/minecraft/world/entity/EntityType.java.patch
+++ b/patches/minecraft/net/minecraft/world/entity/EntityType.java.patch
@@ -1,5 +1,14 @@
--- a/net/minecraft/world/entity/EntityType.java
+++ b/net/minecraft/world/entity/EntityType.java
+@@ -167,7 +_,7 @@
+ private static final float MAGIC_HORSE_WIDTH = 1.3964844F;
+ private static final int DISPLAY_TRACKING_RANGE = 10;
+ public static final EntityType ALLAY = register("allay", EntityType.Builder.of(Allay::new, MobCategory.CREATURE).sized(0.35F, 0.6F).clientTrackingRange(8).updateInterval(2));
+- public static final EntityType AREA_EFFECT_CLOUD = register("area_effect_cloud", EntityType.Builder.of(AreaEffectCloud::new, MobCategory.MISC).fireImmune().sized(6.0F, 0.5F).clientTrackingRange(10).updateInterval(Integer.MAX_VALUE));
++ public static final EntityType AREA_EFFECT_CLOUD = register("area_effect_cloud", EntityType.Builder.of(AreaEffectCloud::new, MobCategory.MISC).fireImmune().sized(6.0F, 0.5F).clientTrackingRange(10).updateInterval(10)); // CraftBukkit - SPIGOT-3729: track area effect clouds
+ public static final EntityType ARMOR_STAND = register("armor_stand", EntityType.Builder.of(ArmorStand::new, MobCategory.MISC).sized(0.5F, 1.975F).clientTrackingRange(10));
+ public static final EntityType ARROW = register("arrow", EntityType.Builder.of(Arrow::new, MobCategory.MISC).sized(0.5F, 0.5F).clientTrackingRange(4).updateInterval(20));
+ public static final EntityType AXOLOTL = register("axolotl", EntityType.Builder.of(Axolotl::new, MobCategory.AXOLOTLS).sized(0.75F, 0.42F).clientTrackingRange(10));
@@ -308,6 +_,11 @@
private final EntityDimensions dimensions;
private final FeatureFlagSet requiredFeatures;
@@ -12,7 +21,7 @@
private static EntityType register(String p_20635_, EntityType.Builder p_20636_) {
return Registry.register(BuiltInRegistries.ENTITY_TYPE, p_20635_, p_20636_.build(p_20635_));
}
-@@ -321,17 +_,24 @@
+@@ -321,21 +_,34 @@
}
public EntityType(EntityType.EntityFactory p_273268_, MobCategory p_272918_, boolean p_273417_, boolean p_273389_, boolean p_273556_, boolean p_272654_, ImmutableSet p_273631_, EntityDimensions p_272946_, int p_272895_, int p_273451_, FeatureFlagSet p_273518_) {
@@ -47,7 +56,71 @@
+ this.customClientFactory = customClientFactory;
}
+- @Nullable
+ public T spawn(ServerLevel p_20593_, @Nullable ItemStack p_20594_, @Nullable Player p_20595_, BlockPos p_20596_, MobSpawnType p_20597_, boolean p_20598_, boolean p_20599_) {
++ // CraftBukkit start
++ return this.spawn(p_20593_, p_20594_, p_20595_, p_20596_, p_20597_, p_20598_, p_20599_, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG);
++ }
++
++ @Nullable
++ public T spawn(ServerLevel p_20593_, @Nullable ItemStack p_20594_, @Nullable Player p_20595_, BlockPos p_20596_, MobSpawnType p_20597_, boolean p_20598_, boolean p_20599_, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
++ // CraftBukkit end
+ Consumer consumer;
+ CompoundTag compoundtag;
+ if (p_20594_ != null) {
+@@ -347,7 +_,7 @@
+ compoundtag = null;
+ }
+
+- return this.spawn(p_20593_, compoundtag, consumer, p_20596_, p_20597_, p_20598_, p_20599_);
++ return this.spawn(p_20593_, compoundtag, consumer, p_20596_, p_20597_, p_20598_, p_20599_, spawnReason); // CraftBukkit end
+ }
+
+ public static Consumer createDefaultStackConfig(ServerLevel p_263583_, ItemStack p_263568_, @Nullable Player p_263575_) {
+@@ -368,20 +_,36 @@
+ public static Consumer appendCustomEntityStackConfig(Consumer p_263579_, ServerLevel p_263571_, ItemStack p_263582_, @Nullable Player p_263574_) {
+ CompoundTag compoundtag = p_263582_.getTag();
+ return compoundtag != null ? p_263579_.andThen((p_262558_) -> {
+- updateCustomEntityTag(p_263571_, p_263574_, p_262558_, compoundtag);
++ try { updateCustomEntityTag(p_263571_, p_263574_, p_262558_, compoundtag); } catch (Throwable t) { LOGGER.warn("Error loading spawn egg NBT", t); } // CraftBukkit - SPIGOT-5665
+ }) : p_263579_;
+ }
+
@Nullable
+ public T spawn(ServerLevel p_262634_, BlockPos p_262707_, MobSpawnType p_262597_) {
+- return this.spawn(p_262634_, (CompoundTag)null, (Consumer)null, p_262707_, p_262597_, false, false);
+- }
+-
+- @Nullable
+- public T spawn(ServerLevel p_262704_, @Nullable CompoundTag p_262603_, @Nullable Consumer p_262621_, BlockPos p_262672_, MobSpawnType p_262644_, boolean p_262690_, boolean p_262590_) {
++ // CraftBukkit start
++ return this.spawn(p_262634_, p_262707_, p_262597_, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
++ }
++
++ @Nullable
++ public T spawn(ServerLevel worldserver, BlockPos blockposition, MobSpawnType enummobspawn, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
++ return this.spawn(worldserver, (CompoundTag) null, null, blockposition, enummobspawn, false, false, spawnReason); // CraftBukkit - decompile error
++ // CraftBukkit end
++ }
++
++ @Nullable
++ public T spawn(ServerLevel worldserver, @Nullable CompoundTag nbttagcompound, @Nullable Consumer consumer, BlockPos blockposition, MobSpawnType enummobspawn, boolean flag, boolean flag1) {
++ // CraftBukkit start
++ return this.spawn(worldserver, nbttagcompound, consumer, blockposition, enummobspawn, flag, flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
++ }
++
++ @Nullable
++ public T spawn(ServerLevel p_262704_, @Nullable CompoundTag p_262603_, @Nullable Consumer p_262621_, BlockPos p_262672_, MobSpawnType p_262644_, boolean p_262690_, boolean p_262590_, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
++ // CraftBukkit end
+ T t = this.create(p_262704_, p_262603_, p_262621_, p_262672_, p_262644_, p_262690_, p_262590_);
+ if (t != null) {
+- p_262704_.addFreshEntityWithPassengers(t);
++ p_262704_.addFreshEntityWithPassengers(t, spawnReason);
++ return !t.isRemoved() ? t : null; // Don't return an entity when CreatureSpawnEvent is canceled
++ // CraftBukkit end
+ }
+
+ return t;
@@ -601,14 +_,23 @@
}
diff --git a/patches/minecraft/net/minecraft/world/entity/ExperienceOrb.java.patch b/patches/minecraft/net/minecraft/world/entity/ExperienceOrb.java.patch
index 5c6a4677a8..059a9bcb95 100644
--- a/patches/minecraft/net/minecraft/world/entity/ExperienceOrb.java.patch
+++ b/patches/minecraft/net/minecraft/world/entity/ExperienceOrb.java.patch
@@ -1,5 +1,47 @@
--- a/net/minecraft/world/entity/ExperienceOrb.java
+++ b/net/minecraft/world/entity/ExperienceOrb.java
+@@ -19,6 +_,9 @@
+ import net.minecraft.world.level.entity.EntityTypeTest;
+ import net.minecraft.world.phys.AABB;
+ import net.minecraft.world.phys.Vec3;
++import org.bukkit.craftbukkit.v1_20_R2.event.CraftEventFactory;
++import org.bukkit.event.entity.EntityTargetEvent;
++import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
+
+ public class ExperienceOrb extends Entity {
+ private static final int LIFETIME = 6000;
+@@ -53,6 +_,7 @@
+
+ public void tick() {
+ super.tick();
++ Player prevTarget = this.followingPlayer;// CraftBukkit - store old target
+ this.xo = this.getX();
+ this.yo = this.getY();
+ this.zo = this.getZ();
+@@ -78,7 +_,22 @@
+ this.followingPlayer = null;
+ }
+
+- if (this.followingPlayer != null) {
++ // CraftBukkit start
++ boolean cancelled = false;
++ if (this.followingPlayer != prevTarget) {
++ EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent(this, followingPlayer, (followingPlayer != null) ? EntityTargetEvent.TargetReason.CLOSEST_PLAYER : EntityTargetEvent.TargetReason.FORGOT_TARGET);
++ LivingEntity target = (event.getTarget() == null) ? null : ((org.bukkit.craftbukkit.v1_20_R2.entity.CraftLivingEntity) event.getTarget()).getHandle();
++ cancelled = event.isCancelled();
++
++ if (cancelled) {
++ followingPlayer = prevTarget;
++ } else {
++ followingPlayer = (target instanceof Player) ? (Player) target : null;
++ }
++ }
++
++ if (this.followingPlayer != null && !cancelled) {
++ // CraftBukkit end
+ Vec3 vec3 = new Vec3(this.followingPlayer.getX() - this.getX(), this.followingPlayer.getY() + (double)this.followingPlayer.getEyeHeight() / 2.0D - this.getY(), this.followingPlayer.getZ() - this.getZ());
+ double d0 = vec3.lengthSqr();
+ if (d0 < 64.0D) {
@@ -90,7 +_,8 @@
this.move(MoverType.SELF, this.getDeltaMovement());
float f = 0.98F;
@@ -18,7 +60,7 @@
if (this.isInvulnerableTo(p_20785_)) {
return false;
} else if (this.level().isClientSide) {
-@@ -204,6 +_,7 @@
+@@ -204,11 +_,13 @@
public void playerTouch(Player p_20792_) {
if (!this.level().isClientSide) {
if (p_20792_.takeXpDelay == 0) {
@@ -26,12 +68,56 @@
p_20792_.takeXpDelay = 2;
p_20792_.take(this, 1);
int i = this.repairPlayerItems(p_20792_, this.value);
-@@ -224,7 +_,7 @@
++
+ if (i > 0) {
+- p_20792_.giveExperiencePoints(i);
++ p_20792_.giveExperiencePoints(CraftEventFactory.callPlayerExpChangeEvent(p_20792_, i).getAmount()); // CraftBukkit - this.value -> event.getAmount()
+ }
+
+ --this.count;
+@@ -224,9 +_,19 @@
Map.Entry entry = EnchantmentHelper.getRandomItemWith(Enchantments.MENDING, p_147093_, ItemStack::isDamaged);
if (entry != null) {
ItemStack itemstack = entry.getValue();
- int i = Math.min(this.xpToDurability(this.value), itemstack.getDamageValue());
+ int i = Math.min((int) (this.value * itemstack.getXpRepairRatio()), itemstack.getDamageValue());
++ // CraftBukkit start
++ org.bukkit.event.player.PlayerItemMendEvent event = CraftEventFactory.callPlayerItemMendEvent(p_147093_, this, itemstack, entry.getKey(), i);
++ i = event.getRepairAmount();
++ if (event.isCancelled()) {
++ return p_147094_;
++ }
++ // CraftBukkit end
++
itemstack.setDamageValue(itemstack.getDamageValue() - i);
int j = p_147094_ - this.durabilityToXp(i);
++ this.value = j; // CraftBukkit - update exp value of orb for PlayerItemMendEvent calls
++
return j > 0 ? this.repairPlayerItems(p_147093_, j) : 0;
+ } else {
+ return p_147094_;
+@@ -270,6 +_,24 @@
+ }
+
+ public static int getExperienceValue(int p_20783_) {
++ // CraftBukkit start
++ if (p_20783_ > 162670129) return p_20783_ - 100000;
++ if (p_20783_ > 81335063) return 81335063;
++ if (p_20783_ > 40667527) return 40667527;
++ if (p_20783_ > 20333759) return 20333759;
++ if (p_20783_ > 10166857) return 10166857;
++ if (p_20783_ > 5083423) return 5083423;
++ if (p_20783_ > 2541701) return 2541701;
++ if (p_20783_ > 1270849) return 1270849;
++ if (p_20783_ > 635413) return 635413;
++ if (p_20783_ > 317701) return 317701;
++ if (p_20783_ > 158849) return 158849;
++ if (p_20783_ > 79423) return 79423;
++ if (p_20783_ > 39709) return 39709;
++ if (p_20783_ > 19853) return 19853;
++ if (p_20783_ > 9923) return 9923;
++ if (p_20783_ > 4957) return 4957;
++ // CraftBukkit end
+ if (p_20783_ >= 2477) {
+ return 2477;
+ } else if (p_20783_ >= 1237) {
diff --git a/patches/minecraft/net/minecraft/world/entity/Interaction.java.patch b/patches/minecraft/net/minecraft/world/entity/Interaction.java.patch
new file mode 100644
index 0000000000..81b682dbf8
--- /dev/null
+++ b/patches/minecraft/net/minecraft/world/entity/Interaction.java.patch
@@ -0,0 +1,35 @@
+--- a/net/minecraft/world/entity/Interaction.java
++++ b/net/minecraft/world/entity/Interaction.java
+@@ -16,10 +_,13 @@
+ import net.minecraft.server.level.ServerPlayer;
+ import net.minecraft.world.InteractionHand;
+ import net.minecraft.world.InteractionResult;
++import net.minecraft.world.damagesource.DamageSource;
+ import net.minecraft.world.entity.player.Player;
+ import net.minecraft.world.level.Level;
+ import net.minecraft.world.level.material.PushReaction;
+ import net.minecraft.world.phys.AABB;
++import org.bukkit.craftbukkit.v1_20_R2.event.CraftEventFactory;
++import org.bukkit.event.entity.EntityDamageEvent;
+ import org.slf4j.Logger;
+
+ public class Interaction extends Entity implements Attackable, Targeting {
+@@ -121,9 +_,17 @@
+
+ public boolean skipAttackInteraction(Entity p_273553_) {
+ if (p_273553_ instanceof Player player) {
++ // CraftBukkit start
++ DamageSource source = player.damageSources().playerAttack(player);
++ EntityDamageEvent event = CraftEventFactory.callNonLivingEntityDamageEvent(this, source, 1.0F, false);
++ if (event.isCancelled()) {
++ return true;
++ }
++ // CraftBukkit end
++
+ this.attack = new Interaction.PlayerAction(player.getUUID(), this.level().getGameTime());
+ if (player instanceof ServerPlayer serverplayer) {
+- CriteriaTriggers.PLAYER_HURT_ENTITY.trigger(serverplayer, this, player.damageSources().generic(), 1.0F, 1.0F, false);
++ CriteriaTriggers.PLAYER_HURT_ENTITY.trigger(serverplayer, this, source, (float) event.getFinalDamage(), 1.0F, false); // CraftBukkit
+ }
+
+ return !this.getResponse();
diff --git a/patches/minecraft/net/minecraft/world/entity/ItemBasedSteering.java.patch b/patches/minecraft/net/minecraft/world/entity/ItemBasedSteering.java.patch
new file mode 100644
index 0000000000..633746636a
--- /dev/null
+++ b/patches/minecraft/net/minecraft/world/entity/ItemBasedSteering.java.patch
@@ -0,0 +1,32 @@
+--- a/net/minecraft/world/entity/ItemBasedSteering.java
++++ b/net/minecraft/world/entity/ItemBasedSteering.java
+@@ -12,8 +_,8 @@
+ private final SynchedEntityData entityData;
+ private final EntityDataAccessor boostTimeAccessor;
+ private final EntityDataAccessor hasSaddleAccessor;
+- private boolean boosting;
+- private int boostTime;
++ public boolean boosting;
++ public int boostTime;
+
+ public ItemBasedSteering(SynchedEntityData p_20841_, EntityDataAccessor p_20842_, EntityDataAccessor p_20843_) {
+ this.entityData = p_20841_;
+@@ -48,9 +_,17 @@
+ return this.boosting ? 1.0F + 1.15F * Mth.sin((float)this.boostTime / (float)this.boostTimeTotal() * (float)Math.PI) : 1.0F;
+ }
+
+- private int boostTimeTotal() {
++ public int boostTimeTotal() {
+ return this.entityData.get(this.boostTimeAccessor);
+ }
++
++ // CraftBukkit add setBoostTicks(int)
++ public void setBoostTicks(int ticks) {
++ this.boosting = true;
++ this.boostTime = 0;
++ this.entityData.set(this.boostTimeAccessor, ticks);
++ }
++ // CraftBukkit end
+
+ public void addAdditionalSaveData(CompoundTag p_20848_) {
+ p_20848_.putBoolean("Saddle", this.hasSaddle());
diff --git a/patches/minecraft/net/minecraft/world/entity/LightningBolt.java.patch b/patches/minecraft/net/minecraft/world/entity/LightningBolt.java.patch
index 5e0a51c5ce..e97265da24 100644
--- a/patches/minecraft/net/minecraft/world/entity/LightningBolt.java.patch
+++ b/patches/minecraft/net/minecraft/world/entity/LightningBolt.java.patch
@@ -1,14 +1,32 @@
--- a/net/minecraft/world/entity/LightningBolt.java
+++ b/net/minecraft/world/entity/LightningBolt.java
-@@ -37,6 +_,7 @@
+@@ -24,19 +_,22 @@
+ import net.minecraft.world.level.gameevent.GameEvent;
+ import net.minecraft.world.phys.AABB;
+ import net.minecraft.world.phys.Vec3;
++import org.bukkit.craftbukkit.v1_20_R2.event.CraftEventFactory;
+
+ public class LightningBolt extends Entity {
+ private static final int START_LIFE = 2;
+ private static final double DAMAGE_RADIUS = 3.0D;
+ private static final double DETECTION_RADIUS = 15.0D;
+- private int life;
++ public int life;
+ public long seed;
+- private int flashes;
+- private boolean visualOnly;
++ public int flashes;
++ public boolean visualOnly;
+ @Nullable
private ServerPlayer cause;
private final Set hitEntities = Sets.newHashSet();
private int blocksSetOnFire;
+ private float damage = 5.0F;
++ public boolean isSilent = false; // Spigot
public LightningBolt(EntityType extends LightningBolt> p_20865_, Level p_20866_) {
super(p_20865_, p_20866_);
-@@ -72,6 +_,14 @@
+@@ -72,9 +_,17 @@
}
@@ -22,8 +40,20 @@
+
public void tick() {
super.tick();
- if (this.life == 2) {
-@@ -121,6 +_,7 @@
+- if (this.life == 2) {
++ if (!isSilent && this.life == 2) { // Spigot
+ if (this.level().isClientSide()) {
+ this.level().playLocalSound(this.getX(), this.getY(), this.getZ(), SoundEvents.LIGHTNING_BOLT_THUNDER, SoundSource.WEATHER, 10000.0F, 0.8F + this.random.nextFloat() * 0.2F, false);
+ this.level().playLocalSound(this.getX(), this.getY(), this.getZ(), SoundEvents.LIGHTNING_BOLT_IMPACT, SoundSource.WEATHER, 2.0F, 0.5F + this.random.nextFloat() * 0.2F, false);
+@@ -114,13 +_,14 @@
+ }
+ }
+
+- if (this.life >= 0) {
++ if (this.life >= 0 && !this.visualOnly) { // CraftBukkit - add !this.visualOnly
+ if (!(this.level() instanceof ServerLevel)) {
+ this.level().setSkyFlashTime(2);
+ } else if (!this.visualOnly) {
List list1 = this.level().getEntities(this, new AABB(this.getX() - 3.0D, this.getY() - 3.0D, this.getZ() - 3.0D, this.getX() + 3.0D, this.getY() + 6.0D + 3.0D, this.getZ() + 3.0D), Entity::isAlive);
for(Entity entity : list1) {
@@ -31,3 +61,34 @@
entity.thunderHit((ServerLevel)this.level(), this);
}
+@@ -142,17 +_,26 @@
+ if (!this.visualOnly && !this.level().isClientSide && this.level().getGameRules().getBoolean(GameRules.RULE_DOFIRETICK)) {
+ BlockPos blockpos = this.blockPosition();
+ BlockState blockstate = BaseFireBlock.getState(this.level(), blockpos);
++
+ if (this.level().getBlockState(blockpos).isAir() && blockstate.canSurvive(this.level(), blockpos)) {
+- this.level().setBlockAndUpdate(blockpos, blockstate);
+- ++this.blocksSetOnFire;
++ // CraftBukkit start - add "!visualOnly"
++ if (!visualOnly && !CraftEventFactory.callBlockIgniteEvent(this.level(), blockpos, this).isCancelled()) {
++ this.level().setBlockAndUpdate(blockpos, blockstate);
++ ++this.blocksSetOnFire;
++ }
++ // CraftBukkit end
+ }
+
+ for(int i = 0; i < p_20871_; ++i) {
+ BlockPos blockpos1 = blockpos.offset(this.random.nextInt(3) - 1, this.random.nextInt(3) - 1, this.random.nextInt(3) - 1);
+ blockstate = BaseFireBlock.getState(this.level(), blockpos1);
+ if (this.level().getBlockState(blockpos1).isAir() && blockstate.canSurvive(this.level(), blockpos1)) {
+- this.level().setBlockAndUpdate(blockpos1, blockstate);
+- ++this.blocksSetOnFire;
++ // CraftBukkit start - add "!visualOnly"
++ if (!visualOnly && !CraftEventFactory.callBlockIgniteEvent(this.level(), blockpos1, this).isCancelled()) {
++ this.level().setBlockAndUpdate(blockpos1, blockstate);
++ ++this.blocksSetOnFire;
++ }
++ // CraftBukkit end
+ }
+ }
+
diff --git a/patches/minecraft/net/minecraft/world/entity/NeutralMob.java.patch b/patches/minecraft/net/minecraft/world/entity/NeutralMob.java.patch
new file mode 100644
index 0000000000..2f20127034
--- /dev/null
+++ b/patches/minecraft/net/minecraft/world/entity/NeutralMob.java.patch
@@ -0,0 +1,20 @@
+--- a/net/minecraft/world/entity/NeutralMob.java
++++ b/net/minecraft/world/entity/NeutralMob.java
+@@ -108,7 +_,7 @@
+ default void stopBeingAngry() {
+ this.setLastHurtByMob((LivingEntity)null);
+ this.setPersistentAngerTarget((UUID)null);
+- this.setTarget((LivingEntity)null);
++ this.setTarget((LivingEntity)null, org.bukkit.event.entity.EntityTargetEvent.TargetReason.FORGOT_TARGET, true); // CraftBukkit
+ this.setRemainingPersistentAngerTime(0);
+ }
+
+@@ -119,7 +_,7 @@
+
+ void setLastHurtByPlayer(@Nullable Player p_21680_);
+
+- void setTarget(@Nullable LivingEntity p_21681_);
++ void setTarget(@Nullable LivingEntity p_21681_, org.bukkit.event.entity.EntityTargetEvent.TargetReason reason, boolean fireEvent); // CraftBukkit
+
+ boolean canAttack(LivingEntity p_181126_);
+