Skip to main content

Minecraft Objects

Here some utility classes to handle Minecraft server and Craftbukkit objects using simple methods.

Item Object

The ItemObject is an utility class that allow to handle Bukkit and Minecraft items with simple methods across supported versions.

Create

Create Minecraft ItemStack using CompoundTag, so it allow to get from different formats.

// Create from compound
Object compound = ...;
Object item = ItemObject.newItem(compound);

// Create from SNBT (or json)
String snbt = "{id:\"minecraft:diamond_sword\"}";
Object item = ItemObject.newItem(TagCompound.newTag(snbt));

Convert

Convert items from Bukkit and Minecraft.

ItemStack item = ...;

// Convert to Minecraft ItemStack
Object mcItem = ItemObject.asNMSCopy(item);

// Convert to Bukkit ItemStack
ItemStack sameItem = ItemObject.asBukkitCopy(mcItem);

Edit

Edit various things of Bukkit and Minecraft ItemStack.

Object item = ItemObject.newItem(TagCompound.newTag("{id:\"minecraft:diamond_sword\"}"));

// Save into CompoundTag
Object compound = ItemObject.save(item);

// Get item tag as CompoundTag
Object tag = ItemObject.getCustomDataTag(item);
// Set item tag
ItemObject.setCustomDataTag(item, tag);


// Normal ItemStack or CraftItemStack
ItemStack item = ...;

// Get handle from CraftItemStack or convert Bukkit ItemStack to Minecraft ItemStack
Object mcItem = ItemObject.getHandle(item);
// Override handle of CraftItemStack or load Minecraft ItemStack into Bukkit ItemStack
ItemObject.setHandle(item, mcItem);

Entity Object

The EntityObject is an utility class that allow to handle Bukkit and Minecraft entities with simple methods across supported versions.

Convert

Convert entities from Bukkit and Minecraft.

Entity entity = ...;

// Convert to Minecraft Entity
Object mcEntity = EntityObject.getHandle(entity);

// Convert to Bukkit Entity
Entity sameEntity = EntityObject.getEntity(mcEntity);

Edit

Edit various things of Minecraft Entity.

Object entity = ...;

// Save into CompoundTag
Object compound = EntityObject.save(entity);
// Load CompoundTag into entity
EntityObject.load(entity, compound);

Block Object

The BlockObject is an utility class that allow to handle Bukkit and Minecraft blocks and tile entities with simple methods across supported versions.

Convert

Convert Bukkit Block into Minecraft BlockEntity (if it's aplicable).

Block block = ...;

// Convert to Minecraft BlockEntity
Object blockEntity = BlockObject.getTileEntity(block);

Edit

Edit various things of Minecraft BlockEntity.

Object tileEntity = ...;

// Save into CompoundTag
Object compound = BlockObject.save(tileEntity);
// Load CompoundTag into tileEntity
BlockObject.load(tileEntity, compound);