abstracted away block registering

This commit is contained in:
Dani The Skunk 2022-10-22 04:47:09 +00:00
parent 7bb294a0d7
commit 30610e36b1
3 changed files with 74 additions and 22 deletions

View File

@ -0,0 +1,34 @@
package com.danitheskunk.skunkstuff;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.material.Material;
import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings;
public class BlockBuilder extends QuiltBlockSettings {
public String name;
public CreativeModeTab creativeModeTab = CreativeModeTab.TAB_MISC;
public Block block;
public BlockBuilder() {
super(QuiltBlockSettings.of(Material.WOOD));
strength(2);
opaque(false);
}
public BlockBuilder name(String name) {
this.name = name;
return this;
}
public BlockBuilder creativeModeTab(CreativeModeTab creativeModeTab) {
this.creativeModeTab = creativeModeTab;
return this;
}
public Block build() {
block = new Block(this);
Blocks.addToDeffered(this);
return block;
}
}

View File

@ -1,5 +1,41 @@
package com.danitheskunk.skunkstuff; package com.danitheskunk.skunkstuff;
public class Blocks { import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import org.quiltmc.qsl.item.setting.api.QuiltItemSettings;
import java.util.ArrayList;
import java.util.List;
public class Blocks {
private static final List<BlockBuilder> deferred = new ArrayList<>();
private static final String namespace = "skunkstuff";
public static BlockBuilder register() {
return new BlockBuilder();
}
public static void addToDeffered(BlockBuilder builder) {
deferred.add(builder);
}
public static void registerAll() {
for(var block : deferred) {
Registry.register(
Registry.BLOCK,
new ResourceLocation(namespace, block.name),
block.block
);
Registry.register(
Registry.ITEM,
new ResourceLocation(namespace, block.name),
new BlockItem(
block.block,
new QuiltItemSettings().group(block.creativeModeTab)
)
);
}
}
} }

View File

@ -1,37 +1,19 @@
package com.danitheskunk.skunkstuff; package com.danitheskunk.skunkstuff;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.material.Material;
import org.quiltmc.loader.api.ModContainer; import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings;
import org.quiltmc.qsl.item.setting.api.QuiltItemSettings;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class SkunkStuff implements ModInitializer { public class SkunkStuff implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("SkunkStuff"); public static final Logger LOGGER = LoggerFactory.getLogger("SkunkStuff");
public static final Block GOBAN_BLOCK = new Block(QuiltBlockSettings.of( public static final Block GOBAN_BLOCK =
Material.WOOD).strength(2).opaque(false)); Blocks.register().name("goban").build();
@Override @Override
public void onInitialize(ModContainer mod) { public void onInitialize(ModContainer mod) {
Registry.register(Registry.BLOCK, Blocks.registerAll();
new ResourceLocation("skunkstuff", "goban"),
GOBAN_BLOCK
);
Registry.register(
Registry.ITEM,
new ResourceLocation("skunkstuff", "goban"),
new BlockItem(GOBAN_BLOCK,
new QuiltItemSettings().group(CreativeModeTab.TAB_MISC)
)
);
LOGGER.info("Hello Quilt world from {}!", mod.metadata().name());
} }
} }