From ea476662d41e8ad077daeec5ac6f01cf0540a373 Mon Sep 17 00:00:00 2001 From: quat1024 Date: Thu, 6 Jul 2023 01:44:00 -0400 Subject: [PATCH] We have quark posts at home --- .../github/cottonmc/templates/Templates.java | 7 ++- .../cottonmc/templates/TemplatesClient.java | 10 +++- .../templates/block/TemplatePostBlock.java | 57 +++++++++++++++++++ .../assets/templates/blockstates/post.json | 19 +++++++ .../assets/templates/lang/en_us.json | 1 + .../recipes/decorations/templates.json | 1 + .../templates/loot_tables/blocks/post.json | 19 +++++++ .../data/templates/recipes/post.json | 21 +++++++ 8 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 src/main/java/io/github/cottonmc/templates/block/TemplatePostBlock.java create mode 100644 src/main/resources/assets/templates/blockstates/post.json create mode 100644 src/main/resources/data/templates/loot_tables/blocks/post.json create mode 100644 src/main/resources/data/templates/recipes/post.json diff --git a/src/main/java/io/github/cottonmc/templates/Templates.java b/src/main/java/io/github/cottonmc/templates/Templates.java index 8ee81a3..ba040b1 100644 --- a/src/main/java/io/github/cottonmc/templates/Templates.java +++ b/src/main/java/io/github/cottonmc/templates/Templates.java @@ -3,10 +3,12 @@ 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.TemplateFenceBlock; +import io.github.cottonmc.templates.block.TemplatePostBlock; import io.github.cottonmc.templates.block.TemplateSlabBlock; import io.github.cottonmc.templates.block.TemplateSlopeBlock; import io.github.cottonmc.templates.block.TemplateEntity; import io.github.cottonmc.templates.block.TemplateWallBlock; +import io.github.cottonmc.templates.block.WaterloggableTemplateBlock; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; @@ -31,6 +33,7 @@ public class Templates implements ModInitializer { public static final Block CUBE = Registry.register(Registries.BLOCK, id("cube"), new TemplateBlock(TemplateInteractionUtil.makeSettings())); public static final Block FENCE = Registry.register(Registries.BLOCK, id("fence"), new TemplateFenceBlock(TemplateInteractionUtil.makeSettings())); + public static final Block POST = Registry.register(Registries.BLOCK, id("post"), new TemplatePostBlock(TemplateInteractionUtil.makeSettings())); public static final Block SLAB = Registry.register(Registries.BLOCK, id("slab"), new TemplateSlabBlock(TemplateInteractionUtil.makeSettings())); public static final Block SLOPE = Registry.register(Registries.BLOCK, id("slope"), new TemplateSlopeBlock(TemplateInteractionUtil.makeSettings())); public static final Block WALL = Registry.register(Registries.BLOCK, id("wall"), new TemplateWallBlock(TemplateInteractionUtil.makeSettings())); @@ -38,7 +41,7 @@ public class Templates implements ModInitializer { //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::makeTemplateBlockEntity, CUBE, FENCE, SLAB, SLOPE, WALL).build(null) + FabricBlockEntityTypeBuilder.create(Templates::makeTemplateBlockEntity, CUBE, FENCE, POST, SLAB, SLOPE, WALL).build(null) ); @SuppressWarnings("unused") @@ -58,6 +61,7 @@ public class Templates implements ModInitializer { public void onInitialize() { Registry.register(Registries.ITEM, id("cube"), new BlockItem(CUBE, new Item.Settings())); Registry.register(Registries.ITEM, id("fence"), new BlockItem(FENCE, new Item.Settings())); + Registry.register(Registries.ITEM, id("post"), new BlockItem(POST, new Item.Settings())); Registry.register(Registries.ITEM, id("slab"), new BlockItem(SLAB, new Item.Settings())); Registry.register(Registries.ITEM, id("slope"), new BlockItem(SLOPE, new Item.Settings())); Registry.register(Registries.ITEM, id("wall"), new BlockItem(WALL, new Item.Settings())); @@ -75,6 +79,7 @@ public class Templates implements ModInitializer { private static void fillItemGroup(ItemGroup.DisplayContext ctx, ItemGroup.Entries ent) { ent.add(CUBE); ent.add(FENCE); + ent.add(POST); ent.add(SLAB); ent.add(SLOPE); ent.add(WALL); diff --git a/src/main/java/io/github/cottonmc/templates/TemplatesClient.java b/src/main/java/io/github/cottonmc/templates/TemplatesClient.java index 06f386a..f2c8796 100644 --- a/src/main/java/io/github/cottonmc/templates/TemplatesClient.java +++ b/src/main/java/io/github/cottonmc/templates/TemplatesClient.java @@ -54,7 +54,14 @@ 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.CUBE, Templates.FENCE, Templates.SLAB, Templates.SLOPE, Templates.WALL); + BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), + Templates.CUBE, + Templates.FENCE, + Templates.POST, + Templates.SLAB, + Templates.SLOPE, + Templates.WALL + ); provider.addTemplateModel(Templates.id("cube_special"), new RetexturedJsonModelUnbakedModel(Templates.id("block/cube"))); provider.addTemplateModel(Templates.id("fence_post_special"), new RetexturedJsonModelUnbakedModel(Templates.id("block/fence_post"))); @@ -70,6 +77,7 @@ public class TemplatesClient implements ClientModInitializer { provider.assignItemModel(Templates.id("cube_special"), Templates.CUBE); provider.assignItemModel(Templates.id("fence_inventory_special"), Templates.FENCE); + provider.assignItemModel(Templates.id("fence_post_special"), Templates.POST); provider.assignItemModel(Templates.id("slope_special"), Templates.SLOPE); provider.assignItemModel(Templates.id("slab_bottom_special"), Templates.SLAB); provider.assignItemModel(Templates.id("wall_inventory_special"), Templates.WALL); diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplatePostBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplatePostBlock.java new file mode 100644 index 0000000..0bb8de1 --- /dev/null +++ b/src/main/java/io/github/cottonmc/templates/block/TemplatePostBlock.java @@ -0,0 +1,57 @@ +package io.github.cottonmc.templates.block; + +import com.google.common.base.MoreObjects; +import io.github.cottonmc.templates.api.TemplateInteractionUtil; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.ShapeContext; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.Properties; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.BlockView; +import org.jetbrains.annotations.Nullable; + +public class TemplatePostBlock extends WaterloggableTemplateBlock { + public TemplatePostBlock(Settings settings) { + super(settings); + + setDefaultState(getDefaultState().with(Properties.AXIS, Direction.Axis.Y)); + } + + @Override + protected void appendProperties(StateManager.Builder builder) { + super.appendProperties(builder.add(Properties.AXIS)); + } + + @Override + public @Nullable BlockState getPlacementState(ItemPlacementContext ctx) { + BlockState sup = super.getPlacementState(ctx); + if(sup != null) sup = sup.with(Properties.AXIS, ctx.getSide().getAxis()); + return sup; + } + + protected static final VoxelShape SHAPE_X = createCuboidShape(0, 6, 6, 16, 10, 10); + protected static final VoxelShape SHAPE_Y = createCuboidShape(6, 0, 6, 10, 16, 10); + protected static final VoxelShape SHAPE_Z = createCuboidShape(6, 6, 0, 10, 10, 16); + + protected VoxelShape shap(BlockState state) { + return switch(state.get(Properties.AXIS)) { + case X -> SHAPE_X; + case Y -> SHAPE_Y; + case Z -> SHAPE_Z; + }; + } + + @Override + public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) { + return MoreObjects.firstNonNull(TemplateInteractionUtil.getCollisionShape(state), shap(state)); + } + + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) { + return shap(state); + } +} diff --git a/src/main/resources/assets/templates/blockstates/post.json b/src/main/resources/assets/templates/blockstates/post.json new file mode 100644 index 0000000..7f1672a --- /dev/null +++ b/src/main/resources/assets/templates/blockstates/post.json @@ -0,0 +1,19 @@ +{ + "variants": { + "axis=x": { + "model": "templates:fence_post_special", + "x": 90, + "y": 90, + "uvlock": true + }, + "axis=y": { + "model": "templates:fence_post_special", + "uvlock": true + }, + "axis=z": { + "model": "templates:fence_post_special", + "uvlock": true, + "x": 90 + } + } +} \ 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 7820876..706f481 100644 --- a/src/main/resources/assets/templates/lang/en_us.json +++ b/src/main/resources/assets/templates/lang/en_us.json @@ -3,6 +3,7 @@ "block.templates.cube": "Cube Template", "block.templates.fence": "Fence Template", + "block.templates.post": "Post Template", "block.templates.slope": "Slope Template", "block.templates.slab": "Slab Template", "block.templates.wall": "Wall Template" 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 f2df0bf..a1e16cf 100644 --- a/src/main/resources/data/templates/advancements/recipes/decorations/templates.json +++ b/src/main/resources/data/templates/advancements/recipes/decorations/templates.json @@ -4,6 +4,7 @@ "recipes": [ "templates:cube", "templates:fence", + "templates:post", "templates:slab", "templates:slope", "templates:wall" diff --git a/src/main/resources/data/templates/loot_tables/blocks/post.json b/src/main/resources/data/templates/loot_tables/blocks/post.json new file mode 100644 index 0000000..7c2b8e9 --- /dev/null +++ b/src/main/resources/data/templates/loot_tables/blocks/post.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "templates:post" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/templates/recipes/post.json b/src/main/resources/data/templates/recipes/post.json new file mode 100644 index 0000000..218de3e --- /dev/null +++ b/src/main/resources/data/templates/recipes/post.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "I ", + "I~", + "I " + ], + "key": { + "I": { + "item": "minecraft:bamboo" + }, + "~": { + "item": "minecraft:string" + } + }, + "result": { + "item": "templates:post", + "count": 8 + }, + "group": "templates" +} \ No newline at end of file