Basic Operations

Adapt Bukkit Location

Pos3 pos3 = Pos3.from(location);

Get CustomCrops world

BukkitCustomCropsPlugin.getInstance().getWorldManager().getWorld(Bukkit.getWorld("world"));

Get/Remove Blockstate

CustomCropsWorld<?> world = ...;
world.getBlockState(pos3);
world.removeBlockState(pos3);

Add Blockstate

CropBlock cropBlock = (CropBlock) BuiltInBlockMechanics.CROP.mechanic();
CustomCropsBlockState blockState = cropBlock.createBlockState();
cropBlock.id(blockState, "tomato");
cropBlock.point(blockState, 0);
world.addBlockState(pos3, blockState);

Set/Remove/Get Custom Data in Blockstate

SynchronizedCompoundMap compoundMap = blockState.compoundMap();
compoundMap.remove("key");
compoundMap.put("key", new StringTag("key", "test"));
compoundMap.get("key");

Get the block type from blockstate

CustomCropsBlock block = blockState.type();
if (block instanceof CropBlock cropBlock) {
    CropConfig cropConfig = cropBlock.config(blockState);
}

Get built-in block/item type from Registry

PotBlock potBlock = (PotBlock) BuiltInBlockMechanics.POT.mechanic();

SeedItem seedItem = (SeedItem) BuiltInItemMechanics.SEED.mechanic();

Place/Remove blocks on Bukkit Worlds

ItemManager itemManager = BukkitCustomCropsPlugin.getInstance().getItemManager();
itemManager.placeFurniture(location, "id", FurnitureRotation.NONE);
itemManager.placeBlock(location, "id");
itemManager.removeFurniture(location);
itemManager.removeBlock(location);

Get ids

ItemManager itemManager = BukkitCustomCropsPlugin.getInstance().getItemManager();
String blockID = itemManager.blockID(block);
String furnitureID = itemManager.furnitureID(entity);
String itemID = itemManager.id(itemStack);

Get configs of the built-in items

CropConfig cropConfig = Registries.CROP.get("tomato");
SprinklerConfig sprinklerConfig = Registries.SPRINKLER.get("sprinkler");
PotConfig potConfig = Registries.POT.get("default");
WateringCanConfig wateringCanConfig = Registries.WATERING_CAN.get("watering_can_1");
FertilizerConfig fertilizerConfig = Registries.FERTILIZER.get("quality_1");

Last updated