Purpur/patches/server/0237-Give-bee-counts-in-beehives-to-Purpur-clients.patch
granny 969064029c
Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@d129162 Properly handle BlockBreakEvent#isDropItems (#8936)
PaperMC/Paper@67a1a8c Fix Inventory#getLocation not working for the composter (#9596)
PaperMC/Paper@5b34a09 Add option to disable chorus plant and mushroom block updates (#9442)
PaperMC/Paper@ed8401c Fix rotation for spawning display entities (#9552)
PaperMC/Paper@bd67b83 Determine lava and water fluid explosion resistance by their block explosion resistance (#9482)
PaperMC/Paper@d928dda Don't tab-complete namespaced commands if `send-namespaced` is false (#9366)
PaperMC/Paper@f43a19c Fix CME in CraftPersistentDataTypeRegistry (#6701)
PaperMC/Paper@45ba652 [ci skip] Rebuild patches
PaperMC/Paper@990765b Fire entity death event for ender dragon (#9495)
PaperMC/Paper@1259b93 Fixed CraftItemStack/CraftItemMeta enchantment level inconsistency (#8792)
PaperMC/Paper@88891c3  Add Entity Coordinate and Rotation API (#9461)
PaperMC/Paper@5bf82aa Add cancellability to PlayerTrackEntityEvent (#8605)
PaperMC/Paper@1b96c64 Improve cancelling PreCreatureSpawnEvent with per player mob spawns (#9400)
PaperMC/Paper@7232506 Add entity tracker min Y distance config option (#9406)
PaperMC/Paper@00a68b1 Player listing API (#8782)
PaperMC/Paper@af6142e [ci skip] Update Gradle wrapper
PaperMC/Paper@281855c Remove unused lag-compensate-block-breaking option (#9635)
PaperMC/Paper@35ef053 [ci skip] update editorconfig and gitattributes (#9608)
PaperMC/Paper@97b9c4a Fix NPE on Boat#getStatus (#9115)
PaperMC/Paper@2be57c6 Expand Pose API (#8781)
PaperMC/Paper@b29ecd4 Expose clicked BlockFace during BlockDamageEvent (#9632)
PaperMC/Paper@e3f29f4 MerchantRecipe: add copy constructor (#8703)
PaperMC/Paper@fed9042 More DragonBattle API (#5655)
PaperMC/Paper@27d39ca Properly clone custom nbt tags inside ItemMeta (#7849)
PaperMC/Paper@0c7385b Add PlayerPickItemEvent (#5590)
PaperMC/Paper@9395aa6 Improve performance of mass crafts (#9603)
PaperMC/Paper@7386a13 Fix endgateway teleportation offset (#9517)
PaperMC/Paper@a712766 Allow custom damage for trident (#8132)
PaperMC/Paper@3716832 Prevent overfilled bundles from duplicating items (#9633)
PaperMC/Paper@9cbad8e Expose Hand during BlockCanBuildEvent (#9636)
2023-08-22 18:41:13 -07:00

118 lines
5.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <blake.galbreath@gmail.com>
Date: Thu, 30 Dec 2021 09:56:43 -0600
Subject: [PATCH] Give bee counts in beehives to Purpur clients
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index cf165386904e4f084ff69463e29fe10fd9af6812..1f6946e1120232d3b104e76212c470f47ed7cde1 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1034,6 +1034,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
public void safeShutdown(boolean waitForShutdown, boolean isRestarting) {
org.purpurmc.purpur.task.BossBarTask.stopAll(); // Purpur
+ org.purpurmc.purpur.task.BeehiveTask.instance().unregister(); // Purpur
this.isRestarting = isRestarting;
this.hasLoggedStop = true; // Paper
if (isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index 62c437f5618032b78d1b68c5c2490d4db9941ce6..af8294476cb0fc322641bbe4168c4b0c020f39fd 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -376,6 +376,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncMobSpawning) mobSpawnExecutor.start(); // Pufferfish
org.purpurmc.purpur.task.BossBarTask.startAll(); // Purpur
+ org.purpurmc.purpur.task.BeehiveTask.instance().register(); // Purpur
return true;
}
}
diff --git a/src/main/java/org/purpurmc/purpur/task/BeehiveTask.java b/src/main/java/org/purpurmc/purpur/task/BeehiveTask.java
new file mode 100644
index 0000000000000000000000000000000000000000..2ebbaf5faa92a88bfb4d61298951e5b74157d1e1
--- /dev/null
+++ b/src/main/java/org/purpurmc/purpur/task/BeehiveTask.java
@@ -0,0 +1,81 @@
+package org.purpurmc.purpur.task;
+
+import com.google.common.io.ByteArrayDataInput;
+import com.google.common.io.ByteArrayDataOutput;
+import com.google.common.io.ByteStreams;
+import io.netty.buffer.Unpooled;
+import net.minecraft.core.BlockPos;
+import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
+import net.minecraft.world.level.block.entity.BlockEntity;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.craftbukkit.scheduler.MinecraftInternalPlugin;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.PluginBase;
+import org.bukkit.plugin.messaging.PluginMessageListener;
+import org.jetbrains.annotations.NotNull;
+
+public class BeehiveTask implements PluginMessageListener {
+ public static final ResourceLocation BEEHIVE_C2S = new ResourceLocation("purpur", "beehive_c2s");
+ public static final ResourceLocation BEEHIVE_S2C = new ResourceLocation("purpur", "beehive_s2c");
+
+ private static BeehiveTask instance;
+
+ public static BeehiveTask instance() {
+ if (instance == null) {
+ instance = new BeehiveTask();
+ }
+ return instance;
+ }
+
+ private final PluginBase plugin = new MinecraftInternalPlugin();
+
+ private BeehiveTask() {
+ }
+
+ public void register() {
+ Bukkit.getMessenger().registerOutgoingPluginChannel(this.plugin, BEEHIVE_S2C.toString());
+ Bukkit.getMessenger().registerIncomingPluginChannel(this.plugin, BEEHIVE_C2S.toString(), this);
+ }
+
+ public void unregister() {
+ Bukkit.getMessenger().unregisterOutgoingPluginChannel(this.plugin, BEEHIVE_S2C.toString());
+ Bukkit.getMessenger().unregisterIncomingPluginChannel(this.plugin, BEEHIVE_C2S.toString());
+ }
+
+ @Override
+ public void onPluginMessageReceived(@NotNull String channel, Player player, byte[] bytes) {
+ ByteArrayDataInput in = in(bytes);
+ long packedPos = in.readLong();
+ BlockPos pos = BlockPos.of(packedPos);
+
+ ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
+
+ BlockEntity blockEntity = serverPlayer.level().getBlockEntity(pos);
+ if (!(blockEntity instanceof BeehiveBlockEntity beehive)) {
+ return;
+ }
+
+ ByteArrayDataOutput out = out();
+
+ out.writeInt(beehive.getOccupantCount());
+ out.writeLong(packedPos);
+
+ FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.wrappedBuffer(out.toByteArray()));
+ serverPlayer.connection.send(new ClientboundCustomPayloadPacket(BEEHIVE_S2C, buf));
+ }
+
+ @SuppressWarnings("UnstableApiUsage")
+ private static ByteArrayDataOutput out() {
+ return ByteStreams.newDataOutput();
+ }
+
+ @SuppressWarnings("UnstableApiUsage")
+ private static ByteArrayDataInput in(byte[] bytes) {
+ return ByteStreams.newDataInput(bytes);
+ }
+}