This commit is contained in:
Jake Potrebic 2024-06-13 10:30:39 -07:00
parent 79da0788dd
commit 6a05c85176
55 changed files with 36 additions and 51 deletions

View file

@ -126,35 +126,22 @@ diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src
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 @@
package net.minecraft.world.level.chunk;
import com.google.common.collect.ImmutableList;
+import com.destroystokyo.paper.exception.ServerInternalException;
import com.google.common.collect.Maps;
import com.google.common.collect.UnmodifiableIterator;
import com.mojang.logging.LogUtils;
@@ -0,0 +0,0 @@ public class LevelChunk extends ChunkAccess {
BlockState iblockdata = this.getBlockState(blockposition);
// CraftBukkit start
} else {
- System.out.println("Attempted to place a tile entity (" + blockEntity + ") at " + blockEntity.getBlockPos().getX() + "," + blockEntity.getBlockPos().getY() + "," + blockEntity.getBlockPos().getZ()
- + " (" + this.getBlockState(blockposition) + ") where there was no entity tile!");
- System.out.println("Chunk coordinates: " + (this.chunkPos.x * 16) + "," + (this.chunkPos.z * 16));
- new Exception().printStackTrace();
if (!iblockdata.hasBlockEntity()) {
- LevelChunk.LOGGER.warn("Trying to set block entity {} at position {}, but state {} does not allow it", new Object[]{blockEntity, blockposition, iblockdata});
- new Exception().printStackTrace(); // CraftBukkit
+ // Paper start - ServerExceptionEvent
+ ServerInternalException e = new ServerInternalException(
+ "Attempted to place a tile entity (" + blockEntity + ") at " + blockEntity.getBlockPos().getX() + ","
+ + blockEntity.getBlockPos().getY() + "," + blockEntity.getBlockPos().getZ()
+ + " (" + getBlockState(blockposition) + ") where there was no entity tile!\n" +
+ "Chunk coordinates: " + (this.chunkPos.x * 16) + "," + (this.chunkPos.z * 16) +
+ "\nWorld: " + level.getLevel().dimension().location());
+ com.destroystokyo.paper.exception.ServerInternalException e = new com.destroystokyo.paper.exception.ServerInternalException(
+ "Trying to set block entity %s at position %s, but state %s does not allow it".formatted(blockEntity, blockposition, iblockdata)
+ );
+ e.printStackTrace();
+ ServerInternalException.reportInternalException(e);
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(e);
+ // Paper end - ServerExceptionEvent
// CraftBukkit end
}
}
} else {
BlockState iblockdata1 = blockEntity.getBlockState();
@@ -0,0 +0,0 @@ public class LevelChunk extends ChunkAccess {
// Paper start - Prevent block entity and entity crashes
final String msg = String.format("BlockEntity threw exception at %s:%s,%s,%s", LevelChunk.this.getLevel().getWorld().getName(), this.getPos().getX(), this.getPos().getY(), this.getPos().getZ());

View file

@ -10,7 +10,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
@@ -0,0 +0,0 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
this.connection.disconnect(ichatmutablecomponent);
this.connection.disconnect((Component) ichatmutablecomponent);
} else {
this.connection.setupInboundProtocol(LoginProtocols.SERVERBOUND, new ServerLoginPacketListenerImpl(this.server, this.connection, transfer));
+ // Paper start - PlayerHandshakeEvent

View file

@ -9,7 +9,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/world/entity/ExperienceOrb.java
+++ b/src/main/java/net/minecraft/world/entity/ExperienceOrb.java
@@ -0,0 +0,0 @@ public class ExperienceOrb extends Entity {
int i = this.repairPlayerItems(player, this.value);
int i = this.repairPlayerItems(entityplayer, this.value);
if (i > 0) {
- player.giveExperiencePoints(CraftEventFactory.callPlayerExpChangeEvent(player, i).getAmount()); // CraftBukkit - this.value -> event.getAmount()

View file

@ -15,7 +15,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/world/level/border/WorldBorder.java
+++ b/src/main/java/net/minecraft/world/level/border/WorldBorder.java
@@ -0,0 +0,0 @@ public class WorldBorder {
return (double) (pos.getX() + 1) > this.getMinX() && (double) pos.getX() < this.getMaxX() && (double) (pos.getZ() + 1) > this.getMinZ() && (double) pos.getZ() < this.getMaxZ();
return this.isWithinBounds((double) chunkPos.getMinBlockX(), (double) chunkPos.getMinBlockZ()) && this.isWithinBounds((double) chunkPos.getMaxBlockX(), (double) chunkPos.getMaxBlockZ());
}
+ // Paper start - Bound treasure maps to world border
@ -30,8 +30,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ // Paper end - Bound treasure maps to world border
+
public boolean isWithinBounds(ChunkPos pos) {
return (double) pos.getMaxBlockX() > this.getMinX() && (double) pos.getMinBlockX() < this.getMaxX() && (double) pos.getMaxBlockZ() > this.getMinZ() && (double) pos.getMinBlockZ() < this.getMaxZ();
public boolean isWithinBounds(AABB box) {
return this.isWithinBounds(box.minX, box.minZ, box.maxX - 9.999999747378752E-6D, box.maxZ - 9.999999747378752E-6D);
}
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644

View file

@ -12,7 +12,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
if (this.clientIsFloating && !this.player.isSleeping() && !this.player.isPassenger() && !this.player.isDeadOrDying()) {
if (++this.aboveGroundTickCount > this.getMaximumFlyingTicks(this.player)) {
ServerGamePacketListenerImpl.LOGGER.warn("{} was kicked for floating too long!", this.player.getName().getString());
- this.disconnect(Component.translatable("multiplayer.disconnect.flying"));
- this.disconnect((Component) Component.translatable("multiplayer.disconnect.flying"));
+ this.disconnect(io.papermc.paper.configuration.GlobalConfiguration.get().messages.kick.flyingPlayer); // Paper - use configurable kick message
return;
}
@ -21,7 +21,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
if (this.clientVehicleIsFloating && this.lastVehicle.getControllingPassenger() == this.player) {
if (++this.aboveGroundVehicleTickCount > this.getMaximumFlyingTicks(this.lastVehicle)) {
ServerGamePacketListenerImpl.LOGGER.warn("{} was kicked for floating a vehicle too long!", this.player.getName().getString());
- this.disconnect(Component.translatable("multiplayer.disconnect.flying"));
- this.disconnect((Component) Component.translatable("multiplayer.disconnect.flying"));
+ this.disconnect(io.papermc.paper.configuration.GlobalConfiguration.get().messages.kick.flyingVehicle); // Paper - use configurable kick message
return;
}

View file

@ -85,8 +85,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
private ExplosionInteraction() {}
return this.id;
}
}
+ // Paper start - respect global sound events gamerule
+ public List<net.minecraft.server.level.ServerPlayer> getPlayersForGlobalSoundGamerule() {

View file

@ -35,20 +35,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ private static final java.util.Comparator<Holder<Enchantment>> ENCHANTMENT_ORDER = java.util.Comparator.comparing(Holder::getRegisteredName);
+ public static final ItemEnchantments EMPTY = new ItemEnchantments(new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER), true);
+ // Paper end
public static final int MAX_LEVEL = 255;
private static final Codec<Integer> LEVEL_CODEC = Codec.intRange(0, 255);
- private static final Codec<Object2IntOpenHashMap<Holder<Enchantment>>> LEVELS_CODEC = Codec.unboundedMap(
+ private static final Codec<Object2IntAVLTreeMap<Holder<Enchantment>>> LEVELS_CODEC = Codec.unboundedMap( // Paper
BuiltInRegistries.ENCHANTMENT.holderByNameCodec(), LEVEL_CODEC
)
- private static final Codec<Object2IntOpenHashMap<Holder<Enchantment>>> LEVELS_CODEC = Codec.unboundedMap(Enchantment.CODEC, LEVEL_CODEC)
- .xmap(Object2IntOpenHashMap::new, Function.identity());
+ // Paper start - sort enchantments
+ private static final Codec<Object2IntAVLTreeMap<Holder<Enchantment>>> LEVELS_CODEC = Codec.unboundedMap(
+ Enchantment.CODEC, LEVEL_CODEC
+ )// Paper start - sort enchantments
+ .xmap(m -> {
+ final Object2IntAVLTreeMap<Holder<Enchantment>> map = new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER);
+ map.putAll(m);
+ return map;
+ }, Function.identity());
+ // Paper end - sort enchantments
+ // Paper end - sort enchantments
private static final Codec<ItemEnchantments> FULL_CODEC = RecordCodecBuilder.create(
instance -> instance.group(
LEVELS_CODEC.fieldOf("levels").forGetter(component -> component.enchantments),
@ -56,8 +54,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
);
public static final Codec<ItemEnchantments> CODEC = Codec.withAlternative(FULL_CODEC, LEVELS_CODEC, map -> new ItemEnchantments(map, true));
public static final StreamCodec<RegistryFriendlyByteBuf, ItemEnchantments> STREAM_CODEC = StreamCodec.composite(
- ByteBufCodecs.map(Object2IntOpenHashMap::new, ByteBufCodecs.holderRegistry(Registries.ENCHANTMENT), ByteBufCodecs.VAR_INT),
+ ByteBufCodecs.map((v) -> new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER), ByteBufCodecs.holderRegistry(Registries.ENCHANTMENT), ByteBufCodecs.VAR_INT), // Paper
- ByteBufCodecs.map(Object2IntOpenHashMap::new, Enchantment.STREAM_CODEC, ByteBufCodecs.VAR_INT),
+ ByteBufCodecs.map((v) -> new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER), Enchantment.STREAM_CODEC, ByteBufCodecs.VAR_INT),
component -> component.enchantments,
ByteBufCodecs.BOOL,
component -> component.showInTooltip,
@ -102,7 +100,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ this.setItemMeta(itemMeta);
}
- ItemEnchantments.Mutable listCopy = new ItemEnchantments.Mutable(list);
- listCopy.set(CraftEnchantment.bukkitToMinecraft(ench), level);
- listCopy.set(CraftEnchantment.bukkitToMinecraftHolder(ench), level);
- this.handle.set(DataComponents.ENCHANTMENTS, listCopy.toImmutable());
+ // Paper end
}
@ -135,7 +133,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
-
- ItemEnchantments.Mutable listCopy = new ItemEnchantments.Mutable(list);
- listCopy.set(CraftEnchantment.bukkitToMinecraft(ench), -1); // Negative to remove
- listCopy.set(CraftEnchantment.bukkitToMinecraftHolder(ench), -1); // Negative to remove
- this.handle.set(DataComponents.ENCHANTMENTS, listCopy.toImmutable());
+ // Paper end

View file

@ -530,7 +530,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@ public interface RandomizableContainer extends Container {
default boolean tryLoadLootTable(CompoundTag nbt) {
if (nbt.contains("LootTable", 8)) {
this.setLootTable(ResourceKey.create(Registries.LOOT_TABLE, new ResourceLocation(nbt.getString("LootTable"))));
this.setLootTable(ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.parse(nbt.getString("LootTable"))));
+ if (this.lootableData() != null && this.getLootTable() != null) this.lootableData().loadNbt(nbt); // Paper - LootTable API
if (nbt.contains("LootTableSeed", 4)) {
this.setLootTableSeed(nbt.getLong("LootTableSeed"));
@ -663,7 +663,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
default void readChestVehicleSaveData(CompoundTag nbt, HolderLookup.Provider registriesLookup) {
this.clearItemStacks();
if (nbt.contains("LootTable", 8)) {
this.setLootTable(ResourceKey.create(Registries.LOOT_TABLE, new ResourceLocation(nbt.getString("LootTable"))));
this.setLootTable(ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.parse(nbt.getString("LootTable"))));
+ // Paper start - LootTable API
+ if (this.getLootTable() != null) {
+ this.lootableData().loadNbt(nbt);

View file

@ -37,8 +37,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
private void explode() {
@@ -0,0 +0,0 @@ public class PrimedTnt extends Entity implements TraceableEntity {
public BlockState getBlockState() {
return (BlockState) this.entityData.get(PrimedTnt.DATA_BLOCK_STATE_ID);
return entity;
}
+
+ // Paper start - Option to prevent TNT from moving in water

View file

@ -20,8 +20,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ this.internalSetAbsorptionAmount(absorptionAmount);
+ // Paper end - Check for NaN
if (nbt.contains("Attributes", 9) && this.level() != null && !this.level().isClientSide) {
this.getAttributes().load(nbt.getList("Attributes", 10));
if (nbt.contains("attributes", 9) && this.level() != null && !this.level().isClientSide) {
this.getAttributes().load(nbt.getList("attributes", 10));
}
@@ -0,0 +0,0 @@ public abstract class LivingEntity extends Entity implements Attackable {
}

View file

@ -11,7 +11,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -0,0 +0,0 @@ import co.aikar.timings.MinecraftTimings; // Paper
public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTask> implements ServerInfo, CommandSource, AutoCloseable {
public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTask> implements ServerInfo, ChunkIOErrorReporter, CommandSource, AutoCloseable {
+ private static MinecraftServer SERVER; // Paper
public static final Logger LOGGER = LogUtils.getLogger();