mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Give bee counts in beehives to Purpur clients
This commit is contained in:
@@ -1,184 +0,0 @@
|
||||
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/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
||||
index 80a8bd2dc32763f8ee2062c2d1b36188f2532523..1dc4476ca1fc41030001d4d23ffff1b810a056cd 100644
|
||||
--- a/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/net/minecraft/server/MinecraftServer.java
|
||||
@@ -1170,6 +1170,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 - Debugging
|
||||
if (isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper - Debugging
|
||||
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
index 683c7c373e1b9f764bb9b53cdaace9740f607c75..509e67eeab1f07ecce3bce0c8c222bc2c184ca6f 100644
|
||||
--- a/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
@@ -399,6 +399,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
||||
}
|
||||
|
||||
org.purpurmc.purpur.task.BossBarTask.startAll(); // Purpur
|
||||
+ if (org.purpurmc.purpur.PurpurConfig.beeCountPayload) org.purpurmc.purpur.task.BeehiveTask.instance().register(); // Purpur
|
||||
return true;
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
index 00f02ad5f248120ce031048e02fe1bacda5567b7..60bb703fdf582bc3ec1081f31818d696e3b276ed 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
|
||||
@@ -435,6 +435,11 @@ public class PurpurConfig {
|
||||
allowWaterPlacementInTheEnd = getBoolean("settings.allow-water-placement-in-the-end", allowWaterPlacementInTheEnd);
|
||||
}
|
||||
|
||||
+ public static boolean beeCountPayload = false;
|
||||
+ private static void beeCountPayload() {
|
||||
+ beeCountPayload = getBoolean("settings.bee-count-payload", beeCountPayload);
|
||||
+ }
|
||||
+
|
||||
public static boolean loggerSuppressInitLegacyMaterialError = false;
|
||||
public static boolean loggerSuppressIgnoredAdvancementWarnings = false;
|
||||
public static boolean loggerSuppressUnrecognizedRecipeErrors = false;
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/network/ClientboundBeehivePayload.java b/src/main/java/org/purpurmc/purpur/network/ClientboundBeehivePayload.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..793a3ea45fe04e84725926f17615c26e008b0ce4
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/purpurmc/purpur/network/ClientboundBeehivePayload.java
|
||||
@@ -0,0 +1,27 @@
|
||||
+package org.purpurmc.purpur.network;
|
||||
+
|
||||
+import net.minecraft.core.BlockPos;
|
||||
+import net.minecraft.network.FriendlyByteBuf;
|
||||
+import net.minecraft.network.codec.StreamCodec;
|
||||
+import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
+import net.minecraft.resources.ResourceLocation;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+public record ClientboundBeehivePayload(BlockPos pos, int numOfBees) implements CustomPacketPayload {
|
||||
+ public static final StreamCodec<FriendlyByteBuf, ClientboundBeehivePayload> STREAM_CODEC = CustomPacketPayload.codec(ClientboundBeehivePayload::write, ClientboundBeehivePayload::new);
|
||||
+ public static final Type<ClientboundBeehivePayload> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath("purpur", "beehive_s2c"));
|
||||
+
|
||||
+ public ClientboundBeehivePayload(FriendlyByteBuf friendlyByteBuf) {
|
||||
+ this(friendlyByteBuf.readBlockPos(), friendlyByteBuf.readInt());
|
||||
+ }
|
||||
+
|
||||
+ private void write(FriendlyByteBuf friendlyByteBuf) {
|
||||
+ friendlyByteBuf.writeBlockPos(this.pos);
|
||||
+ friendlyByteBuf.writeInt(this.numOfBees);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull Type<? extends CustomPacketPayload> type() {
|
||||
+ return TYPE;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/network/ServerboundBeehivePayload.java b/src/main/java/org/purpurmc/purpur/network/ServerboundBeehivePayload.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..fa72769e06061609e1e658a0250e99c8cb026c0e
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/purpurmc/purpur/network/ServerboundBeehivePayload.java
|
||||
@@ -0,0 +1,26 @@
|
||||
+package org.purpurmc.purpur.network;
|
||||
+
|
||||
+import net.minecraft.core.BlockPos;
|
||||
+import net.minecraft.network.FriendlyByteBuf;
|
||||
+import net.minecraft.network.codec.StreamCodec;
|
||||
+import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
+import net.minecraft.resources.ResourceLocation;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+public record ServerboundBeehivePayload(BlockPos pos) implements CustomPacketPayload {
|
||||
+ public static final StreamCodec<FriendlyByteBuf, ServerboundBeehivePayload> STREAM_CODEC = CustomPacketPayload.codec(ServerboundBeehivePayload::write, ServerboundBeehivePayload::new);
|
||||
+ public static final Type<ServerboundBeehivePayload> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath("purpur", "beehive_c2s"));
|
||||
+
|
||||
+ public ServerboundBeehivePayload(FriendlyByteBuf friendlyByteBuf) {
|
||||
+ this(friendlyByteBuf.readBlockPos());
|
||||
+ }
|
||||
+
|
||||
+ private void write(FriendlyByteBuf friendlyByteBuf) {
|
||||
+ friendlyByteBuf.writeBlockPos(this.pos);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull Type<? extends CustomPacketPayload> type() {
|
||||
+ return TYPE;
|
||||
+ }
|
||||
+}
|
||||
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..664f9d5e1ce5e2787bf699bd11758b9e3aa8ed3a
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/purpurmc/purpur/task/BeehiveTask.java
|
||||
@@ -0,0 +1,67 @@
|
||||
+package org.purpurmc.purpur.task;
|
||||
+
|
||||
+import io.netty.buffer.Unpooled;
|
||||
+import net.minecraft.network.FriendlyByteBuf;
|
||||
+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.entity.Player;
|
||||
+import org.bukkit.plugin.PluginBase;
|
||||
+import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.purpurmc.purpur.network.ClientboundBeehivePayload;
|
||||
+import org.purpurmc.purpur.network.ServerboundBeehivePayload;
|
||||
+import org.purpurmc.purpur.util.MinecraftInternalPlugin;
|
||||
+
|
||||
+public class BeehiveTask implements PluginMessageListener {
|
||||
+
|
||||
+ 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, ClientboundBeehivePayload.TYPE.id().toString());
|
||||
+ Bukkit.getMessenger().registerIncomingPluginChannel(this.plugin, ServerboundBeehivePayload.TYPE.id().toString(), this);
|
||||
+ }
|
||||
+
|
||||
+ public void unregister() {
|
||||
+ Bukkit.getMessenger().unregisterOutgoingPluginChannel(this.plugin, ClientboundBeehivePayload.TYPE.id().toString());
|
||||
+ Bukkit.getMessenger().unregisterIncomingPluginChannel(this.plugin, ServerboundBeehivePayload.TYPE.id().toString());
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, byte[] bytes) {
|
||||
+ FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.copiedBuffer(bytes));
|
||||
+ ServerboundBeehivePayload payload = ServerboundBeehivePayload.STREAM_CODEC.decode(byteBuf);
|
||||
+
|
||||
+ ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
||||
+
|
||||
+ // targeted block info max range specified in client at net.minecraft.client.gui.hud.DebugHud#render
|
||||
+ if (!payload.pos().getCenter().closerThan(serverPlayer.position(), 20)) return; // Targeted Block info max range is 20
|
||||
+ if (serverPlayer.level().getChunkIfLoaded(payload.pos()) == null) return;
|
||||
+
|
||||
+ BlockEntity blockEntity = serverPlayer.level().getBlockEntity(payload.pos());
|
||||
+ if (!(blockEntity instanceof BeehiveBlockEntity beehive)) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ ClientboundBeehivePayload customPacketPayload = new ClientboundBeehivePayload(payload.pos(), beehive.getOccupantCount());
|
||||
+ FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
||||
+ ClientboundBeehivePayload.STREAM_CODEC.encode(friendlyByteBuf, customPacketPayload);
|
||||
+ byte[] byteArray = new byte[friendlyByteBuf.readableBytes()];
|
||||
+ friendlyByteBuf.readBytes(byteArray);
|
||||
+ player.sendPluginMessage(this.plugin, customPacketPayload.type().id().toString(), byteArray);
|
||||
+ }
|
||||
+}
|
||||
Reference in New Issue
Block a user