Skip to content

Commit de5e661

Browse files
committed
Add beecount to item meta
1 parent 0fffa8b commit de5e661

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

src/main/java/com/laytonsmith/abstraction/blocks/MCBeehive.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
public interface MCBeehive extends MCBlockState {
66
MCLocation getFlowerLocation();
77
void setFlowerLocation(MCLocation loc);
8+
void addBees(int count);
9+
int getEntityCount();
810
}

src/main/java/com/laytonsmith/abstraction/bukkit/blocks/BukkitMCBeehive.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
import com.laytonsmith.abstraction.MCLocation;
44
import com.laytonsmith.abstraction.blocks.MCBeehive;
55
import com.laytonsmith.abstraction.bukkit.BukkitMCLocation;
6+
import org.bukkit.Bukkit;
67
import org.bukkit.Location;
8+
import org.bukkit.World;
79
import org.bukkit.block.Beehive;
10+
import org.bukkit.entity.Bee;
11+
import org.bukkit.entity.EntitySnapshot;
812

913
public class BukkitMCBeehive extends BukkitMCBlockState implements MCBeehive {
1014

@@ -37,4 +41,28 @@ public void setFlowerLocation(MCLocation loc) {
3741
bh.setFlower((Location) loc.getHandle());
3842
}
3943
}
44+
45+
@Override
46+
public void addBees(int count) {
47+
try {
48+
EntitySnapshot beeSnapshot = Bukkit.getEntityFactory().createEntitySnapshot("{id:\"minecraft:bee\"}");
49+
World world;
50+
if(bh.isPlaced()) {
51+
world = bh.getWorld();
52+
} else {
53+
// use dummy world
54+
world = Bukkit.getWorlds().get(0);
55+
}
56+
for(int i = 0; i < count; i++) {
57+
bh.addEntity((Bee) beeSnapshot.createEntity(world));
58+
}
59+
} catch(Exception ignore) {
60+
// probably before 1.20.6
61+
}
62+
}
63+
64+
@Override
65+
public int getEntityCount() {
66+
return bh.getEntityCount();
67+
}
4068
}

src/main/java/com/laytonsmith/core/ObjectGenerator.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.laytonsmith.abstraction.MCTropicalFishBucketMeta;
5353
import com.laytonsmith.abstraction.MCWorld;
5454
import com.laytonsmith.abstraction.StaticLayer;
55+
import com.laytonsmith.abstraction.blocks.MCBeehive;
5556
import com.laytonsmith.abstraction.blocks.MCBlockData;
5657
import com.laytonsmith.abstraction.blocks.MCBlockState;
5758
import com.laytonsmith.abstraction.blocks.MCCommandBlock;
@@ -619,6 +620,8 @@ public Construct itemMeta(MCItemStack is, Target t) {
619620
} else if(bs instanceof MCCommandBlock cmdBlock) {
620621
ma.set("command", cmdBlock.getCommand());
621622
ma.set("customname", cmdBlock.getName());
623+
} else if(bs instanceof MCBeehive beehive) {
624+
ma.set("beecount", new CInt(beehive.getEntityCount(), t), t);
622625
}
623626
} else if(meta instanceof MCArmorMeta armorMeta) { // Must be before MCLeatherArmorMeta
624627
if(armorMeta.hasTrim()) {
@@ -1182,6 +1185,13 @@ public MCItemMeta itemMeta(Mixed c, MCMaterial mat, Target t) throws ConfigRunti
11821185
cmdBlock.setName(ma.get("customname", t).val());
11831186
}
11841187
bsm.setBlockState(bs);
1188+
} else if(bs instanceof MCBeehive beehive
1189+
&& Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_20_6)) {
1190+
if(ma.containsKey("beecount")) {
1191+
int beeCount = ArgumentValidation.getInt32(ma.get("beecount", t), t);
1192+
beehive.addBees(beeCount);
1193+
}
1194+
bsm.setBlockState(bs);
11851195
}
11861196
} else if(meta instanceof MCArmorMeta armorMeta) { // Must be before MCLeatherArmorMeta
11871197
if(ma.containsKey("trim")) {

src/main/resources/functionDocs/get_itemmeta

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ The entity's custom name is derived from the item '''"display"''' string. All ot
3838
|
3939
* '''patterns''' : (array) An array of pattern arrays. Each can contain the keys '''"color"''' (one of ''%DYE_COLORS%'') and '''"shape"''' (one of ''%PATTERN_SHAPES%'').
4040
|-
41+
| Bee Hives/Nests
42+
|
43+
* '''beecount''' : (int) The number of bees stored in this hive or nest (0 - 3). (requires MC 1.20.6+ to set)
44+
Stored Bee NBT is not yet supported.
45+
|-
4146
| BlockData
4247
|
4348
* '''blockdata''' : (array) An array of blockdata (known as block states in vanilla) like is returned from get_blockdata(), or null if none.

0 commit comments

Comments
 (0)