|
| 1 | +package motherlode.base.api.varianttypes.ore; |
| 2 | + |
| 3 | +import java.util.function.UnaryOperator; |
| 4 | +import net.minecraft.block.Block; |
| 5 | +import net.minecraft.block.Blocks; |
| 6 | +import net.minecraft.item.Item; |
| 7 | +import net.minecraft.item.ItemGroup; |
| 8 | +import net.minecraft.util.Identifier; |
| 9 | +import motherlode.base.api.Motherlode; |
| 10 | +import motherlode.base.api.Registerable; |
| 11 | +import motherlode.base.api.assets.CommonAssets; |
| 12 | +import motherlode.base.api.assets.CommonData; |
| 13 | +import motherlode.base.api.assets.DataProcessor; |
| 14 | +import motherlode.base.api.varianttype.MotherlodeVariantType; |
| 15 | +import com.swordglowsblue.artifice.api.ArtificeResourcePack; |
| 16 | + |
| 17 | +/** |
| 18 | + * Variant type that adds blocks and items for an overworld ore type. |
| 19 | + */ |
| 20 | +public class OreType extends MotherlodeVariantType<Object, OreType> { |
| 21 | + public static final OreType IRON = new OreType(new Identifier("minecraft", "iron"), Blocks.IRON_ORE, Blocks.DEEPSLATE_IRON_ORE).withoutBase().register(); |
| 22 | + public static final OreType COAL = new OreType(new Identifier("minecraft", "coal"), Blocks.COAL_ORE, Blocks.DEEPSLATE_COAL_ORE, "coal").withoutBase().register(); |
| 23 | + public static final OreType COPPER = new OreType(new Identifier("minecraft", "copper"), Blocks.COPPER_ORE, Blocks.DEEPSLATE_COPPER_ORE).withoutBase().register(); |
| 24 | + public static final OreType GOLD = new OreType(new Identifier("minecraft", "gold"), Blocks.GOLD_ORE, Blocks.DEEPSLATE_GOLD_ORE).withoutBase().register(); |
| 25 | + public static final OreType REDSTONE = new OreType(new Identifier("minecraft", "redstone"), Blocks.REDSTONE_ORE, Blocks.DEEPSLATE_REDSTONE_ORE, "redstone_dust").withoutBase().register(); |
| 26 | + public static final OreType LAPIS_LAZULI = new OreType(new Identifier("minecraft", "lapis_lazuli"), Blocks.LAPIS_ORE, Blocks.DEEPSLATE_LAPIS_ORE, "lapis_lazuli").withoutBase().register(); |
| 27 | + public static final OreType DIAMOND = new OreType(new Identifier("minecraft", "diamond"), Blocks.DIAMOND_ORE, Blocks.DEEPSLATE_DIAMOND_ORE, "diamond").withoutBase().register(); |
| 28 | + |
| 29 | + private final Block stoneOreBlock; |
| 30 | + private final Block deepslateOreBlock; |
| 31 | + private Item material; |
| 32 | + |
| 33 | + private final String materialName; |
| 34 | + |
| 35 | + public OreType(Identifier id, Block stoneOreBlock, Block deepslateOreBlock, String materialName) { |
| 36 | + super(id); |
| 37 | + this.materialName = materialName; |
| 38 | + |
| 39 | + this.stoneOreBlock = stoneOreBlock; |
| 40 | + this.deepslateOreBlock = deepslateOreBlock; |
| 41 | + } |
| 42 | + |
| 43 | + public OreType(Identifier id, Block stoneOreBlock, Block deepslateOreBlock) { |
| 44 | + this(id, stoneOreBlock, deepslateOreBlock, id.getPath() + "_ingot"); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + protected OreType getThis() { |
| 49 | + return this; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + protected void registerBase(Identifier id) { |
| 54 | + this.material = new Item(new Item.Settings().group(ItemGroup.MATERIALS)); |
| 55 | + |
| 56 | + registerBlock(this.stoneOreBlock, ItemGroup.BUILDING_BLOCKS, this.getBaseId(), name -> name + "_ore"); |
| 57 | + registerBlock(this.deepslateOreBlock, ItemGroup.BUILDING_BLOCKS, this.getBaseId(), name -> "deepslate_" + name + "_ore"); |
| 58 | + Registerable.item(this.material).register(Motherlode.id(this.getBaseId(), name -> this.materialName)); |
| 59 | + } |
| 60 | + |
| 61 | + private static void registerBlock(Block block, ItemGroup group, Identifier baseId, UnaryOperator<String> path) { |
| 62 | + Registerable.block(block, group).register(Motherlode.id(baseId, path)); |
| 63 | + } |
| 64 | + |
| 65 | + public Block getStoneOreBlock() { |
| 66 | + return this.stoneOreBlock; |
| 67 | + } |
| 68 | + |
| 69 | + public Block getDeepslateOreBlock() { |
| 70 | + return this.deepslateOreBlock; |
| 71 | + } |
| 72 | + |
| 73 | + public Item getMaterial() { |
| 74 | + return this.material; |
| 75 | + } |
| 76 | + |
| 77 | + public String getMaterialName() { |
| 78 | + return this.materialName; |
| 79 | + } |
| 80 | + |
| 81 | + public OreType withRawOres() { |
| 82 | + return this.with(new RawOreExtension()); |
| 83 | + } |
| 84 | + |
| 85 | + public OreType oresDropMineral() { |
| 86 | + return this.with(new OreDropsExtension(OreDropsExtension.Drop.MINERAL)); |
| 87 | + } |
| 88 | + |
| 89 | + public OreType oresDropThemselves() { |
| 90 | + return this.with(new OreDropsExtension(OreDropsExtension.Drop.THEMSELVES)); |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + protected Object[] baseVariants() { |
| 95 | + return new Object[] { this.stoneOreBlock, this.deepslateOreBlock, this.material }; |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public void accept(ArtificeResourcePack.ClientResourcePackBuilder pack, Identifier id) { |
| 100 | + CommonAssets.DEFAULT_BLOCK.accept(pack, Motherlode.id(id, name -> name + "_ore")); |
| 101 | + CommonAssets.DEFAULT_BLOCK.accept(pack, Motherlode.id(id, name -> "deepslate_" + name + "_ore")); |
| 102 | + CommonAssets.DEFAULT_ITEM_MODEL.accept(pack, Motherlode.id(this.getBaseId(), name -> this.materialName)); |
| 103 | + } |
| 104 | + |
| 105 | + @Override |
| 106 | + public void accept(ArtificeResourcePack.ServerResourcePackBuilder pack, Identifier id) { |
| 107 | + Identifier oresTagId = new Identifier(CommonData.COMMON_NAMESPACE, id.getPath() + "_ores"); |
| 108 | + Identifier stoneOreId = Motherlode.id(id, name -> name + "_ore"); |
| 109 | + Identifier deepslateOreId = Motherlode.id(id, name -> "deepslate_" + name + "_ore"); |
| 110 | + |
| 111 | + CommonData.BLOCK_TAG.apply(oresTagId).accept(pack, stoneOreId); |
| 112 | + CommonData.BLOCK_TAG.apply(oresTagId).accept(pack, deepslateOreId); |
| 113 | + |
| 114 | + if (this.stoneOreBlock instanceof DataProcessor) |
| 115 | + ((DataProcessor) this.stoneOreBlock).accept(pack, stoneOreId); |
| 116 | + if (this.deepslateOreBlock instanceof DataProcessor) |
| 117 | + ((DataProcessor) this.deepslateOreBlock).accept(pack, deepslateOreId); |
| 118 | + } |
| 119 | + |
| 120 | + @Override |
| 121 | + protected void registerOnClient(Identifier id) { |
| 122 | + } |
| 123 | +} |
0 commit comments