Skip to content

Commit

Permalink
more work
Browse files Browse the repository at this point in the history
  • Loading branch information
yannicklamprecht committed Feb 24, 2024
1 parent c3f7af3 commit d5128d1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 23 deletions.
41 changes: 28 additions & 13 deletions patches/api/0464-add-biome-change-per-player.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ Subject: [PATCH] add biome change per player

diff --git a/src/main/java/io/papermc/paper/event/packet/PlayerBiomesLoadEvent.java b/src/main/java/io/papermc/paper/event/packet/PlayerBiomesLoadEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..3169868d75ce36a524db2b0df920b9f628d4fd40
index 0000000000000000000000000000000000000000..df6864e4bd3ad030897ac1ccae9ecf456c18747b
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/packet/PlayerBiomesLoadEvent.java
@@ -0,0 +1,67 @@
@@ -0,0 +1,82 @@
+package io.papermc.paper.event.packet;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.bukkit.BiomesSnapshot;
+import org.bukkit.Chunk;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.world.WorldEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
Expand All @@ -28,15 +32,16 @@ index 0000000000000000000000000000000000000000..3169868d75ce36a524db2b0df920b9f6
+ * Should only be used for packet/clientside related stuff.
+ * Not intended for modifying server side state.
+ */
+public class PlayerBiomesLoadEvent extends Event {
+public class PlayerBiomesLoadEvent extends WorldEvent {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final Player player;
+ private BiomesSnapshot biomeSnapshot;
+ private final Map<Chunk, BiomesSnapshot> chunkBiomesSnapshots = new HashMap<>();
+
+ @ApiStatus.Internal
+ public PlayerBiomesLoadEvent(@NotNull final Player player) {
+ public PlayerBiomesLoadEvent(@NotNull final Player player, World world) {
+ super(world);
+ this.player = player;
+ }
+
Expand All @@ -60,21 +65,31 @@ index 0000000000000000000000000000000000000000..3169868d75ce36a524db2b0df920b9f6
+ }
+
+ /**
+ * Returns a biomes snapshot, by default it won't be set.
+ * Returns a biomes snapshot for the given chunk, by default it won't be set.
+ *
+ * @param chunk the given chunk
+ * @return biome snapshot if one is set
+ */
+ public @Nullable BiomesSnapshot getBiomeSnapshot() {
+ return biomeSnapshot;
+ public @Nullable BiomesSnapshot getBiomeSnapshotAt(Chunk chunk) {
+ return chunkBiomesSnapshots.get(chunk);
+ }
+
+ /**
+ * Sets the biome snapshot that will be send as an override to the player
+ * Sets the biome snapshot for the given chunk that will be send as an override to the player
+ *
+ * @param biomeSnapshot the biome override
+ * @param biomesSnapshot the biome override
+ */
+ public void setBiomeSnapshot(@Nullable final BiomesSnapshot biomeSnapshot) {
+ this.biomeSnapshot = biomeSnapshot;
+ public void setBiomeSnapshot(Chunk chunk, @Nullable final BiomesSnapshot biomesSnapshot) {
+ this.chunkBiomesSnapshots.put(chunk, biomesSnapshot);
+ }
+
+ /**
+ * Returns if chunk biomes were overridden
+ *
+ * @return true if override was made, else false
+ */
+ public boolean hasOverrides() {
+ return !this.chunkBiomesSnapshots.isEmpty();
+ }
+}
diff --git a/src/main/java/org/bukkit/BiomesSnapshot.java b/src/main/java/org/bukkit/BiomesSnapshot.java
Expand Down
32 changes: 22 additions & 10 deletions patches/server/1048-add-biome-change-per-player.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] add biome change per player


diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundChunksBiomesPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundChunksBiomesPacket.java
index 51f647de153255c919b1440338cf1b3e2d6b5dbf..c67f600cb74c7b9b747af55c7015f2a8ff0ce6d2 100644
index 51f647de153255c919b1440338cf1b3e2d6b5dbf..f525c51a1c888f76fa56528f204e4fac52416641 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundChunksBiomesPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundChunksBiomesPacket.java
@@ -2,12 +2,20 @@ package net.minecraft.network.protocol.game;
@@ -2,12 +2,22 @@ package net.minecraft.network.protocol.game;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
Expand All @@ -25,27 +25,39 @@ index 51f647de153255c919b1440338cf1b3e2d6b5dbf..c67f600cb74c7b9b747af55c7015f2a8
import net.minecraft.world.level.chunk.LevelChunkSection;
+import net.minecraft.world.level.chunk.PalettedContainer;
+import org.bukkit.BiomesSnapshot;
+import org.bukkit.Chunk;
+import org.bukkit.craftbukkit.CraftBiomesSnapshot;
+import org.bukkit.craftbukkit.CraftChunk;

public record ClientboundChunksBiomesPacket(List<ClientboundChunksBiomesPacket.ChunkBiomeData> chunkBiomeData) implements Packet<ClientGamePacketListener> {
private static final int TWO_MEGABYTES = 2097152;
@@ -16,7 +24,14 @@ public record ClientboundChunksBiomesPacket(List<ClientboundChunksBiomesPacket.C
@@ -16,8 +26,23 @@ public record ClientboundChunksBiomesPacket(List<ClientboundChunksBiomesPacket.C
this(buf.readList(ClientboundChunksBiomesPacket.ChunkBiomeData::new));
}

- public static ClientboundChunksBiomesPacket forChunks(List<LevelChunk> chunks) {
- return new ClientboundChunksBiomesPacket(chunks.stream().map(ClientboundChunksBiomesPacket.ChunkBiomeData::new).toList());
+ public static ClientboundChunksBiomesPacket forChunks(Player player, List<LevelChunk> chunks) {
+
+ final PlayerBiomesLoadEvent biomesLoadEvent = new PlayerBiomesLoadEvent((org.bukkit.entity.Player) player.getBukkitEntity());
+ org.bukkit.entity.Player bukkitPlayer = (org.bukkit.entity.Player) player.getBukkitEntity();
+ final PlayerBiomesLoadEvent biomesLoadEvent = new PlayerBiomesLoadEvent(bukkitPlayer, bukkitPlayer.getWorld());
+ biomesLoadEvent.callEvent();
+ if(biomesLoadEvent.getBiomeSnapshot() != null) {
+ final ChunkBiomeData biomeData = new ChunkBiomeData(biomesLoadEvent.getBiomeSnapshot());
+ if(biomesLoadEvent.hasOverrides()) {
+ return new ClientboundChunksBiomesPacket(chunks.stream().map(levelChunk -> create(levelChunk, biomesLoadEvent)).toList());
+ } else {
+ return new ClientboundChunksBiomesPacket(chunks.stream().map(ClientboundChunksBiomesPacket.ChunkBiomeData::new).toList());
+ }
+ }
+
return new ClientboundChunksBiomesPacket(chunks.stream().map(ClientboundChunksBiomesPacket.ChunkBiomeData::new).toList());
+ private static ClientboundChunksBiomesPacket.ChunkBiomeData create(LevelChunk levelChunk, PlayerBiomesLoadEvent biomesLoadEvent) {
+ final BiomesSnapshot snapshotAt = biomesLoadEvent.getBiomeSnapshotAt(new CraftChunk(levelChunk));
+ if(snapshotAt != null){
+ return new ClientboundChunksBiomesPacket.ChunkBiomeData(snapshotAt);
+ }
+ return new ClientboundChunksBiomesPacket.ChunkBiomeData(levelChunk);
}

@@ -38,6 +53,11 @@ public record ClientboundChunksBiomesPacket(List<ClientboundChunksBiomesPacket.C
@Override
@@ -38,6 +63,11 @@ public record ClientboundChunksBiomesPacket(List<ClientboundChunksBiomesPacket.C
extractChunkData(new FriendlyByteBuf(this.getWriteBuffer()), chunk);
}

Expand All @@ -57,7 +69,7 @@ index 51f647de153255c919b1440338cf1b3e2d6b5dbf..c67f600cb74c7b9b747af55c7015f2a8
public ChunkBiomeData(FriendlyByteBuf buf) {
this(buf.readChunkPos(), buf.readByteArray(2097152));
}
@@ -71,6 +91,25 @@ public record ClientboundChunksBiomesPacket(List<ClientboundChunksBiomesPacket.C
@@ -71,6 +101,25 @@ public record ClientboundChunksBiomesPacket(List<ClientboundChunksBiomesPacket.C

}

Expand Down

0 comments on commit d5128d1

Please sign in to comment.