Skip to content

Commit

Permalink
Add beecount to item meta
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Nov 10, 2024
1 parent 0fffa8b commit de5e661
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
public interface MCBeehive extends MCBlockState {
MCLocation getFlowerLocation();
void setFlowerLocation(MCLocation loc);
void addBees(int count);
int getEntityCount();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import com.laytonsmith.abstraction.MCLocation;
import com.laytonsmith.abstraction.blocks.MCBeehive;
import com.laytonsmith.abstraction.bukkit.BukkitMCLocation;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Beehive;
import org.bukkit.entity.Bee;
import org.bukkit.entity.EntitySnapshot;

public class BukkitMCBeehive extends BukkitMCBlockState implements MCBeehive {

Expand Down Expand Up @@ -37,4 +41,28 @@ public void setFlowerLocation(MCLocation loc) {
bh.setFlower((Location) loc.getHandle());
}
}

@Override
public void addBees(int count) {
try {
EntitySnapshot beeSnapshot = Bukkit.getEntityFactory().createEntitySnapshot("{id:\"minecraft:bee\"}");
World world;
if(bh.isPlaced()) {
world = bh.getWorld();
} else {
// use dummy world
world = Bukkit.getWorlds().get(0);
}
for(int i = 0; i < count; i++) {
bh.addEntity((Bee) beeSnapshot.createEntity(world));
}
} catch(Exception ignore) {
// probably before 1.20.6
}
}

@Override
public int getEntityCount() {
return bh.getEntityCount();
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/laytonsmith/core/ObjectGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.laytonsmith.abstraction.MCTropicalFishBucketMeta;
import com.laytonsmith.abstraction.MCWorld;
import com.laytonsmith.abstraction.StaticLayer;
import com.laytonsmith.abstraction.blocks.MCBeehive;
import com.laytonsmith.abstraction.blocks.MCBlockData;
import com.laytonsmith.abstraction.blocks.MCBlockState;
import com.laytonsmith.abstraction.blocks.MCCommandBlock;
Expand Down Expand Up @@ -619,6 +620,8 @@ public Construct itemMeta(MCItemStack is, Target t) {
} else if(bs instanceof MCCommandBlock cmdBlock) {
ma.set("command", cmdBlock.getCommand());
ma.set("customname", cmdBlock.getName());
} else if(bs instanceof MCBeehive beehive) {
ma.set("beecount", new CInt(beehive.getEntityCount(), t), t);
}
} else if(meta instanceof MCArmorMeta armorMeta) { // Must be before MCLeatherArmorMeta
if(armorMeta.hasTrim()) {
Expand Down Expand Up @@ -1182,6 +1185,13 @@ public MCItemMeta itemMeta(Mixed c, MCMaterial mat, Target t) throws ConfigRunti
cmdBlock.setName(ma.get("customname", t).val());
}
bsm.setBlockState(bs);
} else if(bs instanceof MCBeehive beehive
&& Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_20_6)) {
if(ma.containsKey("beecount")) {
int beeCount = ArgumentValidation.getInt32(ma.get("beecount", t), t);
beehive.addBees(beeCount);
}
bsm.setBlockState(bs);
}
} else if(meta instanceof MCArmorMeta armorMeta) { // Must be before MCLeatherArmorMeta
if(ma.containsKey("trim")) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/functionDocs/get_itemmeta
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ The entity's custom name is derived from the item '''"display"''' string. All ot
|
* '''patterns''' : (array) An array of pattern arrays. Each can contain the keys '''"color"''' (one of ''%DYE_COLORS%'') and '''"shape"''' (one of ''%PATTERN_SHAPES%'').
|-
| Bee Hives/Nests
|
* '''beecount''' : (int) The number of bees stored in this hive or nest (0 - 3). (requires MC 1.20.6+ to set)
Stored Bee NBT is not yet supported.
|-
| BlockData
|
* '''blockdata''' : (array) An array of blockdata (known as block states in vanilla) like is returned from get_blockdata(), or null if none.
Expand Down

0 comments on commit de5e661

Please sign in to comment.