From 3683ebd97aa4b9bf6eadd597595d20cd2e0bf0ac Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 18 Oct 2021 20:09:41 +0200 Subject: [PATCH] Auto-Add Block/Item Tags for `BaseLeavesBlock` and `FeatureSaplingBlock` (paulevsGitch/BetterEnd#303) --- .../java/ru/bclib/blocks/BaseLeavesBlock.java | 9 --------- .../java/ru/bclib/registry/BlockRegistry.java | 20 ++++++++++++++++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java index 3ac139bf..2ded221e 100644 --- a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java @@ -20,7 +20,6 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import ru.bclib.api.TagAPI; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.BlockModelProvider; import ru.bclib.interfaces.RenderLayerProvider; @@ -40,32 +39,24 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, .blockVision((state, world, pos) -> false); } - private void init(Block sapling) { - TagAPI.addTags(this, TagAPI.BLOCK_LEAVES); - } - public BaseLeavesBlock(Block sapling, MaterialColor color, Consumer customizeProperties) { super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color))); this.sapling = sapling; - init(sapling); } public BaseLeavesBlock(Block sapling, MaterialColor color, int light, Consumer customizeProperties) { super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color).luminance(light))); this.sapling = sapling; - init(sapling); } public BaseLeavesBlock(Block sapling, MaterialColor color) { super(makeLeaves(color)); this.sapling = sapling; - init(sapling); } public BaseLeavesBlock(Block sapling, MaterialColor color, int light) { super(makeLeaves(color).lightLevel(light)); this.sapling = sapling; - init(sapling); } @Override diff --git a/src/main/java/ru/bclib/registry/BlockRegistry.java b/src/main/java/ru/bclib/registry/BlockRegistry.java index 80ee433b..ce9d941e 100644 --- a/src/main/java/ru/bclib/registry/BlockRegistry.java +++ b/src/main/java/ru/bclib/registry/BlockRegistry.java @@ -7,6 +7,9 @@ import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; +import ru.bclib.api.TagAPI; +import ru.bclib.blocks.BaseLeavesBlock; +import ru.bclib.blocks.FeatureSaplingBlock; import ru.bclib.interfaces.CustomItemProvider; public abstract class BlockRegistry extends BaseRegistry { @@ -29,7 +32,22 @@ public abstract class BlockRegistry extends BaseRegistry { .getBurnChance() == 0) { FlammableBlockRegistry.getDefaultInstance().add(block, 5, 5); } - return Registry.register(Registry.BLOCK, id, block); + + block = Registry.register(Registry.BLOCK, id, block); + + if (block instanceof BaseLeavesBlock){ + TagAPI.addTags(block, TagAPI.BLOCK_LEAVES); + if (item != null){ + TagAPI.addTags(item, TagAPI.ITEM_LEAVES); + } + } else if (block instanceof FeatureSaplingBlock){ + TagAPI.addTags(block, TagAPI.BLOCK_SAPLINGS); + if (item != null){ + TagAPI.addTags(item, TagAPI.ITEM_SAPLINGS); + } + } + + return block; } public Block registerBlockOnly(ResourceLocation id, Block block) {