mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-23 08:46:44 +01:00
Implement API to get and set FireworkMeta on Firework entities
By: feildmaster <admin@feildmaster.com>
This commit is contained in:
parent
01e087c5d5
commit
d21d3199b9
1 changed files with 30 additions and 0 deletions
|
@ -1,15 +1,37 @@
|
|||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import net.minecraft.server.EntityFireworks;
|
||||
import net.minecraft.server.Item;
|
||||
import net.minecraft.server.ItemStack;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
|
||||
public class CraftFirework extends CraftEntity implements Firework {
|
||||
private static final int FIREWORK_ITEM_INDEX = 8;
|
||||
|
||||
private final CraftItemStack item;
|
||||
|
||||
public CraftFirework(CraftServer server, EntityFireworks entity) {
|
||||
super(server, entity);
|
||||
|
||||
ItemStack item = getHandle().getDataWatcher().f(FIREWORK_ITEM_INDEX);
|
||||
|
||||
if (item == null) {
|
||||
item = new ItemStack(Item.FIREWORKS);
|
||||
getHandle().getDataWatcher().watch(FIREWORK_ITEM_INDEX, item);
|
||||
}
|
||||
|
||||
this.item = CraftItemStack.asCraftMirror(item);
|
||||
|
||||
// Ensure the item is a firework...
|
||||
if (this.item.getType() != Material.FIREWORK) {
|
||||
this.item.setType(Material.FIREWORK);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,4 +47,12 @@ public class CraftFirework extends CraftEntity implements Firework {
|
|||
public EntityType getType() {
|
||||
return EntityType.FIREWORK;
|
||||
}
|
||||
|
||||
public FireworkMeta getFireworkMeta() {
|
||||
return (FireworkMeta) item.getItemMeta();
|
||||
}
|
||||
|
||||
public void setFireworkMeta(FireworkMeta meta) {
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue