Move class, rename blockentity, cube template

This commit is contained in:
quat1024 2023-07-05 23:57:19 -04:00
parent 084861080b
commit b2b18e294c
12 changed files with 94 additions and 28 deletions

View File

@ -1,18 +1,23 @@
package io.github.cottonmc.templates;
import io.github.cottonmc.templates.api.TemplateInteractionUtil;
import io.github.cottonmc.templates.block.TemplateBlock;
import io.github.cottonmc.templates.block.TemplateSlabBlock;
import io.github.cottonmc.templates.block.TemplateSlopeBlock;
import io.github.cottonmc.templates.block.entity.TemplateEntity;
import io.github.cottonmc.templates.block.TemplateEntity;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -22,16 +27,24 @@ import java.util.function.BiConsumer;
public class Templates implements ModInitializer {
public static final String MODID = "templates";
public static final Block CUBE = Registry.register(Registries.BLOCK, id("cube"), new TemplateBlock(TemplateInteractionUtil.makeSettings()));
public static final Block SLOPE = Registry.register(Registries.BLOCK, id("slope"), new TemplateSlopeBlock(TemplateInteractionUtil.makeSettings()));
public static final BlockEntityType<TemplateEntity> SLOPE_ENTITY = Registry.register(
public static final Block SLAB = Registry.register(Registries.BLOCK, id("slab"), new TemplateSlabBlock(TemplateInteractionUtil.makeSettings()));
//N.B. it's fine to make your own block entity type instead of gluing additional blocks to this one
public static final BlockEntityType<TemplateEntity> TEMPLATE_BLOCK_ENTITY = Registry.register(
Registries.BLOCK_ENTITY_TYPE, id("slope"),
FabricBlockEntityTypeBuilder.create(Templates::makeSlopeEntity, SLOPE).build(null)
FabricBlockEntityTypeBuilder.create(Templates::makeTemplateBlockEntity, CUBE, SLOPE, SLAB).build(null)
);
public static final Block SLAB = Registry.register(Registries.BLOCK, id("slab"), new TemplateSlabBlock(TemplateInteractionUtil.makeSettings()));
public static final BlockEntityType<TemplateEntity> SLAB_ENTITY = Registry.register(
Registries.BLOCK_ENTITY_TYPE, id("slab"),
FabricBlockEntityTypeBuilder.create(Templates::makeSlabEntity, SLAB).build(null)
@SuppressWarnings("unused")
public static final ItemGroup TAB = Registry.register(
Registries.ITEM_GROUP, id("tab"),
FabricItemGroup.builder()
.displayName(Text.translatable("itemGroup.templates.tab"))
.icon(() -> new ItemStack(SLOPE))
.entries(Templates::fillItemGroup)
.build()
);
//Overridden in TemplatesClient
@ -39,6 +52,7 @@ public class Templates implements ModInitializer {
@Override
public void onInitialize() {
Registry.register(Registries.ITEM, id("cube"), new BlockItem(CUBE, new Item.Settings()));
Registry.register(Registries.ITEM, id("slope"), new BlockItem(SLOPE, new Item.Settings()));
Registry.register(Registries.ITEM, id("slab"), new BlockItem(SLAB, new Item.Settings()));
}
@ -47,12 +61,14 @@ public class Templates implements ModInitializer {
return new Identifier(MODID, path);
}
//simply for breaking circular references in the registration calls
private static TemplateEntity makeSlopeEntity(BlockPos pos, BlockState state) {
return new TemplateEntity(SLOPE_ENTITY, pos, state);
//simply for breaking circular reference in the registration call
private static TemplateEntity makeTemplateBlockEntity(BlockPos pos, BlockState state) {
return new TemplateEntity(TEMPLATE_BLOCK_ENTITY, pos, state);
}
private static TemplateEntity makeSlabEntity(BlockPos pos, BlockState state) {
return new TemplateEntity(SLAB_ENTITY, pos, state);
private static void fillItemGroup(ItemGroup.DisplayContext ctx, ItemGroup.Entries ent) {
ent.add(CUBE);
ent.add(SLOPE);
ent.add(SLAB);
}
}

View File

@ -54,14 +54,15 @@ public class TemplatesClient implements ClientModInitializer {
ModelLoadingRegistry.INSTANCE.registerResourceProvider(rm -> provider); //block models
ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> provider); //item models
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), Templates.SLOPE, Templates.SLAB);
provider.addTemplateModel(Templates.id("slope_special"), new RetexturedMeshUnbakedModel(Templates.id("block/slope_base"), SlopeBaseMesh::make));
provider.assignItemModel(Templates.id("slope_special"), Templates.SLOPE);
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), Templates.CUBE, Templates.SLOPE, Templates.SLAB);
provider.addTemplateModel(Templates.id("cube_special"), new RetexturedJsonModelUnbakedModel(Templates.id("block/cube")));
provider.addTemplateModel(Templates.id("slab_bottom_special"), new RetexturedJsonModelUnbakedModel(Templates.id("block/slab_bottom")));
provider.addTemplateModel(Templates.id("slab_top_special"), new RetexturedJsonModelUnbakedModel(Templates.id("block/slab_top")));
provider.addTemplateModel(Templates.id("slope_special"), new RetexturedMeshUnbakedModel(Templates.id("block/slope_base"), SlopeBaseMesh::make));
provider.assignItemModel(Templates.id("cube_special"), Templates.CUBE);
provider.assignItemModel(Templates.id("slope_special"), Templates.SLOPE);
provider.assignItemModel(Templates.id("slab_bottom_special"), Templates.SLAB);
}
}

