reapply stored bee api patches

This commit is contained in:
granny
2024-04-29 00:51:29 -07:00
parent 79d7e7f17b
commit f0d8a13a1f
13 changed files with 31 additions and 32 deletions

View File

@@ -5,18 +5,18 @@ Subject: [PATCH] Stored Bee API
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java diff --git a/src/main/java/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java
index ba610e05806ad020d439d59d30b820bc9cd3fbff..6afaab31539667667481f7e9bfc0c6846abe661a 100644 index d8efb00c325448d566c59418fe22268c6eb4cfce..f7a6ab35c95ffda73f17843916ddb624ad290b42 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java --- a/src/main/java/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java +++ b/src/main/java/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java
@@ -134,6 +134,22 @@ public class BeehiveBlockEntity extends BlockEntity { @@ -146,11 +146,33 @@ public class BeehiveBlockEntity extends BlockEntity {
return list; return list;
} }
+ // Purpur start + // Purpur start
+ public List<Entity> releaseBee(BlockState iblockdata, BeeData data, BeehiveBlockEntity.BeeReleaseStatus tileentitybeehive_releasestatus, boolean force) { + public List<Entity> releaseBee(BlockState iblockdata, BeehiveBlockEntity.BeeData data, BeehiveBlockEntity.BeeReleaseStatus tileentitybeehive_releasestatus, boolean force) {
+ List<Entity> list = Lists.newArrayList(); + List<Entity> list = Lists.newArrayList();
+ +
+ BeehiveBlockEntity.releaseBee(this.level, this.worldPosition, iblockdata, data, list, tileentitybeehive_releasestatus, this.savedFlowerPos, force); + BeehiveBlockEntity.releaseOccupant(this.level, this.worldPosition, iblockdata, data.occupant, list, tileentitybeehive_releasestatus, this.savedFlowerPos, force);
+ +
+ if (!list.isEmpty()) { + if (!list.isEmpty()) {
+ stored.remove(data); + stored.remove(data);
@@ -28,10 +28,8 @@ index ba610e05806ad020d439d59d30b820bc9cd3fbff..6afaab31539667667481f7e9bfc0c684
+ } + }
+ // Purpur end + // Purpur end
+ +
public void addOccupant(Entity entity, boolean hasNectar) { @VisibleForDebug
this.addOccupantWithPresetTicks(entity, hasNectar, 0); public int getOccupantCount() {
}
@@ -143,6 +159,12 @@ public class BeehiveBlockEntity extends BlockEntity {
return this.stored.size(); return this.stored.size();
} }
@@ -44,20 +42,20 @@ index ba610e05806ad020d439d59d30b820bc9cd3fbff..6afaab31539667667481f7e9bfc0c684
// Paper start - Add EntityBlockStorage clearEntities // Paper start - Add EntityBlockStorage clearEntities
public void clearBees() { public void clearBees() {
this.stored.clear(); this.stored.clear();
@@ -435,9 +457,9 @@ public class BeehiveBlockEntity extends BlockEntity { @@ -471,9 +493,9 @@ public class BeehiveBlockEntity extends BlockEntity {
private BeeReleaseStatus() {} }
} }
- private static class BeeData { - private static class BeeData {
+ public static class BeeData { // Purpur - change from private to public + public static class BeeData { // Purpur - change from private to public
- final CompoundTag entityData; - private final BeehiveBlockEntity.Occupant occupant;
+ public final CompoundTag entityData; // Purpur - make public + public final BeehiveBlockEntity.Occupant occupant; // Purpur - make public
int ticksInHive; private int exitTickCounter; // Paper - Fix bees aging inside hives; separate counter for checking if bee should exit to reduce exit attempts
int exitTickCounter; // Paper - Fix bees aging inside hives; separate counter for checking if bee should exit to reduce exit attempts private int ticksInHive;
final int minOccupationTicks;
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java
index 2e51fab98d95c93d2095f7be6dbb5d5474158bfb..32285c8e0f42897793759fba85a1e8658750c843 100644 index 1a2a05160ba51d9c75f1ae6ae61d944d81428722..3beb26ad2ef0fded49a8da8c5dec64f9508c1995 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java
@@ -16,8 +16,15 @@ import org.bukkit.entity.Bee; @@ -16,8 +16,15 @@ import org.bukkit.entity.Bee;
@@ -75,7 +73,7 @@ index 2e51fab98d95c93d2095f7be6dbb5d5474158bfb..32285c8e0f42897793759fba85a1e865
+ // Purpur end + // Purpur end
} }
protected CraftBeehive(CraftBeehive state) { protected CraftBeehive(CraftBeehive state, Location location) {
@@ -75,15 +82,54 @@ public class CraftBeehive extends CraftBlockEntityState<BeehiveBlockEntity> impl @@ -75,15 +82,54 @@ public class CraftBeehive extends CraftBlockEntityState<BeehiveBlockEntity> impl
bees.add((Bee) bee.getBukkitEntity()); bees.add((Bee) bee.getBukkitEntity());
} }
@@ -120,20 +118,20 @@ index 2e51fab98d95c93d2095f7be6dbb5d5474158bfb..32285c8e0f42897793759fba85a1e865
public void addEntity(Bee entity) { public void addEntity(Bee entity) {
Preconditions.checkArgument(entity != null, "Entity must not be null"); Preconditions.checkArgument(entity != null, "Entity must not be null");
- this.getSnapshot().addOccupant(((CraftBee) entity).getHandle(), false); - this.getSnapshot().addOccupant(((CraftBee) entity).getHandle());
+ int length = this.getSnapshot().getStored().size(); // Purpur + int length = this.getSnapshot().getStored().size(); // Purpur
+ getSnapshot().addOccupant(((CraftBee) entity).getHandle(), false); + getSnapshot().addOccupant(((CraftBee) entity).getHandle());
+ +
+ // Purpur start - check if new bee was added, and if yes, add to stored bees + // Purpur start - check if new bee was added, and if yes, add to stored bees
+ List<BeehiveBlockEntity.BeeData> s = this.getSnapshot().getStored(); + List<BeehiveBlockEntity.BeeData> storedBeeData = this.getSnapshot().getStored();
+ if(length < s.size()) { + if(length < storedBeeData.size()) {
+ storage.add(new org.purpurmc.purpur.entity.PurpurStoredBee(s.get(s.size() - 1), this)); + storage.add(new org.purpurmc.purpur.entity.PurpurStoredBee(storedBeeData.getLast(), this));
+ } + }
+ // Purpur end + // Purpur end
} }
@Override @Override
@@ -95,6 +141,7 @@ public class CraftBeehive extends CraftBlockEntityState<BeehiveBlockEntity> impl @@ -100,6 +146,7 @@ public class CraftBeehive extends CraftBlockEntityState<BeehiveBlockEntity> impl
@Override @Override
public void clearEntities() { public void clearEntities() {
getSnapshot().clearBees(); getSnapshot().clearBees();
@@ -143,15 +141,16 @@ index 2e51fab98d95c93d2095f7be6dbb5d5474158bfb..32285c8e0f42897793759fba85a1e865
} }
diff --git a/src/main/java/org/purpurmc/purpur/entity/PurpurStoredBee.java b/src/main/java/org/purpurmc/purpur/entity/PurpurStoredBee.java diff --git a/src/main/java/org/purpurmc/purpur/entity/PurpurStoredBee.java b/src/main/java/org/purpurmc/purpur/entity/PurpurStoredBee.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..8efca1d91188ac4db911a8eb0fa9ea2cc3c48e28 index 0000000000000000000000000000000000000000..25d718489a1a589d9754b8a02340cec819eec6d8
--- /dev/null --- /dev/null
+++ b/src/main/java/org/purpurmc/purpur/entity/PurpurStoredBee.java +++ b/src/main/java/org/purpurmc/purpur/entity/PurpurStoredBee.java
@@ -0,0 +1,102 @@ @@ -0,0 +1,103 @@
+package org.purpurmc.purpur.entity; +package org.purpurmc.purpur.entity;
+ +
+import io.papermc.paper.adventure.PaperAdventure; +import io.papermc.paper.adventure.PaperAdventure;
+import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.Component;
+import net.minecraft.nbt.Tag; +import net.minecraft.nbt.Tag;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.world.level.block.entity.BeehiveBlockEntity; +import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
+import org.bukkit.block.EntityBlockStorage; +import org.bukkit.block.EntityBlockStorage;
+import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer; +import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
@@ -177,12 +176,12 @@ index 0000000000000000000000000000000000000000..8efca1d91188ac4db911a8eb0fa9ea2c
+ this.handle = data; + this.handle = data;
+ this.blockStorage = blockStorage; + this.blockStorage = blockStorage;
+ +
+ this.customName = handle.entityData.contains("CustomName", Tag.TAG_STRING) + this.customName = handle.occupant.entityData().contains("CustomName")
+ ? PaperAdventure.asAdventure(net.minecraft.network.chat.Component.Serializer.fromJson(handle.entityData.getString("CustomName"))) + ? PaperAdventure.asAdventure(net.minecraft.network.chat.Component.Serializer.fromJson(handle.occupant.entityData().getUnsafe().getString("CustomName"), MinecraftServer.getDefaultRegistryAccess()))
+ : null; + : null;
+ +
+ if(handle.entityData.contains("BukkitValues", Tag.TAG_COMPOUND)) { + if(handle.occupant.entityData().getUnsafe().contains("BukkitValues", Tag.TAG_COMPOUND)) {
+ this.persistentDataContainer.putAll(handle.entityData.getCompound("BukkitValues")); + this.persistentDataContainer.putAll(handle.occupant.entityData().getUnsafe().getCompound("BukkitValues"));
+ } + }
+ } + }
+ +
@@ -241,11 +240,11 @@ index 0000000000000000000000000000000000000000..8efca1d91188ac4db911a8eb0fa9ea2c
+ +
+ @Override + @Override
+ public void update() { + public void update() {
+ handle.entityData.put("BukkitValues", this.persistentDataContainer.toTagCompound()); + handle.occupant.entityData().copyTag().put("BukkitValues", this.persistentDataContainer.toTagCompound());
+ if(customName == null) { + if(customName == null) {
+ handle.entityData.remove("CustomName"); + handle.occupant.entityData().copyTag().remove("CustomName");
+ } else { + } else {
+ handle.entityData.putString("CustomName", net.minecraft.network.chat.Component.Serializer.toJson(PaperAdventure.asVanilla(customName))); + handle.occupant.entityData().copyTag().putString("CustomName", net.minecraft.network.chat.Component.Serializer.toJson(PaperAdventure.asVanilla(customName), MinecraftServer.getDefaultRegistryAccess()));
+ } + }
+ } + }
+} +}