This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
ScriptCraft/scriptcraft/src/main/java/com/thebrokenrail/scriptcraft/api/bridge/RegistryBridges.java

48 lines
2.6 KiB
Java

package com.thebrokenrail.scriptcraft.api.bridge;
import com.thebrokenrail.scriptcraft.api.block.CustomBlock;
import com.thebrokenrail.scriptcraft.api.block.CustomBlockEntity;
import com.thebrokenrail.scriptcraft.api.block.CustomBlockWithEntity;
import com.thebrokenrail.scriptcraft.api.item.CustomItem;
import com.thebrokenrail.scriptcraft.core.ScriptCraftCore;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
class RegistryBridges {
static void register() {
ScriptCraftCore.addBridge("Registry.registerBlock", args -> {
CustomBlock.BlockStatePropertyBuilder builder = (CustomBlock.BlockStatePropertyBuilder) args[2];
Registry.register(Registry.BLOCK, new Identifier((String) args[0]), new CustomBlock((Block.Settings) args[1], new Identifier((String) args[0])) {
@Override
protected BlockStatePropertyBuilder getPropertyBuilder() {
return builder;
}
});
return null;
});
ScriptCraftCore.addBridge("Registry.registerBlockWithEntity", args -> {
CustomBlock.BlockStatePropertyBuilder builder = (CustomBlock.BlockStatePropertyBuilder) args[2];
Registry.register(Registry.BLOCK, new Identifier((String) args[0]), new CustomBlockWithEntity((Block.Settings) args[1], new Identifier((String) args[0])) {
@Override
protected BlockStatePropertyBuilder getPropertyBuilder() {
return builder;
}
});
Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier((String) args[0]), BlockEntityType.Builder.create(() -> new CustomBlockEntity(Registry.BLOCK_ENTITY_TYPE.get(new Identifier((String) args[0])), new Identifier((String) args[0])), Registry.BLOCK.get(new Identifier((String) args[0]))).build(null));
return null;
});
ScriptCraftCore.addBridge("Registry.registerItem", args -> {
Registry.register(Registry.ITEM, new Identifier((String) args[0]), new CustomItem((Item.Settings) args[1], new Identifier((String) args[0])));
return null;
});
ScriptCraftCore.addBridge("Registry.registerBlockItem", args -> {
Registry.register(Registry.ITEM, new Identifier((String) args[0]), new BlockItem(Registry.BLOCK.get(new Identifier((String) args[2])), (Item.Settings) args[1]));
return null;
});
}
}