View File

@ -1,6 +1,6 @@
package io.github.cottonmc.templates.api;
import io.github.cottonmc.templates.block.entity.TemplateEntity;
import io.github.cottonmc.templates.block.TemplateEntity;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;

View File

@ -1,6 +1,7 @@
package io.github.cottonmc.templates.block;
import com.google.common.base.MoreObjects;
import io.github.cottonmc.templates.Templates;
import io.github.cottonmc.templates.api.TemplateInteractionUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
@ -21,14 +22,16 @@ import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
public abstract class TemplateBlock extends Block implements BlockEntityProvider {
public class TemplateBlock extends Block implements BlockEntityProvider {
public TemplateBlock(Settings settings) {
super(settings);
setDefaultState(TemplateInteractionUtil.setDefaultStates(getDefaultState()));
}
@Override
public abstract @Nullable BlockEntity createBlockEntity(BlockPos blockPos, BlockState blockState);
public @Nullable BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return Templates.TEMPLATE_BLOCK_ENTITY.instantiate(pos, state);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {

View File

@ -1,4 +1,4 @@
package io.github.cottonmc.templates.block.entity;
package io.github.cottonmc.templates.block;
import io.github.cottonmc.templates.Templates;
import io.github.cottonmc.templates.api.ThemeableBlockEntity;

View File

@ -32,7 +32,7 @@ public class TemplateSlabBlock extends SlabBlock implements BlockEntityProvider
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return Templates.SLAB_ENTITY.instantiate(pos, state);
return Templates.TEMPLATE_BLOCK_ENTITY.instantiate(pos, state);
}
@Override

View File

@ -48,11 +48,6 @@ public class TemplateSlopeBlock extends TemplateBlock {
super.appendProperties(builder.add(FACING, HALF));
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return Templates.SLOPE_ENTITY.instantiate(pos, state);
}
@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {

View File

@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "templates:cube_special"
}
}
}

View File

@ -1,4 +1,7 @@
{
"itemGroup.templates.tab": "Templates",
"block.templates.cube": "Cube Template",
"block.templates.slope": "Slope Template",
"block.templates.slab": "Slab Template"
}

View File

@ -2,8 +2,9 @@
"parent": "minecraft:recipes/root",
"rewards": {
"recipes": [
"templates:slope",
"templates:slab"
"templates:cube",
"templates:slab",
"templates:slope"
]
},
"criteria": {

View File

@ -0,0 +1,19 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "templates:cube"
}
],
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
]
}
]
}

View File

@ -0,0 +1,21 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"III",
"I~I",
"III"
],
"key": {
"I": {
"item": "minecraft:bamboo"
},
"~": {
"item": "minecraft:string"
}
},
"result": {
"item": "templates:cube",
"count": 4
},
"group": "templates"
}