mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Stored Bee API
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: EOT3000 <egor.tolstenkov@outlook.com>
|
||||
Date: Sat, 10 Jun 2023 20:27:14 -0400
|
||||
Subject: [PATCH] Stored Bee API
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/block/EntityBlockStorage.java b/src/main/java/org/bukkit/block/EntityBlockStorage.java
|
||||
index 739911cda33b373f99df627a3a378b37d7d461aa..51e78c22cd021722b963fe31d1d9175d141add1a 100644
|
||||
--- a/src/main/java/org/bukkit/block/EntityBlockStorage.java
|
||||
+++ b/src/main/java/org/bukkit/block/EntityBlockStorage.java
|
||||
@@ -47,6 +47,24 @@ public interface EntityBlockStorage<T extends Entity> extends TileState {
|
||||
@NotNull
|
||||
List<T> releaseEntities();
|
||||
|
||||
+ // Purpur start
|
||||
+ /**
|
||||
+ * Releases a stored entity, and returns the entity in the world.
|
||||
+ *
|
||||
+ * @param entity Entity to release
|
||||
+ * @return The entity which was released, or null if the stored entity is not in the hive
|
||||
+ */
|
||||
+ @org.jetbrains.annotations.Nullable
|
||||
+ T releaseEntity(@NotNull org.purpurmc.purpur.entity.StoredEntity<T> entity);
|
||||
+
|
||||
+ /**
|
||||
+ * Gets all the entities currently stored in the block.
|
||||
+ *
|
||||
+ * @return List of all entities which are stored in the block
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ List<org.purpurmc.purpur.entity.StoredEntity<T>> getEntities();
|
||||
+ //Purpur end
|
||||
/**
|
||||
* Add an entity to the block.
|
||||
*
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/entity/StoredEntity.java b/src/main/java/org/purpurmc/purpur/entity/StoredEntity.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..29540d55532197d2381a52ea9222b5785d224ef8
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/purpurmc/purpur/entity/StoredEntity.java
|
||||
@@ -0,0 +1,52 @@
|
||||
+package org.purpurmc.purpur.entity;
|
||||
+
|
||||
+import org.bukkit.Nameable;
|
||||
+import org.bukkit.block.EntityBlockStorage;
|
||||
+import org.bukkit.entity.Entity;
|
||||
+import org.bukkit.entity.EntityType;
|
||||
+import org.bukkit.persistence.PersistentDataHolder;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+
|
||||
+/**
|
||||
+ * Represents an entity stored in a block
|
||||
+ *
|
||||
+ * @see org.bukkit.block.EntityBlockStorage
|
||||
+ */
|
||||
+public interface StoredEntity<T extends Entity> extends PersistentDataHolder, Nameable {
|
||||
+ /**
|
||||
+ * Checks if this entity has been released yet
|
||||
+ *
|
||||
+ * @return if this entity has been released
|
||||
+ */
|
||||
+ boolean hasBeenReleased();
|
||||
+
|
||||
+ /**
|
||||
+ * Releases the entity from its stored block
|
||||
+ *
|
||||
+ * @return the released entity, or null if unsuccessful (including if this entity has already been released)
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ T release();
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the block in which this entity is stored
|
||||
+ *
|
||||
+ * @return the EntityBlockStorage in which this entity is stored, or null if it has been released
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ EntityBlockStorage<T> getBlockStorage();
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the entity type of this stored entity
|
||||
+ *
|
||||
+ * @return the type of entity this stored entity represents
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ EntityType getType();
|
||||
+
|
||||
+ /**
|
||||
+ * Writes data to the block entity snapshot. {@link EntityBlockStorage#update()} must be run in order to update the block in game.
|
||||
+ */
|
||||
+ void update();
|
||||
+}
|
||||
@@ -1,251 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: EOT3000 <egor.tolstenkov@outlook.com>
|
||||
Date: Sat, 10 Jun 2023 20:27:12 -0400
|
||||
Subject: [PATCH] Stored Bee API
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java b/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java
|
||||
index 7f0e37e23ff4c64355fdc822c0ac683959b8588a..fdebf45a27b903f4abb0bf55e1d79d78b7cc3d32 100644
|
||||
--- a/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java
|
||||
+++ b/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java
|
||||
@@ -147,11 +147,33 @@ public class BeehiveBlockEntity extends BlockEntity {
|
||||
return list;
|
||||
}
|
||||
|
||||
+ // Purpur start - Stored Bee API
|
||||
+ public List<Entity> releaseBee(BlockState iblockdata, BeehiveBlockEntity.BeeData data, BeehiveBlockEntity.BeeReleaseStatus tileentitybeehive_releasestatus, boolean force) {
|
||||
+ List<Entity> list = Lists.newArrayList();
|
||||
+
|
||||
+ BeehiveBlockEntity.releaseOccupant(this.level, this.worldPosition, iblockdata, data.occupant, list, tileentitybeehive_releasestatus, this.savedFlowerPos, force);
|
||||
+
|
||||
+ if (!list.isEmpty()) {
|
||||
+ stored.remove(data);
|
||||
+
|
||||
+ super.setChanged();
|
||||
+ }
|
||||
+
|
||||
+ return list;
|
||||
+ }
|
||||
+ // Purpur end - Stored Bee API
|
||||
+
|
||||
@VisibleForDebug
|
||||
public int getOccupantCount() {
|
||||
return this.stored.size();
|
||||
}
|
||||
|
||||
+ // Purpur start - Stored Bee API
|
||||
+ public List<BeeData> getStored() {
|
||||
+ return stored;
|
||||
+ }
|
||||
+ // Purpur end - Stored Bee API
|
||||
+
|
||||
// Paper start - Add EntityBlockStorage clearEntities
|
||||
public void clearBees() {
|
||||
this.stored.clear();
|
||||
@@ -467,9 +489,9 @@ public class BeehiveBlockEntity extends BlockEntity {
|
||||
}
|
||||
}
|
||||
|
||||
- private static class BeeData {
|
||||
+ public static class BeeData { // Purpur - change from private to public - Stored Bee API
|
||||
|
||||
- private final BeehiveBlockEntity.Occupant occupant;
|
||||
+ public final BeehiveBlockEntity.Occupant occupant; // Purpur - make public - Stored Bee API
|
||||
private int exitTickCounter; // Paper - Fix bees aging inside hives; separate counter for checking if bee should exit to reduce exit attempts
|
||||
private int ticksInHive;
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java
|
||||
index 1a2a05160ba51d9c75f1ae6ae61d944d81428722..a86b026f2f420637d125cf697bcd07bf314c98aa 100644
|
||||
--- a/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;
|
||||
|
||||
public class CraftBeehive extends CraftBlockEntityState<BeehiveBlockEntity> implements Beehive {
|
||||
|
||||
+ private final List<org.purpurmc.purpur.entity.StoredEntity<Bee>> storage = new ArrayList<>(); // Purpur - Stored Bee API
|
||||
+
|
||||
public CraftBeehive(World world, BeehiveBlockEntity tileEntity) {
|
||||
super(world, tileEntity);
|
||||
+ // Purpur start - load bees to be able to modify them individually - Stored Bee API
|
||||
+ for(BeehiveBlockEntity.BeeData data : tileEntity.getStored()) {
|
||||
+ storage.add(new org.purpurmc.purpur.entity.PurpurStoredBee(data, this));
|
||||
+ }
|
||||
+ // Purpur end - Stored Bee API
|
||||
}
|
||||
|
||||
protected CraftBeehive(CraftBeehive state, Location location) {
|
||||
@@ -76,14 +83,54 @@ public class CraftBeehive extends CraftBlockEntityState<BeehiveBlockEntity> impl
|
||||
}
|
||||
}
|
||||
|
||||
+ storage.clear(); // Purpur - Stored Bee API
|
||||
return bees;
|
||||
}
|
||||
|
||||
+ // Purpur start - Stored Bee API
|
||||
+ @Override
|
||||
+ public Bee releaseEntity(org.purpurmc.purpur.entity.StoredEntity<Bee> entity) {
|
||||
+ ensureNoWorldGeneration();
|
||||
+
|
||||
+ if(!getEntities().contains(entity)) {
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
+ if(isPlaced()) {
|
||||
+ BeehiveBlockEntity beehive = ((BeehiveBlockEntity) this.getTileEntityFromWorld());
|
||||
+ BeehiveBlockEntity.BeeData data = ((org.purpurmc.purpur.entity.PurpurStoredBee) entity).getHandle();
|
||||
+
|
||||
+ List<Entity> list = beehive.releaseBee(getHandle(), data, BeeReleaseStatus.BEE_RELEASED, true);
|
||||
+
|
||||
+ if (list.size() == 1) {
|
||||
+ storage.remove(entity);
|
||||
+
|
||||
+ return (Bee) list.get(0).getBukkitEntity();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public List<org.purpurmc.purpur.entity.StoredEntity<Bee>> getEntities() {
|
||||
+ return new ArrayList<>(storage);
|
||||
+ }
|
||||
+ // Purpur end - Stored Bee API
|
||||
+
|
||||
@Override
|
||||
public void addEntity(Bee entity) {
|
||||
Preconditions.checkArgument(entity != null, "Entity must not be null");
|
||||
|
||||
+ int length = this.getSnapshot().getStored().size(); // Purpur - Stored Bee API
|
||||
this.getSnapshot().addOccupant(((CraftBee) entity).getHandle());
|
||||
+
|
||||
+ // Purpur start - check if new bee was added, and if yes, add to stored bees - Stored Bee API
|
||||
+ List<BeehiveBlockEntity.BeeData> storedBeeData = this.getSnapshot().getStored();
|
||||
+ if(length < storedBeeData.size()) {
|
||||
+ storage.add(new org.purpurmc.purpur.entity.PurpurStoredBee(storedBeeData.getLast(), this));
|
||||
+ }
|
||||
+ // Purpur end - Stored Bee API
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,6 +147,7 @@ public class CraftBeehive extends CraftBlockEntityState<BeehiveBlockEntity> impl
|
||||
@Override
|
||||
public void clearEntities() {
|
||||
getSnapshot().clearBees();
|
||||
+ storage.clear(); // Purpur - Stored Bee API
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
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
|
||||
index 0000000000000000000000000000000000000000..7608bf0981fa0d37031e51e57e4086cb5ec4c88b
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/purpurmc/purpur/entity/PurpurStoredBee.java
|
||||
@@ -0,0 +1,106 @@
|
||||
+package org.purpurmc.purpur.entity;
|
||||
+
|
||||
+import io.papermc.paper.adventure.PaperAdventure;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import net.minecraft.nbt.CompoundTag;
|
||||
+import net.minecraft.nbt.Tag;
|
||||
+import net.minecraft.server.MinecraftServer;
|
||||
+import net.minecraft.world.item.component.CustomData;
|
||||
+import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
|
||||
+import org.bukkit.block.EntityBlockStorage;
|
||||
+import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
|
||||
+import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
|
||||
+import org.bukkit.entity.Bee;
|
||||
+import org.bukkit.entity.EntityType;
|
||||
+import org.bukkit.persistence.PersistentDataContainer;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+
|
||||
+import java.util.Locale;
|
||||
+
|
||||
+public class PurpurStoredBee implements StoredEntity<Bee> {
|
||||
+ private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
|
||||
+
|
||||
+ private final EntityBlockStorage<Bee> blockStorage;
|
||||
+ private final BeehiveBlockEntity.BeeData handle;
|
||||
+ private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(PurpurStoredBee.DATA_TYPE_REGISTRY);
|
||||
+
|
||||
+ private Component customName;
|
||||
+
|
||||
+ public PurpurStoredBee(BeehiveBlockEntity.BeeData data, EntityBlockStorage<Bee> blockStorage) {
|
||||
+ this.handle = data;
|
||||
+ this.blockStorage = blockStorage;
|
||||
+
|
||||
+ CompoundTag customData = handle.occupant.entityData().copyTag();
|
||||
+ this.customName = customData.contains("CustomName")
|
||||
+ ? PaperAdventure.asAdventure(net.minecraft.network.chat.Component.Serializer.fromJson(customData.getString("CustomName"), MinecraftServer.getDefaultRegistryAccess()))
|
||||
+ : null;
|
||||
+
|
||||
+ if(customData.contains("BukkitValues", Tag.TAG_COMPOUND)) {
|
||||
+ this.persistentDataContainer.putAll(customData.getCompound("BukkitValues"));
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public BeehiveBlockEntity.BeeData getHandle() {
|
||||
+ return handle;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @Nullable Component customName() {
|
||||
+ return customName;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void customName(@Nullable Component customName) {
|
||||
+ this.customName = customName;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @Nullable String getCustomName() {
|
||||
+ return PaperAdventure.asPlain(customName, Locale.US);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setCustomName(@Nullable String name) {
|
||||
+ customName(name != null ? Component.text(name) : null);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull PersistentDataContainer getPersistentDataContainer() {
|
||||
+ return persistentDataContainer;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean hasBeenReleased() {
|
||||
+ return !blockStorage.getEntities().contains(this);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @Nullable Bee release() {
|
||||
+ return blockStorage.releaseEntity(this);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @Nullable EntityBlockStorage<Bee> getBlockStorage() {
|
||||
+ if(hasBeenReleased()) {
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
+ return blockStorage;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull EntityType getType() {
|
||||
+ return EntityType.BEE;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void update() {
|
||||
+ handle.occupant.entityData().copyTag().put("BukkitValues", this.persistentDataContainer.toTagCompound());
|
||||
+ if(customName == null) {
|
||||
+ handle.occupant.entityData().copyTag().remove("CustomName");
|
||||
+ } else {
|
||||
+ handle.occupant.entityData().copyTag().putString("CustomName", net.minecraft.network.chat.Component.Serializer.toJson(PaperAdventure.asVanilla(customName), MinecraftServer.getDefaultRegistryAccess()));
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
@@ -0,0 +1,28 @@
|
||||
--- a/src/main/java/org/bukkit/block/EntityBlockStorage.java
|
||||
+++ b/src/main/java/org/bukkit/block/EntityBlockStorage.java
|
||||
@@ -47,6 +_,25 @@
|
||||
@NotNull
|
||||
List<T> releaseEntities();
|
||||
|
||||
+ // Purpur start - Stored Bee API
|
||||
+ /**
|
||||
+ * Releases a stored entity, and returns the entity in the world.
|
||||
+ *
|
||||
+ * @param entity Entity to release
|
||||
+ * @return The entity which was released, or null if the stored entity is not in the hive
|
||||
+ */
|
||||
+ @org.jetbrains.annotations.Nullable
|
||||
+ T releaseEntity(@NotNull org.purpurmc.purpur.entity.StoredEntity<T> entity);
|
||||
+
|
||||
+ /**
|
||||
+ * Gets all the entities currently stored in the block.
|
||||
+ *
|
||||
+ * @return List of all entities which are stored in the block
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ List<org.purpurmc.purpur.entity.StoredEntity<T>> getEntities();
|
||||
+ // Purpur end - Stored Bee API
|
||||
+
|
||||
/**
|
||||
* Add an entity to the block.
|
||||
*
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.purpurmc.purpur.entity;
|
||||
|
||||
import org.bukkit.Nameable;
|
||||
import org.bukkit.block.EntityBlockStorage;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.persistence.PersistentDataHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents an entity stored in a block
|
||||
*
|
||||
* @see org.bukkit.block.EntityBlockStorage
|
||||
*/
|
||||
public interface StoredEntity<T extends Entity> extends PersistentDataHolder, Nameable {
|
||||
/**
|
||||
* Checks if this entity has been released yet
|
||||
*
|
||||
* @return if this entity has been released
|
||||
*/
|
||||
boolean hasBeenReleased();
|
||||
|
||||
/**
|
||||
* Releases the entity from its stored block
|
||||
*
|
||||
* @return the released entity, or null if unsuccessful (including if this entity has already been released)
|
||||
*/
|
||||
@Nullable
|
||||
T release();
|
||||
|
||||
/**
|
||||
* Returns the block in which this entity is stored
|
||||
*
|
||||
* @return the EntityBlockStorage in which this entity is stored, or null if it has been released
|
||||
*/
|
||||
@Nullable
|
||||
EntityBlockStorage<T> getBlockStorage();
|
||||
|
||||
/**
|
||||
* Gets the entity type of this stored entity
|
||||
*
|
||||
* @return the type of entity this stored entity represents
|
||||
*/
|
||||
@NotNull
|
||||
EntityType getType();
|
||||
|
||||
/**
|
||||
* Writes data to the block entity snapshot. {@link EntityBlockStorage#update()} must be run in order to update the block in game.
|
||||
*/
|
||||
void update();
|
||||
}
|
||||
@@ -9,3 +9,48 @@
|
||||
private static final int MIN_TICKS_BEFORE_REENTERING_HIVE = 400;
|
||||
private static final int MIN_OCCUPATION_TICKS_NECTAR = 2400;
|
||||
public static final int MIN_OCCUPATION_TICKS_NECTARLESS = 600;
|
||||
@@ -154,11 +_,33 @@
|
||||
return list;
|
||||
}
|
||||
|
||||
+ // Purpur start - Stored Bee API
|
||||
+ public List<Entity> releaseBee(BlockState iblockdata, BeehiveBlockEntity.BeeData data, BeehiveBlockEntity.BeeReleaseStatus tileentitybeehive_releasestatus, boolean force) {
|
||||
+ List<Entity> list = Lists.newArrayList();
|
||||
+
|
||||
+ BeehiveBlockEntity.releaseOccupant(this.level, this.worldPosition, iblockdata, data.occupant, list, tileentitybeehive_releasestatus, this.savedFlowerPos, force);
|
||||
+
|
||||
+ if (!list.isEmpty()) {
|
||||
+ stored.remove(data);
|
||||
+
|
||||
+ super.setChanged();
|
||||
+ }
|
||||
+
|
||||
+ return list;
|
||||
+ }
|
||||
+ // Purpur end - Stored Bee API
|
||||
+
|
||||
@VisibleForDebug
|
||||
public int getOccupantCount() {
|
||||
return this.stored.size();
|
||||
}
|
||||
|
||||
+ // Purpur start - Stored Bee API
|
||||
+ public List<BeeData> getStored() {
|
||||
+ return stored;
|
||||
+ }
|
||||
+ // Purpur end - Stored Bee API
|
||||
+
|
||||
// Paper start - Add EntityBlockStorage clearEntities
|
||||
public void clearBees() {
|
||||
this.stored.clear();
|
||||
@@ -408,8 +_,8 @@
|
||||
return this.stored.stream().map(BeehiveBlockEntity.BeeData::toOccupant).toList();
|
||||
}
|
||||
|
||||
- static class BeeData {
|
||||
- private final BeehiveBlockEntity.Occupant occupant;
|
||||
+ public static class BeeData { // Purpur - make public - Stored Bee API
|
||||
+ public final BeehiveBlockEntity.Occupant occupant; // Purpur - make public - Stored Bee API
|
||||
private int exitTickCounter; // Paper - Fix bees aging inside hives; separate counter for checking if bee should exit to reduce exit attempts
|
||||
private int ticksInHive;
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java
|
||||
@@ -16,8 +_,15 @@
|
||||
|
||||
public class CraftBeehive extends CraftBlockEntityState<BeehiveBlockEntity> implements Beehive {
|
||||
|
||||
+ private final List<org.purpurmc.purpur.entity.StoredEntity<Bee>> storage = new ArrayList<>(); // Purpur - Stored Bee API
|
||||
+
|
||||
public CraftBeehive(World world, BeehiveBlockEntity tileEntity) {
|
||||
super(world, tileEntity);
|
||||
+ // Purpur start - load bees to be able to modify them individually - Stored Bee API
|
||||
+ for(BeehiveBlockEntity.BeeData data : tileEntity.getStored()) {
|
||||
+ storage.add(new org.purpurmc.purpur.entity.PurpurStoredBee(data, this));
|
||||
+ }
|
||||
+ // Purpur end - Stored Bee API
|
||||
}
|
||||
|
||||
protected CraftBeehive(CraftBeehive state, Location location) {
|
||||
@@ -76,14 +_,54 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ storage.clear(); // Purpur - Stored Bee API
|
||||
return bees;
|
||||
}
|
||||
|
||||
+ // Purpur start - Stored Bee API
|
||||
+ @Override
|
||||
+ public Bee releaseEntity(org.purpurmc.purpur.entity.StoredEntity<Bee> entity) {
|
||||
+ ensureNoWorldGeneration();
|
||||
+
|
||||
+ if(!getEntities().contains(entity)) {
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
+ if(isPlaced()) {
|
||||
+ BeehiveBlockEntity beehive = ((BeehiveBlockEntity) this.getTileEntityFromWorld());
|
||||
+ BeehiveBlockEntity.BeeData data = ((org.purpurmc.purpur.entity.PurpurStoredBee) entity).getHandle();
|
||||
+
|
||||
+ List<Entity> list = beehive.releaseBee(getHandle(), data, BeeReleaseStatus.BEE_RELEASED, true);
|
||||
+
|
||||
+ if (list.size() == 1) {
|
||||
+ storage.remove(entity);
|
||||
+
|
||||
+ return (Bee) list.get(0).getBukkitEntity();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public List<org.purpurmc.purpur.entity.StoredEntity<Bee>> getEntities() {
|
||||
+ return new ArrayList<>(storage);
|
||||
+ }
|
||||
+ // Purpur end - Stored Bee API
|
||||
+
|
||||
@Override
|
||||
public void addEntity(Bee entity) {
|
||||
Preconditions.checkArgument(entity != null, "Entity must not be null");
|
||||
|
||||
+ int length = this.getSnapshot().getStored().size(); // Purpur - Stored Bee API
|
||||
this.getSnapshot().addOccupant(((CraftBee) entity).getHandle());
|
||||
+
|
||||
+ // Purpur start - check if new bee was added, and if yes, add to stored bees - Stored Bee API
|
||||
+ List<BeehiveBlockEntity.BeeData> storedBeeData = this.getSnapshot().getStored();
|
||||
+ if(length < storedBeeData.size()) {
|
||||
+ storage.add(new org.purpurmc.purpur.entity.PurpurStoredBee(storedBeeData.getLast(), this));
|
||||
+ }
|
||||
+ // Purpur end - Stored Bee API
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,6 +_,7 @@
|
||||
@Override
|
||||
public void clearEntities() {
|
||||
getSnapshot().clearBees();
|
||||
+ storage.clear(); // Purpur - Stored Bee API
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package org.purpurmc.purpur.entity;
|
||||
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.item.component.CustomData;
|
||||
import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
|
||||
import org.bukkit.block.EntityBlockStorage;
|
||||
import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
|
||||
import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
|
||||
import org.bukkit.entity.Bee;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class PurpurStoredBee implements StoredEntity<Bee> {
|
||||
private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
|
||||
|
||||
private final EntityBlockStorage<Bee> blockStorage;
|
||||
private final BeehiveBlockEntity.BeeData handle;
|
||||
private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(PurpurStoredBee.DATA_TYPE_REGISTRY);
|
||||
|
||||
private Component customName;
|
||||
|
||||
public PurpurStoredBee(BeehiveBlockEntity.BeeData data, EntityBlockStorage<Bee> blockStorage) {
|
||||
this.handle = data;
|
||||
this.blockStorage = blockStorage;
|
||||
|
||||
CompoundTag customData = handle.occupant.entityData().copyTag();
|
||||
this.customName = customData.contains("CustomName")
|
||||
? PaperAdventure.asAdventure(net.minecraft.network.chat.Component.Serializer.fromJson(customData.getString("CustomName"), MinecraftServer.getDefaultRegistryAccess()))
|
||||
: null;
|
||||
|
||||
if(customData.contains("BukkitValues", Tag.TAG_COMPOUND)) {
|
||||
this.persistentDataContainer.putAll(customData.getCompound("BukkitValues"));
|
||||
}
|
||||
}
|
||||
|
||||
public BeehiveBlockEntity.BeeData getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Component customName() {
|
||||
return customName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customName(@Nullable Component customName) {
|
||||
this.customName = customName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getCustomName() {
|
||||
return PaperAdventure.asPlain(customName, Locale.US);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(@Nullable String name) {
|
||||
customName(name != null ? Component.text(name) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PersistentDataContainer getPersistentDataContainer() {
|
||||
return persistentDataContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBeenReleased() {
|
||||
return !blockStorage.getEntities().contains(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Bee release() {
|
||||
return blockStorage.releaseEntity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable EntityBlockStorage<Bee> getBlockStorage() {
|
||||
if(hasBeenReleased()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return blockStorage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull EntityType getType() {
|
||||
return EntityType.BEE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
handle.occupant.entityData().copyTag().put("BukkitValues", this.persistentDataContainer.toTagCompound());
|
||||
if(customName == null) {
|
||||
handle.occupant.entityData().copyTag().remove("CustomName");
|
||||
} else {
|
||||
handle.occupant.entityData().copyTag().putString("CustomName", net.minecraft.network.chat.Component.Serializer.toJson(PaperAdventure.asVanilla(customName), MinecraftServer.getDefaultRegistryAccess()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user