Skip to content

Commit

Permalink
1.21.4 (hard fork) - server
Browse files Browse the repository at this point in the history
  • Loading branch information
Blast-MC committed Jan 14, 2025
1 parent 4f5a0f4 commit 97a0af2
Show file tree
Hide file tree
Showing 39 changed files with 1,203 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--- a/io/papermc/paper/command/subcommands/FixLightCommand.java
+++ b/io/papermc/paper/command/subcommands/FixLightCommand.java
@@ -95,16 +_,20 @@
((StarLightLightingProvider)lightengine).starlight$serverRelightChunks(chunks,
(final ChunkPos chunkPos) -> {
++relitChunks[0];
- sender.getBukkitEntity().sendMessage(text().color(DARK_AQUA).append(
- text("Relit chunk ", BLUE), text(chunkPos.toString()),
- text(", progress: ", BLUE), text(ONE_DECIMAL_PLACES.get().format(100.0 * (double) (relitChunks[0]) / (double) pending[0]) + "%")
+ sender.getBukkitEntity().sendActionBar(text().color(DARK_AQUA).append(
+ text("Relighting Chunks: ", DARK_AQUA), text(chunkPos.toString()),
+ text(" " + relitChunks[0], net.kyori.adventure.text.format.NamedTextColor.YELLOW),
+ text("/", DARK_AQUA),
+ text(pending[0] + " ", net.kyori.adventure.text.format.NamedTextColor.YELLOW),
+ text("(" + (int) (Math.round(100.0 * (double) (relitChunks[0]) / (double) pending[0])) + "%)", net.kyori.adventure.text.format.NamedTextColor.YELLOW)
));
},
(final int totalRelit) -> {
final long end = System.nanoTime();
+ final long diff = Math.round(1.0e-6 * (end - start));
sender.getBukkitEntity().sendMessage(text().color(DARK_AQUA).append(
- text("Relit ", BLUE), text(totalRelit),
- text(" chunks. Took ", BLUE), text(ONE_DECIMAL_PLACES.get().format(1.0e-6 * (end - start)) + "ms")
+ text("Relit ", DARK_AQUA), text(totalRelit, net.kyori.adventure.text.format.NamedTextColor.YELLOW),
+ text(" chunks. Took ", DARK_AQUA), text(diff + "ms", net.kyori.adventure.text.format.NamedTextColor.YELLOW)
));
if (done != null) {
done.run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- a/net/minecraft/core/Holder.java
+++ b/net/minecraft/core/Holder.java
@@ -138,6 +_,12 @@
return new Holder.Reference<>(Holder.Reference.Type.INTRUSIVE, owner, null, value);
}

+ // Parchment start
+ public static <T> Holder.Reference<T> create(HolderOwner<T> owner, @Nullable ResourceKey<T> registryKey, @Nullable T value) {
+ return new Holder.Reference<>(Holder.Reference.Type.STAND_ALONE, owner, registryKey, value);
+ }
+ // Parchment end
+
public ResourceKey<T> key() {
if (this.key == null) {
throw new IllegalStateException("Trying to access unbound value '" + this.value + "' from registry " + this.owner);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -272,6 +_,8 @@
return false;
}

+ gg.projecteden.parchment.entity.EntityDataServices.init();
+
// CraftBukkit start
// this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage)); // Spigot - moved up
this.server.loadPlugins();
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -1053,7 +_,7 @@

private void announceSleepStatus() {
if (this.canSleepThroughNights()) {
- if (!this.getServer().isSingleplayer() || this.getServer().isPublished()) {
+ if (false && !this.getServer().isSingleplayer() || this.getServer().isPublished()) {
int _int = this.getGameRules().getInt(GameRules.RULE_PLAYERS_SLEEPING_PERCENTAGE);
Component component;
if (this.sleepStatus.areEnoughSleeping(_int)) {
@@ -1623,28 +_,47 @@

@Override
public void playSeededSound(
- @Nullable Player player, double x, double y, double z, Holder<SoundEvent> sound, SoundSource category, float volume, float pitch, long seed
- ) {
- this.server
- .getPlayerList()
- .broadcast(
- player, x, y, z, sound.value().getRange(volume), this.dimension(), new ClientboundSoundPacket(sound, category, x, y, z, volume, pitch, seed)
- );
+ @Nullable Player player, double x, double y, double z, Holder<SoundEvent> sound, SoundSource category, float volume, float pitch, long seed) {
+ // Parchment start - sound event
+ org.bukkit.craftbukkit.event.CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.SoundEvent(
+ player == null ? null : player.getBukkitEntity(),
+ net.kyori.adventure.sound.Sound.sound()
+ .type(sound.unwrap().<net.kyori.adventure.key.Key>map(
+ key -> io.papermc.paper.adventure.PaperAdventure.asAdventure(key.location()),
+ soundEvent -> io.papermc.paper.adventure.PaperAdventure.asAdventure(soundEvent.location())
+ ))
+ .source(io.papermc.paper.adventure.PaperAdventure.asAdventure(category))
+ .volume(volume)
+ .pitch(pitch)
+ .seed(seed)
+ .build(),
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(this, x, y, z),
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.DISTANCE_FUNCTION,
+ null
+ ));
+ // Parchment end
}

@Override
public void playSeededSound(@Nullable Player player, Entity entity, Holder<SoundEvent> sound, SoundSource category, float volume, float pitch, long seed) {
- this.server
- .getPlayerList()
- .broadcast(
- player,
- entity.getX(),
- entity.getY(),
- entity.getZ(),
- sound.value().getRange(volume),
- this.dimension(),
- new ClientboundSoundEntityPacket(sound, category, entity, volume, pitch, seed)
- );
+ // Parchment start - sound event
+ org.bukkit.craftbukkit.event.CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.SoundEvent(
+ player == null ? null : player.getBukkitEntity(),
+ net.kyori.adventure.sound.Sound.sound()
+ .type(sound.unwrap().<net.kyori.adventure.key.Key>map(
+ key -> io.papermc.paper.adventure.PaperAdventure.asAdventure(key.location()),
+ soundEvent -> io.papermc.paper.adventure.PaperAdventure.asAdventure(soundEvent.location())
+ ))
+ .source(io.papermc.paper.adventure.PaperAdventure.asAdventure(category))
+ .volume(volume)
+ .pitch(pitch)
+ .seed(seed)
+ .build(),
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(entity),
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.DISTANCE_FUNCTION,
+ null
+ ));
+ // Parchment end
}

@Override
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -176,6 +_,7 @@
import net.minecraft.world.scores.ScoreHolder;
import net.minecraft.world.scores.Team;
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
+import org.bukkit.SoundCategory;
import org.slf4j.Logger;

public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patches.chunk_system.player.ChunkSystemServerPlayer { // Paper - rewrite chunk system
@@ -2546,7 +_,7 @@
// Paper end - Add PlayerSetSpawnEvent

if (event.willNotifyPlayer() && event.getNotification() != null) { // Paper - Add PlayerSetSpawnEvent
- this.sendSystemMessage(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.getNotification())); // Paper - Add PlayerSetSpawnEvent
+ //this.sendSystemMessage(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.getNotification())); // Paper - Add PlayerSetSpawnEvent
}

this.respawnPosition = position;
@@ -2581,12 +_,20 @@

@Override
public void playNotifySound(SoundEvent sound, SoundSource source, float volume, float pitch) {
- this.connection
- .send(
- new ClientboundSoundPacket(
- BuiltInRegistries.SOUND_EVENT.wrapAsHolder(sound), source, this.getX(), this.getY(), this.getZ(), volume, pitch, this.random.nextLong()
- )
- );
+ // Parchment start - sound event
+ org.bukkit.craftbukkit.event.CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.SoundEvent(
+ null,
+ net.kyori.adventure.sound.Sound.sound()
+ .type(io.papermc.paper.adventure.PaperAdventure.asAdventure(sound.location()))
+ .source(io.papermc.paper.adventure.PaperAdventure.asAdventure(source))
+ .volume(volume)
+ .pitch(pitch)
+ .seed(this.random.nextLong())
+ .build(),
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(level(), getX(), getY(), getZ()),
+ _sound -> 0d, soundEvent -> java.util.Collections.singletonList(getBukkitEntity())
+ ));
+ // Parchment end
}

@Override
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -778,9 +_,12 @@
public void handleCustomCommandSuggestions(ServerboundCommandSuggestionPacket packet) {
// PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); // Paper - AsyncTabCompleteEvent; run this async
// CraftBukkit start
- if (!this.tabSpamThrottler.isIncrementAndUnderThreshold() && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) { // Paper - configurable tab spam limits
- this.disconnectAsync(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - Kick event cause // Paper - add proper async disconnect
- return;
+ if (!this.getCraftPlayer().hasPermission("spam.bypass")) { // Parchment - spam bypass
+ if (!this.tabSpamThrottler.isIncrementAndUnderThreshold() && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) { // Paper - configurable tab spam limits
+ this.disconnectAsync(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - Kick event cause // Paper - add proper async disconnect
+ return;
+
+ }
}
// CraftBukkit end
// Paper start - Don't suggest if tab-complete is disabled
@@ -2490,6 +_,7 @@

// Spigot start - spam exclusions
private void detectRateSpam(String message) {
+ if (this.getCraftPlayer().hasPermission("spam.bypass")) return; // Parchment - spam bypass
// CraftBukkit start - replaced with thread safe throttle
for (String exclude : org.spigotmc.SpigotConfig.spamExclusions) {
if (exclude != null && message.startsWith(exclude)) {
@@ -3245,9 +_,11 @@
public void handlePlaceRecipe(ServerboundPlaceRecipePacket packet) {
// Paper start - auto recipe limit
if (!org.bukkit.Bukkit.isPrimaryThread()) {
- if (!this.recipeSpamPackets.isIncrementAndUnderThreshold()) {
- this.disconnectAsync(net.minecraft.network.chat.Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - kick event cause // Paper - add proper async disconnect
- return;
+ if (!this.getCraftPlayer().hasPermission("spam.bypass")) { // Parchment - spam bypass
+ if (!this.recipeSpamPackets.isIncrementAndUnderThreshold()) {
+ this.disconnectAsync(net.minecraft.network.chat.Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - kick event cause // Paper - add proper async disconnect
+ return;
+ }
}
}
// Paper end - auto recipe limit
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -802,19 +_,7 @@
if (!keepInventory && respawnPosition != null && level1 != null) {
BlockState blockState = level1.getBlockState(respawnPosition);
if (blockState.is(Blocks.RESPAWN_ANCHOR)) {
- serverPlayer.connection
- .send(
- new ClientboundSoundPacket(
- SoundEvents.RESPAWN_ANCHOR_DEPLETE,
- SoundSource.BLOCKS,
- respawnPosition.getX(),
- respawnPosition.getY(),
- respawnPosition.getZ(),
- 1.0F,
- 1.0F,
- level.getRandom().nextLong()
- )
- );
+ player.playNotifySound(SoundEvents.RESPAWN_ANCHOR_DEPLETE.value(), SoundSource.BLOCKS, 1.0F, 1.0F); // Parchment - use existing play sound method
}
// Paper start - Add PlayerPostRespawnEvent
if (blockState.is(net.minecraft.tags.BlockTags.BEDS) && !teleportTransition.missingRespawnBlock()) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -5081,4 +_,31 @@
return ((ServerLevel) this.level).isPositionEntityTicking(this.blockPosition());
}
// Paper end - Expose entity id counter
+
+
+ @javax.annotation.Nullable
+ private gg.projecteden.parchment.entity.EntityData storedEntityData;
+
+ /**
+ * Retrieves the stored EntityData for this entity
+ * @return The currently stored EntityData
+ */
+ public gg.projecteden.parchment.entity.EntityData getStoredEntityData() {
+ if (this.storedEntityData == null) {
+ this.storedEntityData = gg.projecteden.parchment.entity.EntityData.create(this.getBukkitEntity());
+ }
+ return this.storedEntityData;
+ }
+
+ /**
+ * Clears the currently stored EntityData for this entity
+ * @return the previously stored EntityData
+ */
+ public @javax.annotation.Nullable gg.projecteden.parchment.entity.EntityData clearStoredEntityData() {
+ gg.projecteden.parchment.entity.EntityData data = this.storedEntityData;
+ this.storedEntityData = null;
+
+ return data;
+ }
+
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -4087,7 +_,7 @@
Vec3 direction = this.getLookAngle();
Vec3 end = start.add(direction.x * maxDistance, direction.y * maxDistance, direction.z * maxDistance);

- List<Entity> entityList = this.level().getEntities(this, getBoundingBox().expandTowards(direction.x * maxDistance, direction.y * maxDistance, direction.z * maxDistance).inflate(1.0D, 1.0D, 1.0D), EntitySelector.NO_SPECTATORS.and(Entity::isPickable));
+ List<Entity> entityList = this.level().getEntities(this, getBoundingBox().expandTowards(direction.x * maxDistance, direction.y * maxDistance, direction.z * maxDistance).inflate(1.0D, 1.0D, 1.0D), EntitySelector.NO_SPECTATORS.and(entity -> entity.isPickable() || entity instanceof Display)); // Parchment - add displays;

double distance = 0.0D;
net.minecraft.world.phys.EntityHitResult result = null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--- a/net/minecraft/world/entity/decoration/HangingEntity.java
+++ b/net/minecraft/world/entity/decoration/HangingEntity.java
@@ -23,6 +_,9 @@
protected static final Predicate<Entity> HANGING_ENTITY = entity -> entity instanceof HangingEntity;
protected Direction direction = Direction.SOUTH;

+ private int checkInterval; { this.checkInterval = this.getId() % this.level().spigotConfig.hangingTickFrequency; } // Paper - Perf: offset item frame ticking
+ public boolean tick = true; // Parchment
+
protected HangingEntity(EntityType<? extends HangingEntity> entityType, Level level) {
super(entityType, level);
}
@@ -116,4 +_,38 @@
public float mirror(Mirror transformMirror) {
return this.rotate(transformMirror.getRotation(this.direction));
}
+
+ @Override
+ public void tick() {
+ if (tick && !this.level().isClientSide) { // Parchment
+ this.checkBelowWorld();
+ if (this.checkInterval++ == this.level().spigotConfig.hangingTickFrequency) { // Spigot
+ this.checkInterval = 0;
+ if (!this.isRemoved() && !this.survives()) {
+ // CraftBukkit start - fire break events
+ BlockState material = this.level().getBlockState(this.blockPosition());
+ org.bukkit.event.hanging.HangingBreakEvent.RemoveCause cause;
+
+ if (!material.isAir()) {
+ // TODO: This feels insufficient to catch 100% of suffocation cases
+ cause = org.bukkit.event.hanging.HangingBreakEvent.RemoveCause.OBSTRUCTION;
+ } else {
+ cause = org.bukkit.event.hanging.HangingBreakEvent.RemoveCause.PHYSICS;
+ }
+
+ org.bukkit.event.hanging.HangingBreakEvent event = new org.bukkit.event.hanging.HangingBreakEvent((org.bukkit.entity.Hanging) this.getBukkitEntity(), cause);
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (this.isRemoved() || event.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
+ this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DROP); // CraftBukkit - add Bukkit remove cause
+ this.dropItem((ServerLevel) this.level(), (Entity) null);
+ }
+ }
+ }
+
+ }
+
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--- a/net/minecraft/world/entity/monster/AbstractSkeleton.java
+++ b/net/minecraft/world/entity/monster/AbstractSkeleton.java
@@ -202,6 +_,12 @@
ItemStack itemInHand = this.getItemInHand(ProjectileUtil.getWeaponHoldingHand(this, Items.BOW));
ItemStack projectile = this.getProjectile(itemInHand);
AbstractArrow arrow = this.getArrow(projectile, distanceFactor, itemInHand);
+
+ // Parchment start
+ gg.projecteden.parchment.event.entity.PreEntityShootBowEvent preEvent = new gg.projecteden.parchment.event.entity.PreEntityShootBowEvent(this.getBukkitEntity(), this.getMainHandItem().asBukkitCopy(), itemstack1.asBukkitCopy());
+ if (!preEvent.callEvent()) return;
+ // Parchment end
+
double d = target.getX() - this.getX();
double d1 = target.getY(0.3333333333333333) - arrow.getY();
double d2 = target.getZ() - this.getZ();
@@ -217,7 +_,7 @@
if (event.getProjectile() == arrow.getBukkitEntity()) {
// CraftBukkit end
Projectile.spawnProjectileUsingShoot(
- arrow, serverLevel, projectile, d, d1 + squareRoot * 0.2F, d2, 1.6F, 14 - serverLevel.getDifficulty().getId() * 4
+ arrow, serverLevel, projectile, d, d1 + squareRoot * 0.2F, d2, 1.6F, 14 - serverLevel.getDifficulty().getId() * 4, preEvent.isRelative()
);
} // CraftBukkit
}
Loading

0 comments on commit 97a0af2

Please sign in to comment.