diff --git a/src/main/java/io/github/cottonmc/templates/Templates.java b/src/main/java/io/github/cottonmc/templates/Templates.java index 933bd4a..f63d67b 100644 --- a/src/main/java/io/github/cottonmc/templates/Templates.java +++ b/src/main/java/io/github/cottonmc/templates/Templates.java @@ -8,12 +8,14 @@ import io.github.cottonmc.templates.block.TemplateCarpetBlock; import io.github.cottonmc.templates.block.TemplateFenceBlock; import io.github.cottonmc.templates.block.TemplateFenceGateBlock; import io.github.cottonmc.templates.block.TemplateLeverBlock; +import io.github.cottonmc.templates.block.TemplatePaneBlock; import io.github.cottonmc.templates.block.TemplatePostBlock; import io.github.cottonmc.templates.block.TemplatePressurePlateBlock; 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.TemplateStairsBlock; +import io.github.cottonmc.templates.block.TemplateTrapdoorBlock; import io.github.cottonmc.templates.block.TemplateWallBlock; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; @@ -60,12 +62,12 @@ public class Templates implements ModInitializer { public static final Block FENCE = reg("fence", new TemplateFenceBlock(cp(Blocks.OAK_FENCE))); public static final Block FENCE_GATE = reg("fence_gate", new TemplateFenceGateBlock(cp(Blocks.OAK_FENCE_GATE))); public static final Block LEVER = reg("lever", new TemplateLeverBlock(cp(Blocks.LEVER))); - //pane + public static final Block PANE = reg("pane", new TemplatePaneBlock(cp(Blocks.GLASS_PANE))); public static final Block POST = reg("post", new TemplatePostBlock(cp(Blocks.OAK_FENCE))); public static final Block PRESSURE_PLATE = reg("pressure_plate", new TemplatePressurePlateBlock(cp(Blocks.OAK_PRESSURE_PLATE))); public static final Block SLAB = reg("slab", new TemplateSlabBlock(cp(Blocks.OAK_SLAB))); public static final Block STAIRS = reg("stairs", new TemplateStairsBlock(cp(Blocks.OAK_STAIRS))); - //trapdoor + public static final Block TRAPDOOR = reg("trapdoor", new TemplateTrapdoorBlock(cp(Blocks.OAK_TRAPDOOR))); public static final Block WALL = reg("wall", new TemplateWallBlock(cp(Blocks.COBBLESTONE_WALL))); public static final Block SLOPE = reg("slope", new TemplateSlopeBlock(TemplateInteractionUtil.makeSettings())); diff --git a/src/main/java/io/github/cottonmc/templates/TemplatesClient.java b/src/main/java/io/github/cottonmc/templates/TemplatesClient.java index bb467ab..34d6d6b 100644 --- a/src/main/java/io/github/cottonmc/templates/TemplatesClient.java +++ b/src/main/java/io/github/cottonmc/templates/TemplatesClient.java @@ -73,6 +73,11 @@ public class TemplatesClient implements ClientModInitializer { provider.addTemplateModel(Templates.id("fence_gate_open_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_fence_gate_open"))); provider.addTemplateModel(Templates.id("fence_gate_wall_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_fence_gate_wall"))); provider.addTemplateModel(Templates.id("fence_gate_wall_open_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_fence_gate_wall_open"))); + provider.addTemplateModel(Templates.id("glass_pane_post_special"), new UnbakedAutoRetexturedModel(new Identifier("block/glass_pane_post"))); + provider.addTemplateModel(Templates.id("glass_pane_side_special"), new UnbakedAutoRetexturedModel(new Identifier("block/glass_pane_side"))); + provider.addTemplateModel(Templates.id("glass_pane_side_alt_special"), new UnbakedAutoRetexturedModel(new Identifier("block/glass_pane_side_alt"))); + provider.addTemplateModel(Templates.id("glass_pane_noside_special"), new UnbakedAutoRetexturedModel(new Identifier("block/glass_pane_noside"))); + provider.addTemplateModel(Templates.id("glass_pane_noside_alt_special"), new UnbakedAutoRetexturedModel(new Identifier("block/glass_pane_noside_alt"))); provider.addTemplateModel(Templates.id("pressure_plate_up_special"), new UnbakedAutoRetexturedModel(new Identifier("block/pressure_plate_up"))); provider.addTemplateModel(Templates.id("pressure_plate_down_special"), new UnbakedAutoRetexturedModel(new Identifier("block/pressure_plate_down"))); provider.addTemplateModel(Templates.id("slab_bottom_special"), new UnbakedAutoRetexturedModel(new Identifier("block/slab"))); @@ -80,6 +85,9 @@ public class TemplatesClient implements ClientModInitializer { provider.addTemplateModel(Templates.id("stairs_special"), new UnbakedAutoRetexturedModel(new Identifier("block/stairs"))); provider.addTemplateModel(Templates.id("inner_stairs_special"), new UnbakedAutoRetexturedModel(new Identifier("block/inner_stairs"))); provider.addTemplateModel(Templates.id("outer_stairs_special"), new UnbakedAutoRetexturedModel(new Identifier("block/outer_stairs"))); + provider.addTemplateModel(Templates.id("trapdoor_bottom_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_trapdoor_bottom"))); + provider.addTemplateModel(Templates.id("trapdoor_open_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_trapdoor_open"))); + provider.addTemplateModel(Templates.id("trapdoor_top_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_trapdoor_top"))); provider.addTemplateModel(Templates.id("wall_post_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_wall_post"))); provider.addTemplateModel(Templates.id("wall_side_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_wall_side"))); provider.addTemplateModel(Templates.id("wall_side_tall_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_wall_side_tall"))); @@ -106,11 +114,13 @@ public class TemplatesClient implements ClientModInitializer { provider.assignItemModel(Templates.id("fence_inventory_special"), Templates.FENCE); provider.assignItemModel(Templates.id("fence_gate_special"), Templates.FENCE_GATE); provider.assignItemModel(Templates.id("lever_special"), Templates.LEVER); //TODO vanilla uses its own item model + //provider.assignItemModel(Templates.id("glass_pane_side_special"), Templates.PANE); //Done with a regular json model actually provider.assignItemModel(Templates.id("fence_post_inventory_special"), Templates.POST); provider.assignItemModel(Templates.id("pressure_plate_up_special"), Templates.PRESSURE_PLATE); provider.assignItemModel(Templates.id("slope_special"), Templates.SLOPE); provider.assignItemModel(Templates.id("slab_bottom_special"), Templates.SLAB); provider.assignItemModel(Templates.id("stairs_special"), Templates.STAIRS); + provider.assignItemModel(Templates.id("trapdoor_bottom_special"), Templates.TRAPDOOR); provider.assignItemModel(Templates.id("wall_inventory_special"), Templates.WALL); } } diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplatePaneBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplatePaneBlock.java new file mode 100644 index 0000000..d33bd9a --- /dev/null +++ b/src/main/java/io/github/cottonmc/templates/block/TemplatePaneBlock.java @@ -0,0 +1,80 @@ +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; +import net.minecraft.block.BlockState; +import net.minecraft.block.PaneBlock; +import net.minecraft.block.ShapeContext; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.state.StateManager; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; + +public class TemplatePaneBlock extends PaneBlock implements BlockEntityProvider { + public TemplatePaneBlock(Settings settings) { + super(settings); + setDefaultState(TemplateInteractionUtil.setDefaultStates(getDefaultState())); + } + + @Override + public @Nullable BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return Templates.TEMPLATE_BLOCK_ENTITY.instantiate(pos, state); + } + + @Override + protected void appendProperties(StateManager.Builder builder) { + super.appendProperties(TemplateInteractionUtil.appendProperties(builder)); + } + + @Override + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + ActionResult r = TemplateInteractionUtil.onUse(state, world, pos, player, hand, hit); + if(!r.isAccepted()) r = super.onUse(state, world, pos, player, hand, hit); + return r; + } + + @Override + public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { + TemplateInteractionUtil.onStateReplaced(state, world, pos, newState, moved); + super.onStateReplaced(state, world, pos, newState, moved); + } + + @Override + public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { + TemplateInteractionUtil.onPlaced(world, pos, state, placer, stack); + super.onPlaced(world, pos, state, placer, stack); + } + + @Override + public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) { + return MoreObjects.firstNonNull(TemplateInteractionUtil.getCollisionShape(state, view, pos, ctx), super.getCollisionShape(state, view, pos, ctx)); + } + + @Override + public boolean emitsRedstonePower(BlockState state) { + return TemplateInteractionUtil.emitsRedstonePower(state); + } + + @Override + public int getWeakRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction dir) { + return TemplateInteractionUtil.getWeakRedstonePower(state, view, pos, dir); + } + + @Override + public int getStrongRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction dir) { + return TemplateInteractionUtil.getStrongRedstonePower(state, view, pos, dir); + } +} diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateTrapdoorBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplateTrapdoorBlock.java new file mode 100644 index 0000000..7e20590 --- /dev/null +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateTrapdoorBlock.java @@ -0,0 +1,85 @@ +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; +import net.minecraft.block.BlockSetType; +import net.minecraft.block.BlockState; +import net.minecraft.block.ShapeContext; +import net.minecraft.block.TrapdoorBlock; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.state.StateManager; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; + +public class TemplateTrapdoorBlock extends TrapdoorBlock implements BlockEntityProvider { + public TemplateTrapdoorBlock(Settings settings, BlockSetType blah) { + super(settings, blah); + setDefaultState(TemplateInteractionUtil.setDefaultStates(getDefaultState())); + } + + public TemplateTrapdoorBlock(Settings settings) { + this(settings, BlockSetType.OAK); + } + + @Override + public @Nullable BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return Templates.TEMPLATE_BLOCK_ENTITY.instantiate(pos, state); + } + + @Override + protected void appendProperties(StateManager.Builder builder) { + super.appendProperties(TemplateInteractionUtil.appendProperties(builder)); + } + + @Override + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + ActionResult r = TemplateInteractionUtil.onUse(state, world, pos, player, hand, hit); + if(!r.isAccepted()) r = super.onUse(state, world, pos, player, hand, hit); + return r; + } + + @Override + public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { + TemplateInteractionUtil.onStateReplaced(state, world, pos, newState, moved); + super.onStateReplaced(state, world, pos, newState, moved); + } + + @Override + public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { + TemplateInteractionUtil.onPlaced(world, pos, state, placer, stack); + super.onPlaced(world, pos, state, placer, stack); + } + + @Override + public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) { + return MoreObjects.firstNonNull(TemplateInteractionUtil.getCollisionShape(state, view, pos, ctx), super.getCollisionShape(state, view, pos, ctx)); + } + + @Override + public boolean emitsRedstonePower(BlockState state) { + return TemplateInteractionUtil.emitsRedstonePower(state); + } + + @Override + public int getWeakRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction dir) { + return TemplateInteractionUtil.getWeakRedstonePower(state, view, pos, dir); + } + + @Override + public int getStrongRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction dir) { + return TemplateInteractionUtil.getStrongRedstonePower(state, view, pos, dir); + } +} diff --git a/src/main/resources/assets/templates/blockstates/pane.json b/src/main/resources/assets/templates/blockstates/pane.json new file mode 100644 index 0000000..463e918 --- /dev/null +++ b/src/main/resources/assets/templates/blockstates/pane.json @@ -0,0 +1,77 @@ +{ + "multipart": [ + { + "apply": { + "model": "templates:glass_pane_post_special" + } + }, + { + "apply": { + "model": "templates:glass_pane_side_special" + }, + "when": { + "north": "true" + } + }, + { + "apply": { + "model": "templates:glass_pane_side_special", + "y": 90 + }, + "when": { + "east": "true" + } + }, + { + "apply": { + "model": "templates:glass_pane_side_alt_special" + }, + "when": { + "south": "true" + } + }, + { + "apply": { + "model": "templates:glass_pane_side_alt_special", + "y": 90 + }, + "when": { + "west": "true" + } + }, + { + "apply": { + "model": "templates:glass_pane_noside_special" + }, + "when": { + "north": "false" + } + }, + { + "apply": { + "model": "templates:glass_pane_noside_alt_special" + }, + "when": { + "east": "false" + } + }, + { + "apply": { + "model": "templates:glass_pane_noside_alt_special", + "y": 90 + }, + "when": { + "south": "false" + } + }, + { + "apply": { + "model": "templates:glass_pane_noside_special", + "y": 270 + }, + "when": { + "west": "false" + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/templates/blockstates/trapdoor.json b/src/main/resources/assets/templates/blockstates/trapdoor.json new file mode 100644 index 0000000..f7f5a6a --- /dev/null +++ b/src/main/resources/assets/templates/blockstates/trapdoor.json @@ -0,0 +1,69 @@ +{ + "variants": { + "facing=east,half=bottom,open=false": { + "model": "templates:trapdoor_bottom_special", + "y": 90 + }, + "facing=east,half=bottom,open=true": { + "model": "templates:trapdoor_open_special", + "y": 90 + }, + "facing=east,half=top,open=false": { + "model": "templates:trapdoor_top_special", + "y": 90 + }, + "facing=east,half=top,open=true": { + "model": "templates:trapdoor_open_special", + "x": 180, + "y": 270 + }, + "facing=north,half=bottom,open=false": { + "model": "templates:trapdoor_bottom_special" + }, + "facing=north,half=bottom,open=true": { + "model": "templates:trapdoor_open_special" + }, + "facing=north,half=top,open=false": { + "model": "templates:trapdoor_top_special" + }, + "facing=north,half=top,open=true": { + "model": "templates:trapdoor_open_special", + "x": 180, + "y": 180 + }, + "facing=south,half=bottom,open=false": { + "model": "templates:trapdoor_bottom_special", + "y": 180 + }, + "facing=south,half=bottom,open=true": { + "model": "templates:trapdoor_open_special", + "y": 180 + }, + "facing=south,half=top,open=false": { + "model": "templates:trapdoor_top_special", + "y": 180 + }, + "facing=south,half=top,open=true": { + "model": "templates:trapdoor_open_special", + "x": 180, + "y": 0 + }, + "facing=west,half=bottom,open=false": { + "model": "templates:trapdoor_bottom_special", + "y": 270 + }, + "facing=west,half=bottom,open=true": { + "model": "templates:trapdoor_open_special", + "y": 270 + }, + "facing=west,half=top,open=false": { + "model": "templates:trapdoor_top_special", + "y": 270 + }, + "facing=west,half=top,open=true": { + "model": "templates:trapdoor_open_special", + "x": 180, + "y": 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 9c769ac..11068a4 100644 --- a/src/main/resources/assets/templates/lang/en_us.json +++ b/src/main/resources/assets/templates/lang/en_us.json @@ -8,10 +8,12 @@ "block.templates.fence": "Fence Template", "block.templates.fence_gate": "Fence Gate Template", "block.templates.lever": "Lever Template", + "block.templates.pane": "Pane Template", "block.templates.post": "Post Template", "block.templates.pressure_plate": "Pressure Plate Template", "block.templates.slope": "Slope Template", "block.templates.slab": "Slab Template", "block.templates.stairs": "Stairs Template", + "block.templates.trapdoor": "Trapdoor Template", "block.templates.wall": "Wall Template" } \ No newline at end of file diff --git a/src/main/resources/assets/templates/models/item/pane.json b/src/main/resources/assets/templates/models/item/pane.json new file mode 100644 index 0000000..d51ecf4 --- /dev/null +++ b/src/main/resources/assets/templates/models/item/pane.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "minecraft:block/scaffolding_top" + } +} \ 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 08e483f..72621e6 100644 --- a/src/main/resources/data/templates/advancements/recipes/decorations/templates.json +++ b/src/main/resources/data/templates/advancements/recipes/decorations/templates.json @@ -8,10 +8,12 @@ "templates:cube", "templates:fence", "templates:fence_gate", + "templates:pane", "templates:post", "templates:slab", "templates:slope", "templates:stairs", + "templates:trapdoor", "templates:wall" ] }, diff --git a/src/main/resources/data/templates/loot_tables/blocks/pane.json b/src/main/resources/data/templates/loot_tables/blocks/pane.json new file mode 100644 index 0000000..e7de537 --- /dev/null +++ b/src/main/resources/data/templates/loot_tables/blocks/pane.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "templates:pane" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/templates/loot_tables/blocks/slab.json b/src/main/resources/data/templates/loot_tables/blocks/slab.json index 58d8f8b..c07fdf5 100644 --- a/src/main/resources/data/templates/loot_tables/blocks/slab.json +++ b/src/main/resources/data/templates/loot_tables/blocks/slab.json @@ -6,6 +6,25 @@ "entries": [ { "type": "minecraft:item", + "functions": [ + { + "add": false, + "conditions": [ + { + "block": "templates:slab", + "condition": "minecraft:block_state_property", + "properties": { + "type": "double" + } + } + ], + "count": 2.0, + "function": "minecraft:set_count" + }, + { + "function": "minecraft:explosion_decay" + } + ], "name": "templates:slab" } ], diff --git a/src/main/resources/data/templates/loot_tables/blocks/trapdoor.json b/src/main/resources/data/templates/loot_tables/blocks/trapdoor.json new file mode 100644 index 0000000..13a9352 --- /dev/null +++ b/src/main/resources/data/templates/loot_tables/blocks/trapdoor.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "templates:trapdoor" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/templates/recipes/pane.json b/src/main/resources/data/templates/recipes/pane.json new file mode 100644 index 0000000..7339df0 --- /dev/null +++ b/src/main/resources/data/templates/recipes/pane.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "~ ~", + "III", + "III" + ], + "key": { + "I": { + "item": "minecraft:bamboo" + }, + "~": { + "item": "minecraft:string" + } + }, + "result": { + "item": "templates:pane", + "count": 16 + }, + "group": "templates" +} \ No newline at end of file diff --git a/src/main/resources/data/templates/recipes/trapdoor.json b/src/main/resources/data/templates/recipes/trapdoor.json new file mode 100644 index 0000000..ccbad5e --- /dev/null +++ b/src/main/resources/data/templates/recipes/trapdoor.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "III", + "III", + "~ ~" + ], + "key": { + "I": { + "item": "minecraft:bamboo" + }, + "~": { + "item": "minecraft:string" + } + }, + "result": { + "item": "templates:trapdoor", + "count": 4 + }, + "group": "templates" +} \ No newline at end of file