From 3d77770a8b7370ff69501240b1a63e5cacc173e7 Mon Sep 17 00:00:00 2001 From: quat1024 Date: Sun, 9 Jul 2023 01:06:10 -0400 Subject: [PATCH] Spend less on candles --- .../github/cottonmc/templates/Templates.java | 29 ++++--- .../cottonmc/templates/TemplatesClient.java | 5 ++ .../templates/block/TemplateCandleBlock.java | 85 +++++++++++++++++++ .../assets/templates/blockstates/candle.json | 16 ++++ .../assets/templates/lang/en_us.json | 1 + .../data/minecraft/tags/blocks/candles.json | 6 ++ .../recipes/decorations/templates.json | 1 + .../templates/loot_tables/blocks/candle.json | 63 ++++++++++++++ .../data/templates/recipes/candle.json | 24 ++++++ 9 files changed, 218 insertions(+), 12 deletions(-) create mode 100644 src/main/java/io/github/cottonmc/templates/block/TemplateCandleBlock.java create mode 100644 src/main/resources/assets/templates/blockstates/candle.json create mode 100644 src/main/resources/data/minecraft/tags/blocks/candles.json create mode 100644 src/main/resources/data/templates/loot_tables/blocks/candle.json create mode 100644 src/main/resources/data/templates/recipes/candle.json diff --git a/src/main/java/io/github/cottonmc/templates/Templates.java b/src/main/java/io/github/cottonmc/templates/Templates.java index 1599eec..ee4c46d 100644 --- a/src/main/java/io/github/cottonmc/templates/Templates.java +++ b/src/main/java/io/github/cottonmc/templates/Templates.java @@ -3,6 +3,7 @@ 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.TemplateButtonBlock; +import io.github.cottonmc.templates.block.TemplateCandleBlock; import io.github.cottonmc.templates.block.TemplateCarpetBlock; import io.github.cottonmc.templates.block.TemplateFenceBlock; import io.github.cottonmc.templates.block.TemplateFenceGateBlock; @@ -16,16 +17,16 @@ import io.github.cottonmc.templates.block.TemplateWallBlock; 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.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.block.piston.PistonBehavior; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; -import net.minecraft.sound.BlockSoundGroup; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -46,21 +47,25 @@ public class Templates implements ModInitializer { return b; } - public static final Block BUTTON = reg("button", new TemplateButtonBlock(TemplateInteractionUtil.makeSettings().pistonBehavior(PistonBehavior.DESTROY))); - //candle? (lol) - public static final Block CARPET = reg("carpet", new TemplateCarpetBlock(TemplateInteractionUtil.makeSettings().sounds(BlockSoundGroup.WOOL).pistonBehavior(PistonBehavior.DESTROY))); + private static AbstractBlock.Settings cp(Block base) { + return TemplateInteractionUtil.configureSettings(AbstractBlock.Settings.copy(base)); + } + + public static final Block BUTTON = reg("button", new TemplateButtonBlock(cp(Blocks.OAK_BUTTON))); + public static final Block CANDLE = reg("candle", new TemplateCandleBlock(TemplateCandleBlock.configureSettings(cp(Blocks.CANDLE)))); + public static final Block CARPET = reg("carpet", new TemplateCarpetBlock(cp(Blocks.WHITE_CARPET))); public static final Block CUBE = reg("cube", new TemplateBlock(TemplateInteractionUtil.makeSettings())); //door? (hard cause its a multiblock) - public static final Block FENCE = reg("fence", new TemplateFenceBlock(TemplateInteractionUtil.makeSettings())); - public static final Block FENCE_GATE = reg("fence_gate", new TemplateFenceGateBlock(TemplateInteractionUtil.makeSettings())); - public static final Block LEVER = reg("lever", new TemplateLeverBlock(TemplateInteractionUtil.makeSettings().pistonBehavior(PistonBehavior.DESTROY))); + 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 POST = reg("post", new TemplatePostBlock(TemplateInteractionUtil.makeSettings())); - public static final Block PRESSURE_PLATE = reg("pressure_plate", new TemplatePressurePlateBlock(TemplateInteractionUtil.makeSettings().noCollision().pistonBehavior(PistonBehavior.DESTROY))); - public static final Block SLAB = reg("slab", new TemplateSlabBlock(TemplateInteractionUtil.makeSettings())); + 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))); //stair //trapdoor - public static final Block WALL = reg("wall", new TemplateWallBlock(TemplateInteractionUtil.makeSettings())); + public static final Block WALL = reg("wall", new TemplateWallBlock(cp(Blocks.COBBLESTONE_WALL))); public static final Block SLOPE = reg("slope", new TemplateSlopeBlock(TemplateInteractionUtil.makeSettings())); //30 degree slope (shallow/deep) diff --git a/src/main/java/io/github/cottonmc/templates/TemplatesClient.java b/src/main/java/io/github/cottonmc/templates/TemplatesClient.java index 6808fcb..608fc3e 100644 --- a/src/main/java/io/github/cottonmc/templates/TemplatesClient.java +++ b/src/main/java/io/github/cottonmc/templates/TemplatesClient.java @@ -61,6 +61,10 @@ public class TemplatesClient implements ClientModInitializer { //vanilla style models (using "auto" method) provider.addTemplateModel(Templates.id("button_special"), new UnbakedAutoRetexturedModel(new Identifier("block/button"))); provider.addTemplateModel(Templates.id("button_pressed_special"), new UnbakedAutoRetexturedModel(new Identifier("block/button_pressed"))); + provider.addTemplateModel(Templates.id("one_candle_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_candle"))); + provider.addTemplateModel(Templates.id("two_candles_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_two_candles"))); + provider.addTemplateModel(Templates.id("three_candles_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_three_candles"))); + provider.addTemplateModel(Templates.id("four_candles_special"), new UnbakedAutoRetexturedModel(new Identifier("block/template_four_candles"))); provider.addTemplateModel(Templates.id("carpet_special"), new UnbakedAutoRetexturedModel(new Identifier("block/carpet"))); provider.addTemplateModel(Templates.id("cube_special"), new UnbakedAutoRetexturedModel(new Identifier("block/cube"))); provider.addTemplateModel(Templates.id("fence_post_special"), new UnbakedAutoRetexturedModel(new Identifier("block/fence_post"))); @@ -92,6 +96,7 @@ public class TemplatesClient implements ClientModInitializer { //item model assignments (in lieu of models/item/___.json) provider.assignItemModel(Templates.id("button_inventory_special"), Templates.BUTTON); + provider.assignItemModel(Templates.id("one_candle_special"), Templates.CANDLE); //TODO vanilla uses its own item model provider.assignItemModel(Templates.id("carpet_special"), Templates.CARPET); provider.assignItemModel(Templates.id("cube_special"), Templates.CUBE); provider.assignItemModel(Templates.id("fence_inventory_special"), Templates.FENCE); diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateCandleBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplateCandleBlock.java new file mode 100644 index 0000000..6fa0fc2 --- /dev/null +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateCandleBlock.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.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockEntityProvider; +import net.minecraft.block.BlockState; +import net.minecraft.block.CandleBlock; +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 TemplateCandleBlock extends CandleBlock implements BlockEntityProvider { + public TemplateCandleBlock(Settings settings) { + super(settings); + setDefaultState(TemplateInteractionUtil.setDefaultStates(getDefaultState())); + } + + public static AbstractBlock.Settings configureSettings(AbstractBlock.Settings in) { + return in.luminance(state -> Math.max(TemplateInteractionUtil.luminance(state), CandleBlock.STATE_TO_LUMINANCE.applyAsInt(state))); + } + + @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/candle.json b/src/main/resources/assets/templates/blockstates/candle.json new file mode 100644 index 0000000..dab7d87 --- /dev/null +++ b/src/main/resources/assets/templates/blockstates/candle.json @@ -0,0 +1,16 @@ +{ + "variants": { + "candles=1": { + "model": "templates:one_candle_special" + }, + "candles=2": { + "model": "templates:two_candles_special" + }, + "candles=3": { + "model": "templates:three_candles_special" + }, + "candles=4": { + "model": "templates:four_candles_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 fc5ac87..ff573a4 100644 --- a/src/main/resources/assets/templates/lang/en_us.json +++ b/src/main/resources/assets/templates/lang/en_us.json @@ -2,6 +2,7 @@ "itemGroup.templates.tab": "Templates", "block.templates.button": "Button Template", + "block.templates.candle": "Candle Template", "block.templates.carpet": "Carpet Template", "block.templates.cube": "Cube Template", "block.templates.fence": "Fence Template", diff --git a/src/main/resources/data/minecraft/tags/blocks/candles.json b/src/main/resources/data/minecraft/tags/blocks/candles.json new file mode 100644 index 0000000..9cce157 --- /dev/null +++ b/src/main/resources/data/minecraft/tags/blocks/candles.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "templates:candle" + ] +} \ 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 1ff4d06..98ac140 100644 --- a/src/main/resources/data/templates/advancements/recipes/decorations/templates.json +++ b/src/main/resources/data/templates/advancements/recipes/decorations/templates.json @@ -3,6 +3,7 @@ "rewards": { "recipes": [ "templates:button", + "templates:candle", "templates:carpet", "templates:cube", "templates:fence", diff --git a/src/main/resources/data/templates/loot_tables/blocks/candle.json b/src/main/resources/data/templates/loot_tables/blocks/candle.json new file mode 100644 index 0000000..1f24d7b --- /dev/null +++ b/src/main/resources/data/templates/loot_tables/blocks/candle.json @@ -0,0 +1,63 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "entries": [ + { + "type": "minecraft:item", + "functions": [ + { + "add": false, + "conditions": [ + { + "block": "templates:candle", + "condition": "minecraft:block_state_property", + "properties": { + "candles": "2" + } + } + ], + "count": 2.0, + "function": "minecraft:set_count" + }, + { + "add": false, + "conditions": [ + { + "block": "templates:candle", + "condition": "minecraft:block_state_property", + "properties": { + "candles": "3" + } + } + ], + "count": 3.0, + "function": "minecraft:set_count" + }, + { + "add": false, + "conditions": [ + { + "block": "templates:candle", + "condition": "minecraft:block_state_property", + "properties": { + "candles": "4" + } + } + ], + "count": 4.0, + "function": "minecraft:set_count" + }, + { + "function": "minecraft:explosion_decay" + } + ], + "name": "templates:candle" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "minecraft:blocks/candle" +} \ No newline at end of file diff --git a/src/main/resources/data/templates/recipes/candle.json b/src/main/resources/data/templates/recipes/candle.json new file mode 100644 index 0000000..a21d459 --- /dev/null +++ b/src/main/resources/data/templates/recipes/candle.json @@ -0,0 +1,24 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "~", + "I", + "C" + ], + "key": { + "I": { + "item": "minecraft:bamboo" + }, + "~": { + "item": "minecraft:string" + }, + "C": { + "item": "#minecraft:candles" + } + }, + "result": { + "item": "templates:candle", + "count": 1 + }, + "group": "templates" +} \ No newline at end of file