diff --git a/src/main/java/io/github/cottonmc/templates/Templates.java b/src/main/java/io/github/cottonmc/templates/Templates.java index 1f5c85e..2aaf313 100644 --- a/src/main/java/io/github/cottonmc/templates/Templates.java +++ b/src/main/java/io/github/cottonmc/templates/Templates.java @@ -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 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 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 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); } } diff --git a/src/main/java/io/github/cottonmc/templates/TemplatesClient.java b/src/main/java/io/github/cottonmc/templates/TemplatesClient.java index 9ba9975..199dc28 100644 --- a/src/main/java/io/github/cottonmc/templates/TemplatesClient.java +++ b/src/main/java/io/github/cottonmc/templates/TemplatesClient.java @@ -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); } } diff --git a/src/main/java/io/github/cottonmc/templates/api/TemplateInteractionUtil.java b/src/main/java/io/github/cottonmc/templates/api/TemplateInteractionUtil.java index fd99c1e..0ac62c4 100644 --- a/src/main/java/io/github/cottonmc/templates/api/TemplateInteractionUtil.java +++ b/src/main/java/io/github/cottonmc/templates/api/TemplateInteractionUtil.java @@ -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; diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplateBlock.java index 2a33f15..73891b4 100644 --- a/src/main/java/io/github/cottonmc/templates/block/TemplateBlock.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateBlock.java @@ -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 builder) { diff --git a/src/main/java/io/github/cottonmc/templates/block/entity/TemplateEntity.java b/src/main/java/io/github/cottonmc/templates/block/TemplateEntity.java similarity index 98% rename from src/main/java/io/github/cottonmc/templates/block/entity/TemplateEntity.java rename to src/main/java/io/github/cottonmc/templates/block/TemplateEntity.java index 7e0ab78..50cb905 100644 --- a/src/main/java/io/github/cottonmc/templates/block/entity/TemplateEntity.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateEntity.java @@ -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; diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateSlabBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplateSlabBlock.java index dbb9d1e..ba42095 100644 --- a/src/main/java/io/github/cottonmc/templates/block/TemplateSlabBlock.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateSlabBlock.java @@ -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 diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateSlopeBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplateSlopeBlock.java index 5a9931d..bae06a3 100644 --- a/src/main/java/io/github/cottonmc/templates/block/TemplateSlopeBlock.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateSlopeBlock.java @@ -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) { diff --git a/src/main/resources/assets/templates/blockstates/cube.json b/src/main/resources/assets/templates/blockstates/cube.json new file mode 100644 index 0000000..d97fee7 --- /dev/null +++ b/src/main/resources/assets/templates/blockstates/cube.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "templates:cube_special" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/templates/lang/en_us.json b/src/main/resources/assets/templates/lang/en_us.json index ae32e51..8e22537 100644 --- a/src/main/resources/assets/templates/lang/en_us.json +++ b/src/main/resources/assets/templates/lang/en_us.json @@ -1,4 +1,7 @@ { + "itemGroup.templates.tab": "Templates", + + "block.templates.cube": "Cube Template", "block.templates.slope": "Slope Template", "block.templates.slab": "Slab Template" } \ No newline at end of file diff --git a/src/main/resources/data/templates/advancements/recipes/decorations/templates.json b/src/main/resources/data/templates/advancements/recipes/decorations/templates.json index 4d3ea97..f0e3ce0 100644 --- a/src/main/resources/data/templates/advancements/recipes/decorations/templates.json +++ b/src/main/resources/data/templates/advancements/recipes/decorations/templates.json @@ -2,8 +2,9 @@ "parent": "minecraft:recipes/root", "rewards": { "recipes": [ - "templates:slope", - "templates:slab" + "templates:cube", + "templates:slab", + "templates:slope" ] }, "criteria": { diff --git a/src/main/resources/data/templates/loot_tables/blocks/cube.json b/src/main/resources/data/templates/loot_tables/blocks/cube.json new file mode 100644 index 0000000..99deca6 --- /dev/null +++ b/src/main/resources/data/templates/loot_tables/blocks/cube.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "templates:cube" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/templates/recipes/cube.json b/src/main/resources/data/templates/recipes/cube.json new file mode 100644 index 0000000..f4ba3da --- /dev/null +++ b/src/main/resources/data/templates/recipes/cube.json @@ -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" +} \ No newline at end of file