Skip to content

For developers

PetteriM1 edited this page Sep 16, 2024 · 14 revisions

Javadocs

https://suomicraftpe.ddns.net/javadocs/nukkit-pm1e/

Maven dependency

<dependency>
    <groupId>cn.nukkit</groupId>
    <artifactId>Nukkit</artifactId>
    <version>PM1E</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/patched.jar</systemPath>
</dependency>

Gradle dependency

dependencies {
    implementation(files("lib/patched.jar"))
}

(Put patched.jar from server-dir/.cache into a folder called lib in your project folder)

Bedrock protocol

https://github.com/CloudburstMC/protocol-docs

https://wiki.vg/Bedrock_Protocol

How to register blocks, items and entities

Register a vanilla block

void registerBlock(int blockId, Class<? extends Block> blockClass) {
        Block.list[blockId] = blockClass;
        Block block;
        try {
            block = blockClass.newInstance();
            try {
                Constructor<?> constructor = blockClass.getDeclaredConstructor(int.class);
                constructor.setAccessible(true);
                for (int data = 0; data < (1 << Block.DATA_BITS); ++data) {
                    int fullId = (blockId << Block.DATA_BITS) | data;
                    Block.fullList[fullId] = (Block) constructor.newInstance(data);
                }
                Block.hasMeta[blockId] = true;
            } catch (NoSuchMethodException ignore) {
                for (int data = 0; data < Block.DATA_SIZE; ++data) {
                    int fullId = (blockId << Block.DATA_BITS) | data;
                    Block.fullList[fullId] = block;
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        Block.solid[blockId] = block.isSolid();
        Block.transparent[blockId] = block.isTransparent();
        Block.hardness[blockId] = block.getHardness();
        Block.light[blockId] = block.getLightLevel();
        if (block.isSolid()) {
            if (block.isTransparent()) {
                if (block instanceof BlockLiquid || block instanceof BlockIce) {
                    Block.lightFilter[blockId] = 2;
                } else {
                    Block.lightFilter[blockId] = 1;
                }
            } else {
                Block.lightFilter[blockId] = 15;
            }
        } else {
            Block.lightFilter[blockId] = 1;
        }
    }

Register a custom block

See https://github.com/PetteriM1/CustomBlockExample

Register a vanilla entity

Entity.registerEntity(String saveId, Class<? extends Entity> entityClass)

Register a custom entity

See https://github.com/PetteriM1/CustomEntityExample

Register a block entity

BlockEntity.registerBlockEntity(String saveId, Class<? extends BlockEntity> blockEntityClass)

Register a vanilla item

Item.list[id] = YourItem.class

Register a custom item

See https://github.com/PetteriM1/CustomItemExample

Register an enchantment

Enchantment.enchantments[id] = YourEnchantment.class

How to create a scoreboard

See https://github.com/CloudburstMC/Nukkit/pull/2181 and https://github.com/PetteriM1/SimpleScoreboards

How to create a crafting recipe

// Recipe can be a ShapedRecipe, ShapelessRecipe, FurnaceRecipe, etc. 
server.getCraftingManager().registerRecipe(recipe)
// Update cached recipe packet after registering your recipes
server.getCraftingManager().rebuildPacket()