Updated Tag API and tag constants

This commit is contained in:
paulevsGitch 2022-01-21 14:56:37 +03:00
parent 7ab5377a03
commit db082ef1be
35 changed files with 308 additions and 385 deletions

View file

@ -4,9 +4,6 @@ import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.Tag;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
@ -14,6 +11,7 @@ import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.MaterialColor;
import ru.bclib.BCLib;
import ru.bclib.api.TagAPI;
import ru.bclib.api.TagAPI.TagLocation;
import ru.bclib.blocks.BaseBarkBlock;
import ru.bclib.blocks.BaseBarrelBlock;
import ru.bclib.blocks.BaseBlock;
@ -98,112 +96,92 @@ public class WoodenComplexMaterial extends ComplexMaterial {
}
final protected void initBase(FabricBlockSettings blockSettings, FabricItemSettings itemSettings) {
Tag.Named<Block> tagBlockLog = getBlockTag(TAG_LOGS);
Tag.Named<Item> tagItemLog = getItemTag(TAG_LOGS);
TagLocation<Block> tagBlockLog = new TagLocation<>(getBlockTag(TAG_LOGS).getName());
TagLocation<Item> tagItemLog = new TagLocation<>(getItemTag(TAG_LOGS).getName());
addBlockEntry(
new BlockEntry(BLOCK_STRIPPED_LOG, (complexMaterial, settings) -> {
return new BaseRotatedPillarBlock(settings);
})
.setBlockTags(BlockTags.LOGS, BlockTags.LOGS_THAT_BURN, tagBlockLog)
.setItemTags(ItemTags.LOGS, ItemTags.LOGS_THAT_BURN, tagItemLog)
new BlockEntry(BLOCK_STRIPPED_LOG, (complexMaterial, settings) -> new BaseRotatedPillarBlock(settings))
.setBlockTags(TagAPI.NAMED_BLOCK_LOGS, TagAPI.NAMED_BLOCK_LOGS_THAT_BURN, tagBlockLog)
.setItemTags(TagAPI.NAMED_ITEM_LOGS, TagAPI.NAMED_ITEM_LOGS_THAT_BURN, tagItemLog)
);
addBlockEntry(
new BlockEntry(BLOCK_STRIPPED_BARK, (complexMaterial, settings) -> {
return new BaseBarkBlock(settings);
})
.setBlockTags(BlockTags.LOGS, BlockTags.LOGS_THAT_BURN, tagBlockLog)
.setItemTags(ItemTags.LOGS, ItemTags.LOGS_THAT_BURN, tagItemLog)
new BlockEntry(BLOCK_STRIPPED_BARK, (complexMaterial, settings) -> new BaseBarkBlock(settings))
.setBlockTags(TagAPI.NAMED_BLOCK_LOGS, TagAPI.NAMED_BLOCK_LOGS_THAT_BURN, tagBlockLog)
.setItemTags(TagAPI.NAMED_ITEM_LOGS, TagAPI.NAMED_ITEM_LOGS_THAT_BURN, tagItemLog)
);
addBlockEntry(
new BlockEntry(BLOCK_LOG, (complexMaterial, settings) -> {
return new BaseStripableLogBlock(woodColor, getBlock(BLOCK_STRIPPED_LOG));
})
.setBlockTags(BlockTags.LOGS, BlockTags.LOGS_THAT_BURN, tagBlockLog)
.setItemTags(ItemTags.LOGS, ItemTags.LOGS_THAT_BURN, tagItemLog)
new BlockEntry(BLOCK_LOG, (complexMaterial, settings) -> new BaseStripableLogBlock(woodColor, getBlock(BLOCK_STRIPPED_LOG)))
.setBlockTags(TagAPI.NAMED_BLOCK_LOGS, TagAPI.NAMED_BLOCK_LOGS_THAT_BURN, tagBlockLog)
.setItemTags(TagAPI.NAMED_ITEM_LOGS, TagAPI.NAMED_ITEM_LOGS_THAT_BURN, tagItemLog)
);
addBlockEntry(
new BlockEntry(BLOCK_BARK, (complexMaterial, settings) -> {
return new StripableBarkBlock(woodColor, getBlock(BLOCK_STRIPPED_BARK));
})
.setBlockTags(BlockTags.LOGS, BlockTags.LOGS_THAT_BURN, tagBlockLog)
.setItemTags(ItemTags.LOGS, ItemTags.LOGS_THAT_BURN, tagItemLog)
new BlockEntry(BLOCK_BARK, (complexMaterial, settings) -> new StripableBarkBlock(woodColor, getBlock(BLOCK_STRIPPED_BARK)))
.setBlockTags(TagAPI.NAMED_BLOCK_LOGS, TagAPI.NAMED_BLOCK_LOGS_THAT_BURN, tagBlockLog)
.setItemTags(TagAPI.NAMED_ITEM_LOGS, TagAPI.NAMED_ITEM_LOGS_THAT_BURN, tagItemLog)
);
addBlockEntry(new BlockEntry(BLOCK_PLANKS, (complexMaterial, settings) -> {
return new BaseBlock(settings);
}).setBlockTags(BlockTags.PLANKS)
.setItemTags(ItemTags.PLANKS));
addBlockEntry(new BlockEntry(BLOCK_STAIRS, (complexMaterial, settings) -> {
return new BaseStairsBlock(getBlock(BLOCK_PLANKS));
}).setBlockTags(BlockTags.WOODEN_STAIRS, BlockTags.STAIRS)
.setItemTags(ItemTags.WOODEN_STAIRS, ItemTags.STAIRS));
addBlockEntry(new BlockEntry(BLOCK_SLAB, (complexMaterial, settings) -> {
return new BaseSlabBlock(getBlock(BLOCK_PLANKS));
}).setBlockTags(BlockTags.WOODEN_SLABS, BlockTags.SLABS)
.setItemTags(ItemTags.WOODEN_SLABS, ItemTags.SLABS));
addBlockEntry(new BlockEntry(BLOCK_FENCE, (complexMaterial, settings) -> {
return new BaseFenceBlock(getBlock(BLOCK_PLANKS));
}).setBlockTags(BlockTags.FENCES, BlockTags.WOODEN_FENCES)
.setItemTags(ItemTags.FENCES, ItemTags.WOODEN_FENCES));
addBlockEntry(new BlockEntry(BLOCK_GATE, (complexMaterial, settings) -> {
return new BaseGateBlock(getBlock(BLOCK_PLANKS));
}).setBlockTags(BlockTags.FENCE_GATES));
addBlockEntry(new BlockEntry(BLOCK_BUTTON, (complexMaterial, settings) -> {
return new BaseWoodenButtonBlock(getBlock(BLOCK_PLANKS));
}).setBlockTags(BlockTags.BUTTONS, BlockTags.WOODEN_BUTTONS)
.setItemTags(ItemTags.BUTTONS, ItemTags.WOODEN_BUTTONS));
addBlockEntry(new BlockEntry(BLOCK_PRESSURE_PLATE, (complexMaterial, settings) -> {
return new WoodenPressurePlateBlock(getBlock(BLOCK_PLANKS));
}).setBlockTags(BlockTags.PRESSURE_PLATES, BlockTags.WOODEN_PRESSURE_PLATES)
.setItemTags(ItemTags.WOODEN_PRESSURE_PLATES));
addBlockEntry(new BlockEntry(BLOCK_TRAPDOOR, (complexMaterial, settings) -> {
return new BaseTrapdoorBlock(getBlock(BLOCK_PLANKS));
}).setBlockTags(BlockTags.TRAPDOORS, BlockTags.WOODEN_TRAPDOORS)
.setItemTags(ItemTags.TRAPDOORS, ItemTags.WOODEN_TRAPDOORS));
addBlockEntry(new BlockEntry(BLOCK_DOOR, (complexMaterial, settings) -> {
return new BaseDoorBlock(getBlock(BLOCK_PLANKS));
}).setBlockTags(BlockTags.DOORS, BlockTags.WOODEN_DOORS)
.setItemTags(ItemTags.DOORS, ItemTags.WOODEN_DOORS));
addBlockEntry(new BlockEntry(BLOCK_LADDER, (complexMaterial, settings) -> {
return new BaseLadderBlock(getBlock(BLOCK_PLANKS));
}).setBlockTags(BlockTags.CLIMBABLE));
addBlockEntry(new BlockEntry(BLOCK_SIGN, (complexMaterial, settings) -> {
return new BaseSignBlock(getBlock(BLOCK_PLANKS));
}).setBlockTags(BlockTags.SIGNS)
.setItemTags(ItemTags.SIGNS));
addBlockEntry(new BlockEntry(BLOCK_PLANKS, (complexMaterial, settings) -> new BaseBlock(settings))
.setBlockTags(TagAPI.NAMED_BLOCK_PLANKS)
.setItemTags(TagAPI.NAMED_ITEM_PLANKS));
addBlockEntry(new BlockEntry(BLOCK_STAIRS, (complexMaterial, settings) -> new BaseStairsBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(TagAPI.NAMED_BLOCK_WOODEN_STAIRS, TagAPI.NAMED_BLOCK_STAIRS)
.setItemTags(TagAPI.NAMED_ITEM_WOODEN_STAIRS, TagAPI.NAMED_ITEM_STAIRS));
addBlockEntry(new BlockEntry(BLOCK_SLAB, (complexMaterial, settings) -> new BaseSlabBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(TagAPI.NAMED_BLOCK_WOODEN_SLABS, TagAPI.NAMED_BLOCK_SLABS)
.setItemTags(TagAPI.NAMED_ITEM_WOODEN_SLABS, TagAPI.NAMED_ITEM_SLABS));
addBlockEntry(new BlockEntry(BLOCK_FENCE, (complexMaterial, settings) -> new BaseFenceBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(TagAPI.NAMED_BLOCK_FENCES, TagAPI.NAMED_BLOCK_WOODEN_FENCES)
.setItemTags(TagAPI.NAMED_ITEM_FENCES, TagAPI.NAMED_ITEM_WOODEN_FENCES));
addBlockEntry(new BlockEntry(BLOCK_GATE, (complexMaterial, settings) -> new BaseGateBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(TagAPI.NAMED_BLOCK_FENCE_GATES));
addBlockEntry(new BlockEntry(BLOCK_BUTTON, (complexMaterial, settings) -> new BaseWoodenButtonBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(TagAPI.NAMED_BLOCK_BUTTONS, TagAPI.NAMED_BLOCK_WOODEN_BUTTONS)
.setItemTags(TagAPI.NAMED_ITEM_BUTTONS, TagAPI.NAMED_ITEM_WOODEN_BUTTONS));
addBlockEntry(new BlockEntry(BLOCK_PRESSURE_PLATE, (complexMaterial, settings) -> new WoodenPressurePlateBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(TagAPI.NAMED_BLOCK_PRESSURE_PLATES, TagAPI.NAMED_BLOCK_WOODEN_PRESSURE_PLATES)
.setItemTags(TagAPI.NAMED_ITEM_WOODEN_PRESSURE_PLATES));
addBlockEntry(new BlockEntry(BLOCK_TRAPDOOR, (complexMaterial, settings) -> new BaseTrapdoorBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(TagAPI.NAMED_BLOCK_TRAPDOORS, TagAPI.NAMED_BLOCK_WOODEN_TRAPDOORS)
.setItemTags(TagAPI.NAMED_ITEM_TRAPDOORS, TagAPI.NAMED_ITEM_WOODEN_TRAPDOORS));
addBlockEntry(new BlockEntry(BLOCK_DOOR, (complexMaterial, settings) -> new BaseDoorBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(TagAPI.NAMED_BLOCK_DOORS, TagAPI.NAMED_BLOCK_WOODEN_DOORS)
.setItemTags(TagAPI.NAMED_ITEM_DOORS, TagAPI.NAMED_ITEM_WOODEN_DOORS));
addBlockEntry(new BlockEntry(BLOCK_LADDER, (complexMaterial, settings) -> new BaseLadderBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(TagAPI.NAMED_BLOCK_CLIMBABLE));
addBlockEntry(new BlockEntry(BLOCK_SIGN, (complexMaterial, settings) -> new BaseSignBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(TagAPI.NAMED_BLOCK_SIGNS)
.setItemTags(TagAPI.NAMED_ITEM_SIGNS));
}
final protected void initStorage(FabricBlockSettings blockSettings, FabricItemSettings itemSettings) {
addBlockEntry(new BlockEntry(BLOCK_CHEST, (complexMaterial, settings) -> {
return new BaseChestBlock(getBlock(BLOCK_PLANKS));
}).setBlockTags(TagAPI.BLOCK_CHEST, TagAPI.BLOCK_WOODEN_CHEST)
.setItemTags(TagAPI.ITEM_CHEST, TagAPI.ITEM_WOODEN_CHEST));
addBlockEntry(new BlockEntry(BLOCK_CHEST, (complexMaterial, settings) -> new BaseChestBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(TagAPI.NAMED_COMMON_BLOCK_CHEST, TagAPI.NAMED_COMMON_BLOCK_WOODEN_CHEST)
.setItemTags(TagAPI.NAMED_COMMON_ITEM_CHEST, TagAPI.NAMED_COMMON_ITEM_WOODEN_CHEST));
addBlockEntry(new BlockEntry(BLOCK_BARREL, (complexMaterial, settings) -> {
return new BaseBarrelBlock(getBlock(BLOCK_PLANKS));
}).setBlockTags(TagAPI.BLOCK_BARREL, TagAPI.BLOCK_WOODEN_BARREL)
.setItemTags(TagAPI.ITEM_BARREL, TagAPI.ITEM_WOODEN_BARREL));
addBlockEntry(new BlockEntry(BLOCK_BARREL, (complexMaterial, settings) -> new BaseBarrelBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(TagAPI.NAMED_COMMON_BLOCK_BARREL, TagAPI.NAMED_COMMON_BLOCK_WOODEN_BARREL)
.setItemTags(TagAPI.NAMED_COMMON_ITEM_BARREL, TagAPI.NAMED_COMMON_ITEM_WOODEN_BARREL));
}
final protected void initDecorations(FabricBlockSettings blockSettings, FabricItemSettings itemSettings) {
addBlockEntry(new BlockEntry(BLOCK_CRAFTING_TABLE, (complexMaterial, settings) -> {
return new BaseCraftingTableBlock(getBlock(BLOCK_PLANKS));
}).setBlockTags(TagAPI.BLOCK_WORKBENCHES)
.setItemTags(TagAPI.ITEM_WORKBENCHES));
addBlockEntry(new BlockEntry(BLOCK_CRAFTING_TABLE, (complexMaterial, settings) -> new BaseCraftingTableBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(TagAPI.NAMED_COMMON_BLOCK_WORKBENCHES)
.setItemTags(TagAPI.NAMED_COMMON_ITEM_WORKBENCHES));
addBlockEntry(new BlockEntry(BLOCK_BOOKSHELF, (complexMaterial, settings) -> {
return new BaseBookshelfBlock(getBlock(BLOCK_PLANKS));
}).setBlockTags(TagAPI.BLOCK_BOOKSHELVES));
addBlockEntry(new BlockEntry(BLOCK_BOOKSHELF, (complexMaterial, settings) -> new BaseBookshelfBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(TagAPI.NAMED_COMMON_BLOCK_BOOKSHELVES));
addBlockEntry(new BlockEntry(BLOCK_COMPOSTER, (complexMaterial, settings) -> {
return new BaseComposterBlock(getBlock(BLOCK_PLANKS));
}));
addBlockEntry(new BlockEntry(BLOCK_COMPOSTER, (complexMaterial, settings) -> new BaseComposterBlock(getBlock(BLOCK_PLANKS))));
}
@Override

View file

@ -2,10 +2,10 @@ package ru.bclib.complexmaterials.entry;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import ru.bclib.api.TagAPI;
import ru.bclib.api.TagAPI.TagLocation;
import ru.bclib.complexmaterials.ComplexMaterial;
import ru.bclib.registry.BlockRegistry;
@ -15,8 +15,8 @@ public class BlockEntry extends ComplexMaterialEntry {
final BiFunction<ComplexMaterial, FabricBlockSettings, Block> initFunction;
final boolean hasItem;
Tag.Named<Block>[] blockTags;
Tag.Named<Item>[] itemTags;
TagLocation<Block>[] blockTags;
TagLocation<Item>[] itemTags;
public BlockEntry(String suffix, BiFunction<ComplexMaterial, FabricBlockSettings, Block> initFunction) {
this(suffix, true, initFunction);
@ -28,12 +28,12 @@ public class BlockEntry extends ComplexMaterialEntry {
this.hasItem = hasItem;
}
public BlockEntry setBlockTags(Tag.Named<Block>... blockTags) {
public BlockEntry setBlockTags(TagLocation<Block>... blockTags) {
this.blockTags = blockTags;
return this;
}
public BlockEntry setItemTags(Tag.Named<Item>... itemTags) {
public BlockEntry setItemTags(TagLocation<Item>... itemTags) {
this.itemTags = itemTags;
return this;
}
@ -44,14 +44,14 @@ public class BlockEntry extends ComplexMaterialEntry {
if (hasItem) {
registry.register(location, block);
if (itemTags != null) {
TagAPI.addTags(block, itemTags);
TagAPI.addItemTags(block, itemTags);
}
}
else {
registry.registerBlockOnly(location, block);
}
if (blockTags != null) {
TagAPI.addTags(block, blockTags);
TagAPI.addBlockTags(block, blockTags);
}
return block;
}

View file

@ -2,9 +2,9 @@ package ru.bclib.complexmaterials.entry;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.world.item.Item;
import ru.bclib.api.TagAPI;
import ru.bclib.api.TagAPI.TagLocation;
import ru.bclib.complexmaterials.ComplexMaterial;
import ru.bclib.registry.ItemRegistry;
@ -13,14 +13,14 @@ import java.util.function.BiFunction;
public class ItemEntry extends ComplexMaterialEntry {
final BiFunction<ComplexMaterial, FabricItemSettings, Item> initFunction;
Tag.Named<Item>[] itemTags;
TagLocation<Item>[] itemTags;
public ItemEntry(String suffix, BiFunction<ComplexMaterial, FabricItemSettings, Item> initFunction) {
super(suffix);
this.initFunction = initFunction;
}
public ItemEntry setItemTags(Tag.Named<Item>[] itemTags) {
public ItemEntry setItemTags(TagLocation<Item>[] itemTags) {
this.itemTags = itemTags;
return this;
}
@ -30,7 +30,7 @@ public class ItemEntry extends ComplexMaterialEntry {
Item item = initFunction.apply(material, itemSettings);
registry.register(location, item);
if (itemTags != null) {
TagAPI.addTags(item, itemTags);
TagAPI.addItemTags(item, itemTags);
}
return item;
}