com.yungnickyoung.minecraft.yungsapi.module.BlockModuleFabric Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of YungsApi-1.21-Fabric Show documentation
Show all versions of YungsApi-1.21-Fabric Show documentation
A common API for YUNG's Minecraft mods
The newest version!
package com.yungnickyoung.minecraft.yungsapi.module;
import com.yungnickyoung.minecraft.yungsapi.api.autoregister.AutoRegisterBlock;
import com.yungnickyoung.minecraft.yungsapi.autoregister.AutoRegistrationManager;
import com.yungnickyoung.minecraft.yungsapi.autoregister.AutoRegisterField;
import com.yungnickyoung.minecraft.yungsapi.mixin.accessor.StairBlockAccessor;
import net.minecraft.class_2248;
import net.minecraft.class_2349;
import net.minecraft.class_2354;
import net.minecraft.class_2378;
import net.minecraft.class_2482;
import net.minecraft.class_2544;
import net.minecraft.class_2960;
import net.minecraft.class_4970;
import net.minecraft.class_7923;
/**
* Registration of Blocks and BlockItems.
*/
public class BlockModuleFabric {
public static void processEntries() {
AutoRegistrationManager.BLOCKS.stream()
.filter(data -> !data.processed())
.forEach(BlockModuleFabric::register);
}
private static void register(AutoRegisterField data) {
AutoRegisterBlock autoRegisterBlock = (AutoRegisterBlock) data.object();
class_2248 block = autoRegisterBlock.get();
// Register block
class_2378.method_10230(class_7923.field_41175, data.name(), block);
// Register item if applicable
if (autoRegisterBlock.hasItemProperties()) {
ItemModuleFabric.registerBlockItem(data.name(), block, autoRegisterBlock.getItemProperties().get());
}
String namespace = data.name().method_12836();
String path = data.name().method_12832();
// Register associated Blocks & their BlockItems, if applicable
if (autoRegisterBlock.hasStairs()) {
class_2248 stairBlock = StairBlockAccessor.createStairBlock(block.method_9564(), class_4970.class_2251.method_55226(block));
class_2960 name = class_2960.method_60655(namespace, path + "_stairs");
class_2378.method_10230(class_7923.field_41175, name, stairBlock);
autoRegisterBlock.setStairs(stairBlock);
if (autoRegisterBlock.hasItemProperties()) {
ItemModuleFabric.registerBlockItem(name, stairBlock, autoRegisterBlock.getItemProperties().get());
}
}
if (autoRegisterBlock.hasSlab()) {
class_2248 slabBlock = new class_2482(class_4970.class_2251.method_55226(block));
class_2960 name = class_2960.method_60655(namespace, path + "_slab");
class_2378.method_10230(class_7923.field_41175, name, slabBlock);
autoRegisterBlock.setSlab(slabBlock);
if (autoRegisterBlock.hasItemProperties()) {
ItemModuleFabric.registerBlockItem(name, slabBlock, autoRegisterBlock.getItemProperties().get());
}
}
if (autoRegisterBlock.hasFence()) {
class_2248 fenceBlock = new class_2354(class_4970.class_2251.method_55226(block));
class_2960 name = class_2960.method_60655(namespace, path + "_fence");
class_2378.method_10230(class_7923.field_41175, name, fenceBlock);
autoRegisterBlock.setFence(fenceBlock);
if (autoRegisterBlock.hasItemProperties()) {
ItemModuleFabric.registerBlockItem(name, fenceBlock, autoRegisterBlock.getItemProperties().get());
}
}
if (autoRegisterBlock.hasFenceGate()) {
class_2248 fenceGateBlock = new class_2349(autoRegisterBlock.getFenceGateWoodType(), class_4970.class_2251.method_55226(block));
class_2960 name = class_2960.method_60655(namespace, path + "_fence_gate");
class_2378.method_10230(class_7923.field_41175, name, fenceGateBlock);
autoRegisterBlock.setFenceGate(fenceGateBlock);
if (autoRegisterBlock.hasItemProperties()) {
ItemModuleFabric.registerBlockItem(name, fenceGateBlock, autoRegisterBlock.getItemProperties().get());
}
}
if (autoRegisterBlock.hasWall()) {
class_2248 wallBlock = new class_2544(class_4970.class_2251.method_55226(block));
class_2960 name = class_2960.method_60655(namespace, path + "_wall");
class_2378.method_10230(class_7923.field_41175, name, wallBlock);
autoRegisterBlock.setWall(wallBlock);
if (autoRegisterBlock.hasItemProperties()) {
ItemModuleFabric.registerBlockItem(name, wallBlock, autoRegisterBlock.getItemProperties().get());
}
}
data.markProcessed();
}
}