Move diffs around to compile without later ones applied

This commit is contained in:
Nassim Jahnke 2024-01-23 18:01:39 +01:00
parent 091f54138b
commit cd30cd6d41
19 changed files with 243 additions and 196 deletions

View file

@ -13,7 +13,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
super.tick(); super.tick();
if (!this.level().isClientSide) { if (!this.level().isClientSide) {
- this.setClimbing(this.horizontalCollision); - this.setClimbing(this.horizontalCollision);
+ this.setClimbing(this.horizontalCollision && (this.level().paperConfig().entities.behavior.allowSpiderWorldBorderClimbing || !io.papermc.paper.util.CollisionUtil.isCollidingWithBorder(this.level().getWorldBorder(), this.getBoundingBox().inflate(io.papermc.paper.util.CollisionUtil.COLLISION_EPSILON)))); // Paper - inflate by +EPSILON as collision will place us outside the border, but just barely + this.setClimbing(this.horizontalCollision && (this.level().paperConfig().entities.behavior.allowSpiderWorldBorderClimbing)); // Paper - Add config option for spider worldborder climbing
} }
} }

View file

@ -1021,8 +1021,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java --- a/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java +++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
@@ -0,0 +0,0 @@ public class ClientboundLevelChunkPacketData { @@ -0,0 +0,0 @@ public class ClientboundLevelChunkPacketData {
} private final byte[] buffer;
// Paper end - Handle oversized block entities in chunks private final List<ClientboundLevelChunkPacketData.BlockEntityInfo> blockEntitiesData;
- public ClientboundLevelChunkPacketData(LevelChunk chunk) { - public ClientboundLevelChunkPacketData(LevelChunk chunk) {
+ // Paper start - Anti-Xray - Add chunk packet info + // Paper start - Anti-Xray - Add chunk packet info
@ -1046,8 +1046,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ extractChunkData(new FriendlyByteBuf(this.getWriteBuffer()), chunk, chunkPacketInfo); + extractChunkData(new FriendlyByteBuf(this.getWriteBuffer()), chunk, chunkPacketInfo);
+ // Paper end + // Paper end
this.blockEntitiesData = Lists.newArrayList(); this.blockEntitiesData = Lists.newArrayList();
int totalTileEntities = 0; // Paper - Handle oversized block entities in chunks
for(Map.Entry<BlockPos, BlockEntity> entry2 : chunk.getBlockEntities().entrySet()) {
@@ -0,0 +0,0 @@ public class ClientboundLevelChunkPacketData { @@ -0,0 +0,0 @@ public class ClientboundLevelChunkPacketData {
return byteBuf; return byteBuf;
} }
@ -1154,6 +1154,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
// Paper start - PlayerChunkLoadEvent // Paper start - PlayerChunkLoadEvent
if (io.papermc.paper.event.packet.PlayerChunkLoadEvent.getHandlerList().getRegisteredListeners().length > 0) { if (io.papermc.paper.event.packet.PlayerChunkLoadEvent.getHandlerList().getRegisteredListeners().length > 0) {
new io.papermc.paper.event.packet.PlayerChunkLoadEvent(new org.bukkit.craftbukkit.CraftChunk(chunk), handler.getPlayer().getBukkitEntity()).callEvent(); new io.papermc.paper.event.packet.PlayerChunkLoadEvent(new org.bukkit.craftbukkit.CraftChunk(chunk), handler.getPlayer().getBukkitEntity()).callEvent();
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -0,0 +0,0 @@ public abstract class PlayerList {
.getHolderOrThrow(net.minecraft.world.level.biome.Biomes.PLAINS);
player.connection.send(new net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket(
new net.minecraft.world.level.chunk.EmptyLevelChunk(worldserver1, player.chunkPosition(), plains),
- worldserver1.getLightEngine(), (java.util.BitSet)null, (java.util.BitSet) null)
+ worldserver1.getLightEngine(), (java.util.BitSet)null, (java.util.BitSet) null, true)
);
}
// Paper end - Send empty chunk
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/Level.java --- a/src/main/java/net/minecraft/world/level/Level.java

View file

@ -15,7 +15,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ +
+ @Override + @Override
+ public boolean hasCollisionsIn(@org.jetbrains.annotations.NotNull org.bukkit.util.BoundingBox boundingBox) { + public boolean hasCollisionsIn(@org.jetbrains.annotations.NotNull org.bukkit.util.BoundingBox boundingBox) {
+ net.minecraft.world.phys.AABB aabb = new net.minecraft.world.phys.AABB(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ(), false); + net.minecraft.world.phys.AABB aabb = new net.minecraft.world.phys.AABB(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());
+ +
+ return !this.getHandle().noCollision(aabb); + return !this.getHandle().noCollision(aabb);
+ } + }
@ -39,7 +39,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ +
+ @Override + @Override
+ public boolean wouldCollideUsing(@org.jetbrains.annotations.NotNull BoundingBox boundingBox) { + public boolean wouldCollideUsing(@org.jetbrains.annotations.NotNull BoundingBox boundingBox) {
+ net.minecraft.world.phys.AABB aabb = new AABB(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ(), false); + net.minecraft.world.phys.AABB aabb = new AABB(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());
+ +
+ return !this.getHandle().level().noCollision(this.getHandle(), aabb); + return !this.getHandle().level().noCollision(this.getHandle(), aabb);
+ } + }

View file

@ -2452,6 +2452,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
Iterator iterator = list.iterator(); Iterator iterator = list.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
diff --git a/src/main/java/net/minecraft/world/entity/monster/Spider.java b/src/main/java/net/minecraft/world/entity/monster/Spider.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Spider.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Spider.java
@@ -0,0 +0,0 @@ public class Spider extends Monster {
public void tick() {
super.tick();
if (!this.level().isClientSide) {
- this.setClimbing(this.horizontalCollision && (this.level().paperConfig().entities.behavior.allowSpiderWorldBorderClimbing)); // Paper - Add config option for spider worldborder climbing
+ this.setClimbing(this.horizontalCollision && (this.level().paperConfig().entities.behavior.allowSpiderWorldBorderClimbing || !io.papermc.paper.util.CollisionUtil.isCollidingWithBorder(this.level().getWorldBorder(), this.getBoundingBox().inflate(io.papermc.paper.util.CollisionUtil.COLLISION_EPSILON)))); // Paper - Add config option for spider worldborder climbing & Inflate by +EPSILON as collision will just barely place us outside border
}
}
diff --git a/src/main/java/net/minecraft/world/level/BlockCollisions.java b/src/main/java/net/minecraft/world/level/BlockCollisions.java diff --git a/src/main/java/net/minecraft/world/level/BlockCollisions.java b/src/main/java/net/minecraft/world/level/BlockCollisions.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/BlockCollisions.java --- a/src/main/java/net/minecraft/world/level/BlockCollisions.java

View file

@ -155,6 +155,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper end - detailed watchdog information + // Paper end - detailed watchdog information
+ +
public void move(MoverType movementType, Vec3 movement) { public void move(MoverType movementType, Vec3 movement) {
final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
+ // Paper start - detailed watchdog information + // Paper start - detailed watchdog information
+ io.papermc.paper.util.TickThread.ensureTickThread("Cannot move an entity off-main"); + io.papermc.paper.util.TickThread.ensureTickThread("Cannot move an entity off-main");
+ synchronized (this.posLock) { + synchronized (this.posLock) {

View file

@ -15,7 +15,6 @@ Adds villagers as separate config
== AT == == AT ==
public net.minecraft.world.entity.Entity isInsidePortal public net.minecraft.world.entity.Entity isInsidePortal
public net.minecraft.world.entity.LivingEntity jumping
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
@ -422,15 +421,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public class ActivationRange public class ActivationRange
{ {
public enum ActivationType
{
+ WATER, // Paper
+ FLYING_MONSTER, // Paper
+ VILLAGER, // Paper
MONSTER,
ANIMAL,
RAIDER,
@@ -0,0 +0,0 @@ public class ActivationRange @@ -0,0 +0,0 @@ public class ActivationRange
AABB boundingBox = new AABB( 0, 0, 0, 0, 0, 0 ); AABB boundingBox = new AABB( 0, 0, 0, 0, 0, 0 );

View file

@ -3,6 +3,8 @@ From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Sat, 8 Feb 2020 23:26:11 -0600 Date: Sat, 8 Feb 2020 23:26:11 -0600
Subject: [PATCH] Entity Jump API Subject: [PATCH] Entity Jump API
== AT ==
public net.minecraft.world.entity.LivingEntity jumping
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644

View file

@ -12,9 +12,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S @@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
} }
public void move(MoverType movementType, Vec3 movement) {
+ final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
if (this.noPhysics) {
this.setPos(this.getX() + movement.x, this.getY() + movement.y, this.getZ() + movement.z);
} else {
@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
}
if (!bl.getType().isAir()) { if (!bl.getType().isAir()) {
- VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl); - VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl);
+ VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl, org.bukkit.craftbukkit.util.CraftVector.toBukkit(moveVector)); // Paper - Expose pre-collision velocity + VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl, org.bukkit.craftbukkit.util.CraftVector.toBukkit(originalMovement)); // Paper - Expose pre-collision velocity
this.level.getCraftServer().getPluginManager().callEvent(event); this.level.getCraftServer().getPluginManager().callEvent(event);
} }
} }

View file

@ -23,7 +23,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ .getHolderOrThrow(net.minecraft.world.level.biome.Biomes.PLAINS); + .getHolderOrThrow(net.minecraft.world.level.biome.Biomes.PLAINS);
+ player.connection.send(new net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket( + player.connection.send(new net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket(
+ new net.minecraft.world.level.chunk.EmptyLevelChunk(worldserver1, player.chunkPosition(), plains), + new net.minecraft.world.level.chunk.EmptyLevelChunk(worldserver1, player.chunkPosition(), plains),
+ worldserver1.getLightEngine(), (java.util.BitSet)null, (java.util.BitSet) null, false) + worldserver1.getLightEngine(), (java.util.BitSet)null, (java.util.BitSet) null)
+ ); + );
+ } + }
+ // Paper end - Send empty chunk + // Paper end - Send empty chunk

View file

@ -25,11 +25,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ // Paper end - Handle oversized block entities in chunks + // Paper end - Handle oversized block entities in chunks
public ClientboundLevelChunkPacketData(LevelChunk chunk) { // Paper start - Anti-Xray - Add chunk packet info
this.heightmaps = new CompoundTag(); @Deprecated @io.papermc.paper.annotation.DoNotUse public ClientboundLevelChunkPacketData(LevelChunk chunk) { this(chunk, null); }
@@ -0,0 +0,0 @@ public class ClientboundLevelChunkPacketData { @@ -0,0 +0,0 @@ public class ClientboundLevelChunkPacketData {
this.buffer = new byte[calculateChunkSize(chunk)]; extractChunkData(new FriendlyByteBuf(this.getWriteBuffer()), chunk, chunkPacketInfo);
extractChunkData(new FriendlyByteBuf(this.getWriteBuffer()), chunk); // Paper end
this.blockEntitiesData = Lists.newArrayList(); this.blockEntitiesData = Lists.newArrayList();
+ int totalTileEntities = 0; // Paper - Handle oversized block entities in chunks + int totalTileEntities = 0; // Paper - Handle oversized block entities in chunks

View file

@ -311,10 +311,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return deobfuscationMap.getOrDefault(name, name); + return deobfuscationMap.getOrDefault(name, name);
+ } + }
+ +
+ public static EnumSet<GoalType> vanillaToPaper(OptimizedSmallEnumSet<Goal.Flag> types) { + public static EnumSet<GoalType> vanillaToPaper(Goal goal) {
+ EnumSet<GoalType> goals = EnumSet.noneOf(GoalType.class); + EnumSet<GoalType> goals = EnumSet.noneOf(GoalType.class);
+ for (GoalType type : GoalType.values()) { + for (GoalType type : GoalType.values()) {
+ if (types.hasElement(paperToVanilla(type))) { + if (goal.getFlags().contains(paperToVanilla(type))) {
+ goals.add(type); + goals.add(type);
+ } + }
+ } + }
@ -420,7 +420,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ +
+ this.setFlags(MobGoalHelper.paperToVanilla(handle.getTypes())); + this.setFlags(MobGoalHelper.paperToVanilla(handle.getTypes()));
+ if (this.getFlags().size() == 0) { + if (this.getFlags().size() == 0) {
+ this.getFlags().addUnchecked(Flag.UNKNOWN_BEHAVIOR); + this.getFlags().add(Flag.UNKNOWN_BEHAVIOR);
+ } + }
+ } + }
+ +
@ -574,7 +574,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ CraftMob craftMob = (CraftMob) mob; + CraftMob craftMob = (CraftMob) mob;
+ Set<Goal<T>> goals = new HashSet<>(); + Set<Goal<T>> goals = new HashSet<>();
+ for (WrappedGoal item : getHandle(craftMob, type).getAvailableGoals()) { + for (WrappedGoal item : getHandle(craftMob, type).getAvailableGoals()) {
+ if (!item.getGoal().getFlags().hasElement(MobGoalHelper.paperToVanilla(type))) { + if (!item.getGoal().getFlags().contains(MobGoalHelper.paperToVanilla(type))) {
+ continue; + continue;
+ } + }
+ +
@ -597,7 +597,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ continue; + continue;
+ } + }
+ for (WrappedGoal item : getHandle(craftMob, internalType).getAvailableGoals()) { + for (WrappedGoal item : getHandle(craftMob, internalType).getAvailableGoals()) {
+ if (item.getGoal().getFlags().hasElement(MobGoalHelper.paperToVanilla(type))) { + if (item.getGoal().getFlags().contains(MobGoalHelper.paperToVanilla(type))) {
+ continue; + continue;
+ } + }
+ +
@ -626,7 +626,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ CraftMob craftMob = (CraftMob) mob; + CraftMob craftMob = (CraftMob) mob;
+ Set<Goal<T>> goals = new HashSet<>(); + Set<Goal<T>> goals = new HashSet<>();
+ getHandle(craftMob, type).getRunningGoals() + getHandle(craftMob, type).getRunningGoals()
+ .filter(item -> item.getGoal().getFlags().hasElement(MobGoalHelper.paperToVanilla(type))) + .filter(item -> item.getGoal().getFlags().contains(MobGoalHelper.paperToVanilla(type)))
+ .forEach(item -> { + .forEach(item -> {
+ if (item.getGoal() instanceof PaperCustomGoal) { + if (item.getGoal() instanceof PaperCustomGoal) {
+ //noinspection unchecked + //noinspection unchecked
@ -647,7 +647,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ continue; + continue;
+ } + }
+ getHandle(craftMob, internalType).getRunningGoals() + getHandle(craftMob, internalType).getRunningGoals()
+ .filter(item -> !item.getGoal().getFlags().hasElement(MobGoalHelper.paperToVanilla(type))) + .filter(item -> !item.getGoal().getFlags().contains(MobGoalHelper.paperToVanilla(type)))
+ .forEach(item -> { + .forEach(item -> {
+ if (item.getGoal() instanceof PaperCustomGoal) { + if (item.getGoal() instanceof PaperCustomGoal) {
+ //noinspection unchecked + //noinspection unchecked
@ -701,7 +701,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public PaperVanillaGoal(Goal handle) { + public PaperVanillaGoal(Goal handle) {
+ this.handle = handle; + this.handle = handle;
+ this.key = MobGoalHelper.getKey(handle.getClass()); + this.key = MobGoalHelper.getKey(handle.getClass());
+ this.types = MobGoalHelper.vanillaToPaper(handle.getFlags()); + this.types = MobGoalHelper.vanillaToPaper(handle);
+ } + }
+ +
+ public Goal getHandle() { + public Goal getHandle() {

View file

@ -30,10 +30,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ } + }
+ // Paper end - per player mob count backoff + // Paper end - per player mob count backoff
+ public int getMobCountNear(final ServerPlayer player, final net.minecraft.world.entity.MobCategory mobCategory) {
public int getMobCountNear(ServerPlayer entityPlayer, net.minecraft.world.entity.MobCategory mobCategory) { - return player.mobCounts[mobCategory.ordinal()];
- return entityPlayer.mobCounts[mobCategory.ordinal()]; + return player.mobCounts[mobCategory.ordinal()] + player.mobBackoffCounts[mobCategory.ordinal()]; // Paper - per player mob count backoff
+ return entityPlayer.mobCounts[mobCategory.ordinal()] + entityPlayer.mobBackoffCounts[mobCategory.ordinal()]; // Paper - per player mob count backoff
} }
// Paper end - Optional per player mob spawns // Paper end - Optional per player mob spawns

View file

@ -2114,7 +2114,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ this.enumClass = clazz; + this.enumClass = clazz;
+ } + }
+ +
+ public boolean addUnchecked(final E element) { + public boolean add(final E element) {
+ final int ordinal = element.ordinal(); + final int ordinal = element.ordinal();
+ final long key = 1L << ordinal; + final long key = 1L << ordinal;
+ +
@ -2124,7 +2124,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return (prev & key) == 0; + return (prev & key) == 0;
+ } + }
+ +
+ public boolean removeUnchecked(final E element) { + public boolean remove(final E element) {
+ final int ordinal = element.ordinal(); + final int ordinal = element.ordinal();
+ final long key = 1L << ordinal; + final long key = 1L << ordinal;
+ +
@ -2142,7 +2142,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return Long.bitCount(this.backingSet); + return Long.bitCount(this.backingSet);
+ } + }
+ +
+ public void addAllUnchecked(final Collection<E> enums) { + public void addAll(final Collection<E> enums) {
+ for (final E element : enums) { + for (final E element : enums) {
+ if (element == null) { + if (element == null) {
+ throw new NullPointerException("Null element"); + throw new NullPointerException("Null element");
@ -2159,7 +2159,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return (other.backingSet & this.backingSet) != 0; + return (other.backingSet & this.backingSet) != 0;
+ } + }
+ +
+ public boolean hasElement(final E element) { + public boolean contains(final E element) {
+ return (this.backingSet & (1L << element.ordinal())) != 0; + return (this.backingSet & (1L << element.ordinal())) != 0;
+ } + }
+} +}
@ -6420,17 +6420,29 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ this.regionManagers.add(this.dataRegionManager); + this.regionManagers.add(this.dataRegionManager);
+ this.nearbyPlayers = new io.papermc.paper.util.player.NearbyPlayers(this.level); + this.nearbyPlayers = new io.papermc.paper.util.player.NearbyPlayers(this.level);
+ // Paper end + // Paper end
+ } }
+
+ // Paper start + // Paper start
+ // always use accessor, so folia can override + // always use accessor, so folia can override
+ public final io.papermc.paper.util.player.NearbyPlayers getNearbyPlayers() { + public final io.papermc.paper.util.player.NearbyPlayers getNearbyPlayers() {
+ return this.nearbyPlayers; + return this.nearbyPlayers;
} + }
+ // Paper end + // Paper end
+
protected ChunkGenerator generator() { protected ChunkGenerator generator() {
return this.generator; return this.generator;
}
@@ -0,0 +0,0 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
});
}
+ public int getMobCountNear(final ServerPlayer player, final net.minecraft.world.entity.MobCategory mobCategory) {
+ return -1;
+ }
+
private static double euclideanDistanceSquared(ChunkPos pos, Entity entity) {
double d0 = (double) SectionPos.sectionToBlockCoord(pos.x, 8);
double d1 = (double) SectionPos.sectionToBlockCoord(pos.z, 8);
@@ -0,0 +0,0 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -0,0 +0,0 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
} }
} }
@ -7366,6 +7378,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.util.CraftSpawnCategory; import org.bukkit.craftbukkit.util.CraftSpawnCategory;
import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey;
@@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
return null;
}
+ // Paper start
+ public net.minecraft.world.phys.BlockHitResult.Type clipDirect(Vec3 start, Vec3 end, net.minecraft.world.phys.shapes.CollisionContext context) {
+ // To be patched over
+ return this.clip(new ClipContext(start, end, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, context)).getType();
+ }
+ // Paper end
+
public boolean isInWorldBounds(BlockPos pos) {
return !this.isOutsideBuildHeight(pos) && Level.isInWorldBoundsHorizontal(pos);
}
@@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable { @@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
return y < -20000000 || y >= 20000000; return y < -20000000 || y >= 20000000;
} }
@ -7383,15 +7409,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
} }
+ // Paper start - if loaded + // Paper start - if loaded
@Nullable + @Nullable
@Override + @Override
- public ChunkAccess getChunk(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create) {
+ public final ChunkAccess getChunkIfLoadedImmediately(int x, int z) { + public final ChunkAccess getChunkIfLoadedImmediately(int x, int z) {
+ return ((ServerLevel)this).chunkSource.getChunkAtIfLoadedImmediately(x, z); + return ((ServerLevel)this).chunkSource.getChunkAtIfLoadedImmediately(x, z);
+ } + }
+ +
+ @Override + @Override
+ @Nullable @Nullable
+ public final BlockState getBlockStateIfLoaded(BlockPos pos) { + public final BlockState getBlockStateIfLoaded(BlockPos pos) {
+ // CraftBukkit start - tree generation + // CraftBukkit start - tree generation
+ if (this.captureTreeGeneration) { + if (this.captureTreeGeneration) {
@ -7417,7 +7442,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return chunk == null ? null : chunk.getFluidState(blockposition); + return chunk == null ? null : chunk.getFluidState(blockposition);
+ } + }
+ +
+ @Override @Override
- public ChunkAccess getChunk(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create) {
+ public final ChunkAccess getChunk(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create) { // Paper - final for inline + public final ChunkAccess getChunk(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create) { // Paper - final for inline
+ // Paper end + // Paper end
ChunkAccess ichunkaccess = this.getChunkSource().getChunk(chunkX, chunkZ, leastStatus, create); ChunkAccess ichunkaccess = this.getChunkSource().getChunk(chunkX, chunkZ, leastStatus, create);
@ -7566,6 +7592,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
this.upgradeData = upgradeData; this.upgradeData = upgradeData;
this.levelHeightAccessor = heightLimitView; this.levelHeightAccessor = heightLimitView;
this.sections = new LevelChunkSection[heightLimitView.getSectionsCount()]; this.sections = new LevelChunkSection[heightLimitView.getSectionsCount()];
diff --git a/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java
@@ -0,0 +0,0 @@ public class EmptyLevelChunk extends LevelChunk {
public BlockState getBlockState(BlockPos pos) {
return Blocks.VOID_AIR.defaultBlockState();
}
+ // Paper start
+ @Override
+ public BlockState getBlockState(final int x, final int y, final int z) {
+ return Blocks.VOID_AIR.defaultBlockState();
+ }
+ // Paper end
@Nullable
@Override
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java --- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
@ -7684,6 +7727,32 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
} }
} }
+ // Paper start - Perf: Reduce instructions and provide final method
+ public BlockState getBlockState(final int x, final int y, final int z) {
+ return this.getBlockStateFinal(x, y, z);
+ }
+ public BlockState getBlockStateFinal(final int x, final int y, final int z) {
+ // Copied and modified from below
+ final int sectionIndex = this.getSectionIndex(y);
+ if (sectionIndex < 0 || sectionIndex >= this.sections.length
+ || this.sections[sectionIndex].nonEmptyBlockCount == 0) {
+ return Blocks.AIR.defaultBlockState();
+ }
+ return this.sections[sectionIndex].states.get((y & 15) << 8 | (z & 15) << 4 | x & 15);
+ }
@Override
public BlockState getBlockState(BlockPos pos) {
+ if (true) {
+ return this.getBlockStateFinal(pos.getX(), pos.getY(), pos.getZ());
+ }
+ // Paper end - Perf: Reduce instructions and provide final method
int i = pos.getX();
int j = pos.getY();
int k = pos.getZ();
@@ -0,0 +0,0 @@ public class LevelChunk extends ChunkAccess {
}
}
+ // Paper start - If loaded util + // Paper start - If loaded util
+ @Override + @Override
+ public final FluidState getFluidIfLoaded(BlockPos blockposition) { + public final FluidState getFluidIfLoaded(BlockPos blockposition) {
@ -7748,6 +7817,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
} }
@Override @Override
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
@@ -0,0 +0,0 @@ public class LevelChunkSection {
public static final int SECTION_HEIGHT = 16;
public static final int SECTION_SIZE = 4096;
public static final int BIOME_CONTAINER_BITS = 2;
- private short nonEmptyBlockCount;
+ short nonEmptyBlockCount; // Paper - package private
private short tickingBlockCount;
private short tickingFluidCount;
public final PalettedContainer<BlockState> states;
diff --git a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java diff --git a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java --- a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
@ -8275,6 +8357,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@Override @Override
public void clear() { public void clear() {
// Create new array to reset memory usage to initial capacity // Create new array to reset memory usage to initial capacity
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -0,0 +0,0 @@ public class ActivationRange
public enum ActivationType
{
+ WATER, // Paper
+ FLYING_MONSTER, // Paper
+ VILLAGER, // Paper
MONSTER,
ANIMAL,
RAIDER,
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/spigotmc/SpigotConfig.java --- a/src/main/java/org/spigotmc/SpigotConfig.java

View file

@ -21,7 +21,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper start - remove streams from pathfindergoalselector; make sure types are not empty + // Paper start - remove streams from pathfindergoalselector; make sure types are not empty
+ public Goal() { + public Goal() {
+ if (this.goalTypes.size() == 0) { + if (this.goalTypes.size() == 0) {
+ this.goalTypes.addUnchecked(Flag.UNKNOWN_BEHAVIOR); + this.goalTypes.add(Flag.UNKNOWN_BEHAVIOR);
+ } + }
+ } + }
+ // Paper end - remove streams from pathfindergoalselector + // Paper end - remove streams from pathfindergoalselector
@ -36,9 +36,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- this.flags.addAll(controls); - this.flags.addAll(controls);
+ // Paper start - remove streams from pathfindergoalselector + // Paper start - remove streams from pathfindergoalselector
+ this.goalTypes.clear(); + this.goalTypes.clear();
+ this.goalTypes.addAllUnchecked(controls); + this.goalTypes.addAll(controls);
+ if (this.goalTypes.size() == 0) { + if (this.goalTypes.size() == 0) {
+ this.goalTypes.addUnchecked(Flag.UNKNOWN_BEHAVIOR); + this.goalTypes.add(Flag.UNKNOWN_BEHAVIOR);
+ } + }
+ // Paper end - remove streams from pathfindergoalselector + // Paper end - remove streams from pathfindergoalselector
} }
@ -153,12 +153,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public void disableControlFlag(Goal.Flag control) { public void disableControlFlag(Goal.Flag control) {
- this.disabledFlags.add(control); - this.disabledFlags.add(control);
+ this.goalTypes.addUnchecked(control); // Paper - remove streams from pathfindergoalselector + this.goalTypes.add(control); // Paper - remove streams from pathfindergoalselector
} }
public void enableControlFlag(Goal.Flag control) { public void enableControlFlag(Goal.Flag control) {
- this.disabledFlags.remove(control); - this.disabledFlags.remove(control);
+ this.goalTypes.removeUnchecked(control); // Paper - remove streams from pathfindergoalselector + this.goalTypes.remove(control); // Paper - remove streams from pathfindergoalselector
} }
public void setControlFlag(Goal.Flag control, boolean enabled) { public void setControlFlag(Goal.Flag control, boolean enabled) {

View file

@ -53,23 +53,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@Nullable @Nullable
public abstract BlockState setBlockState(BlockPos pos, BlockState state, boolean moved); public abstract BlockState setBlockState(BlockPos pos, BlockState state, boolean moved);
diff --git a/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java
@@ -0,0 +0,0 @@ public class EmptyLevelChunk extends LevelChunk {
public void setBlockEmptinessMap(final boolean[] emptinessMap) {}
// Paper end - starlight
+ // Paper start
+ @Override
+ public BlockState getBlockState(int x, int y, int z) {
+ return Blocks.VOID_AIR.defaultBlockState();
+ }
+ // Paper end
@Override
public BlockState getBlockState(BlockPos pos) {
return Blocks.VOID_AIR.defaultBlockState();
diff --git a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java diff --git a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java --- a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
@ -87,56 +70,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@Override @Override
public FluidState getFluidState(BlockPos pos) { public FluidState getFluidState(BlockPos pos) {
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
@@ -0,0 +0,0 @@ public class LevelChunk extends ChunkAccess {
}
}
+ // Paper start - Optimize getBlockData to reduce instructions
@Override
public BlockState getBlockState(BlockPos pos) {
- int i = pos.getX();
- int j = pos.getY();
- int k = pos.getZ();
+ return this.getBlockStateFinal(pos.getX(), pos.getY(), pos.getZ());
+ }
+
+ @Override
+ public BlockState getBlockState(final int x, final int y, final int z) {
+ return this.getBlockStateFinal(x, y, z);
+ }
+ public final BlockState getBlockStateFinal(final int x, final int y, final int z) {
+ // Method body / logic copied from below
+ final int i = this.getSectionIndex(y);
+ if (i < 0 || i >= this.sections.length || this.sections[i].nonEmptyBlockCount == 0 || this.sections[i].hasOnlyAir()) {
+ return Blocks.AIR.defaultBlockState();
+ }
+ // Inlined ChunkSection.getType() and DataPaletteBlock.a(int,int,int)
+ return this.sections[i].states.get((y & 15) << 8 | (z & 15) << 4 | x & 15);
+ }
+
+ public BlockState getBlockState_unused(int i, int j, int k) {
+ // Paper end
if (this.level.isDebug()) {
BlockState iblockdata = null;
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
@@ -0,0 +0,0 @@ public class LevelChunkSection {
public static final int SECTION_HEIGHT = 16;
public static final int SECTION_SIZE = 4096;
public static final int BIOME_CONTAINER_BITS = 2;
- private short nonEmptyBlockCount;
+ short nonEmptyBlockCount; // Paper - package-private
private short tickingBlockCount;
private short tickingFluidCount;
public final PalettedContainer<BlockState> states;
diff --git a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java diff --git a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java --- a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java

View file

@ -13,7 +13,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
} }
+ // Paper start - Optional per player mob spawns + // Paper start - Optional per player mob spawns
+ public void updatePlayerMobTypeMap(Entity entity) { + public void updatePlayerMobTypeMap(final Entity entity) {
+ if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) { + if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) {
+ return; + return;
+ } + }
@ -30,14 +30,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ } + }
+ +
+ public int getMobCountNear(ServerPlayer entityPlayer, net.minecraft.world.entity.MobCategory mobCategory) { public int getMobCountNear(final ServerPlayer player, final net.minecraft.world.entity.MobCategory mobCategory) {
+ return entityPlayer.mobCounts[mobCategory.ordinal()]; - return -1;
+ } + return player.mobCounts[mobCategory.ordinal()];
}
+ // Paper end - Optional per player mob spawns + // Paper end - Optional per player mob spawns
+
private static double euclideanDistanceSquared(ChunkPos pos, Entity entity) { private static double euclideanDistanceSquared(ChunkPos pos, Entity entity) {
double d0 = (double) SectionPos.sectionToBlockCoord(pos.x, 8); double d0 = (double) SectionPos.sectionToBlockCoord(pos.x, 8);
double d1 = (double) SectionPos.sectionToBlockCoord(pos.z, 8);
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java --- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java

View file

@ -1,63 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Tue, 23 May 2023 22:33:36 -0400
Subject: [PATCH] Properly cancel usable items
This fixes the bug causing cancelling PlayerInteractEvent to cause items to continue to be used despite being cancelled on the server.
For example, items being consumed but never finishing, shields being put up, etc.
The underlying issue of this is that the client modifies their synced data values, and so we have to (forcibly) resend
them in order for the client to reset their using item state.
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
@@ -0,0 +0,0 @@ public class ServerPlayerGameMode {
}
// Paper end - extend Player Interact cancellation
player.getBukkitEntity().updateInventory(); // SPIGOT-2867
+ this.player.resyncUsingItem(this.player); // Paper - Properly cancel usable items
enuminteractionresult = (event.useItemInHand() != Event.Result.ALLOW) ? InteractionResult.SUCCESS : InteractionResult.PASS;
} else if (this.gameModeForPlayer == GameType.SPECTATOR) {
MenuProvider itileinventory = iblockdata.getMenuProvider(world, blockposition);
@@ -0,0 +0,0 @@ public class ServerPlayerGameMode {
return enuminteractionresult1;
}
+ // Paper start - Properly cancel usable items; Cancel only if cancelled + if the interact result is different from default response
+ else if (this.interactResult && this.interactResult != cancelledItem) {
+ this.player.resyncUsingItem(this.player);
+ }
+ // Paper end - Properly cancel usable items
}
return enuminteractionresult;
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
}
if (cancelled) {
+ this.player.resyncUsingItem(this.player); // Paper - Properly cancel usable items
this.player.getBukkitEntity().updateInventory(); // SPIGOT-2524
return;
}
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -0,0 +0,0 @@ public abstract class LivingEntity extends Entity implements Attackable {
return ((Byte) this.entityData.get(LivingEntity.DATA_LIVING_ENTITY_FLAGS) & 2) > 0 ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
}
+ // Paper start - Properly cancel usable items
+ public void resyncUsingItem(ServerPlayer serverPlayer) {
+ this.getEntityData().resendPossiblyDesyncedDataValues(java.util.List.of(DATA_LIVING_ENTITY_FLAGS), serverPlayer);
+ }
+ // Paper end - Properly cancel usable items
private void updatingUsingItem() {
if (this.isUsingItem()) {
if (ItemStack.isSameItem(this.getItemInHand(this.getUsedItemHand()), this.useItem)) {

View file

@ -10,6 +10,13 @@ sure that values will be correctly updated to other players.
This also adds utilities to aid in further preventing entity desyncs. This also adds utilities to aid in further preventing entity desyncs.
This also also fixes the bug causing cancelling PlayerInteractEvent to cause items to continue
to be used despite being cancelled on the server.
For example, items being consumed but never finishing, shields being put up, etc.
The underlying issue of this is that the client modifies their synced data values,
and so we have to (forcibly) resend them in order for the client to reset their using item state.
See: https://github.com/PaperMC/Paper/pull/1896 See: https://github.com/PaperMC/Paper/pull/1896
== AT == == AT ==
@ -84,10 +91,42 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public static class DataItem<T> { public static class DataItem<T> {
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
@@ -0,0 +0,0 @@ public class ServerPlayerGameMode {
}
// Paper end - extend Player Interact cancellation
player.getBukkitEntity().updateInventory(); // SPIGOT-2867
+ this.player.resyncUsingItem(this.player); // Paper - Properly cancel usable items
enuminteractionresult = (event.useItemInHand() != Event.Result.ALLOW) ? InteractionResult.SUCCESS : InteractionResult.PASS;
} else if (this.gameModeForPlayer == GameType.SPECTATOR) {
MenuProvider itileinventory = iblockdata.getMenuProvider(world, blockposition);
@@ -0,0 +0,0 @@ public class ServerPlayerGameMode {
return enuminteractionresult1;
}
+ // Paper start - Properly cancel usable items; Cancel only if cancelled + if the interact result is different from default response
+ else if (this.interactResult && this.interactResult != cancelledItem) {
+ this.player.resyncUsingItem(this.player);
+ }
+ // Paper end - Properly cancel usable items
}
return enuminteractionresult;
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
}
if (cancelled) {
+ this.player.resyncUsingItem(this.player); // Paper - Properly cancel usable items
this.player.getBukkitEntity().updateInventory(); // SPIGOT-2524
return;
}
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl @@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
// Entity in bucket - SPIGOT-4048 and SPIGOT-6859a // Entity in bucket - SPIGOT-4048 and SPIGOT-6859a
@ -110,6 +149,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
this.sendLevelInfo(player, worldserver1); this.sendLevelInfo(player, worldserver1);
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -0,0 +0,0 @@ public abstract class LivingEntity extends Entity implements Attackable {
return ((Byte) this.entityData.get(LivingEntity.DATA_LIVING_ENTITY_FLAGS) & 2) > 0 ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
}
+ // Paper start - Properly cancel usable items
+ public void resyncUsingItem(ServerPlayer serverPlayer) {
+ this.getEntityData().resendPossiblyDesyncedDataValues(java.util.List.of(DATA_LIVING_ENTITY_FLAGS), serverPlayer);
+ }
+ // Paper end - Properly cancel usable items
private void updatingUsingItem() {
if (this.isUsingItem()) {
if (ItemStack.isSameItem(this.getItemInHand(this.getUsedItemHand()), this.useItem)) {
diff --git a/src/main/java/net/minecraft/world/entity/animal/Bucketable.java b/src/main/java/net/minecraft/world/entity/animal/Bucketable.java diff --git a/src/main/java/net/minecraft/world/entity/animal/Bucketable.java b/src/main/java/net/minecraft/world/entity/animal/Bucketable.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Bucketable.java --- a/src/main/java/net/minecraft/world/entity/animal/Bucketable.java

View file

@ -69,8 +69,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
return null; return null;
} }
- // Paper start
+ // Paper start - Broken down method of raytracing for EntityLiving#hasLineOfSight, replaces BlockGetter#clip(CollisionContext) + // Paper start - Broken down method of raytracing for EntityLiving#hasLineOfSight, replaces BlockGetter#clip(CollisionContext)
+ public net.minecraft.world.phys.BlockHitResult.Type clipDirect(Vec3 start, Vec3 end, net.minecraft.world.phys.shapes.CollisionContext collisionContext) { public net.minecraft.world.phys.BlockHitResult.Type clipDirect(Vec3 start, Vec3 end, net.minecraft.world.phys.shapes.CollisionContext context) {
- // To be patched over
- return this.clip(new ClipContext(start, end, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, context)).getType();
+ // most of this code comes from BlockGetter#clip(CollisionContext, BiFunction, Function), but removes the needless functions + // most of this code comes from BlockGetter#clip(CollisionContext, BiFunction, Function), but removes the needless functions
+ if (start.equals(end)) { + if (start.equals(end)) {
+ return net.minecraft.world.phys.BlockHitResult.Type.MISS; + return net.minecraft.world.phys.BlockHitResult.Type.MISS;
@ -95,7 +98,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return net.minecraft.world.phys.BlockHitResult.Type.MISS; + return net.minecraft.world.phys.BlockHitResult.Type.MISS;
+ } + }
+ +
+ final net.minecraft.world.phys.BlockHitResult.Type initialCheck = this.clipDirect(start, end, currentBlock, chunk.getBlockState(currentBlock), collisionContext); + final net.minecraft.world.phys.BlockHitResult.Type initialCheck = this.clipDirect(start, end, currentBlock, chunk.getBlockState(currentBlock), context);
+ if (initialCheck != null) { + if (initialCheck != null) {
+ return initialCheck; + return initialCheck;
+ } + }
@ -146,13 +149,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return net.minecraft.world.phys.BlockHitResult.Type.MISS; + return net.minecraft.world.phys.BlockHitResult.Type.MISS;
+ } + }
+ } + }
+ result = this.clipDirect(start, end, currentBlock, chunk.getBlockState(currentBlock), collisionContext); + result = this.clipDirect(start, end, currentBlock, chunk.getBlockState(currentBlock), context);
+ } while (result == null); + } while (result == null);
+ +
+ return result; + return result;
+ }
+ // Paper end
+
public boolean isInWorldBounds(BlockPos pos) {
return !this.isOutsideBuildHeight(pos) && Level.isInWorldBoundsHorizontal(pos);
} }
// Paper end