Skip to content

Commit 6884897

Browse files
authored
Merge pull request #1 from mschae23/ore-variants
Ore types
2 parents 68ccc0a + a890e29 commit 6884897

File tree

11 files changed

+1016
-678
lines changed

11 files changed

+1016
-678
lines changed

src/main/java/motherlode/base/api/varianttype/AbstractExtendableVariantType.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.function.BooleanSupplier;
88
import java.util.function.Supplier;
99
import net.minecraft.util.Identifier;
10+
import org.jetbrains.annotations.ApiStatus;
1011

1112
/**
1213
* JavaDoc planned.
@@ -59,7 +60,7 @@ protected Identifier getBaseId() {
5960
@Override
6061
public S register() {
6162
if (!withoutBase) {
62-
this.registerBase(new Identifier(this.baseNamespace, this.name));
63+
this.registerBase();
6364
this.withoutBase();
6465
}
6566

@@ -75,6 +76,11 @@ public S register() {
7576
return getThis();
7677
}
7778

79+
@ApiStatus.OverrideOnly
80+
protected void registerBase() {
81+
this.registerBase(new Identifier(this.baseNamespace, this.name));
82+
}
83+
7884
@Override
7985
public S withoutBase() {
8086
this.withoutBase = true;

src/main/java/motherlode/base/api/varianttype/MotherlodeVariantType.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,18 @@ public MotherlodeVariantType(Identifier id) {
2222
protected abstract void registerOnClient(Identifier id);
2323

2424
@Override
25-
public S register() {
26-
if (!this.isWithoutBase()) {
27-
Motherlode.getAssetsManager().addAssets(this.getBaseId(), this);
28-
Motherlode.getAssetsManager().addData(this.getBaseId(), this);
29-
Motherlode.registerOnClient(this.getBaseId(), this::registerOnClient);
30-
}
31-
32-
return super.register();
25+
protected void registerBase() {
26+
super.registerBase();
27+
Motherlode.getAssetsManager().addAssets(this.getBaseId(), this);
28+
Motherlode.getAssetsManager().addData(this.getBaseId(), this);
29+
Motherlode.registerOnClient(this.getBaseId(), this::registerOnClient);
3330
}
3431

3532
@Deprecated
3633
public static <T, S extends AbstractExtendableVariantType<T, S>> S extend(S variantType, String namespace) {
3734
return AbstractExtendableVariantType.extend(variantType, namespace);
3835
}
3936

40-
@Deprecated
4137
public static <T, S extends AbstractExtendableVariantType<T, S>, E extends ExtendableVariantType.Extension<T, S>> E extend(S variantType, String namespace, E extension) {
4238
return AbstractExtendableVariantType.extend(variantType, namespace, extension);
4339
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package motherlode.base.api.varianttypes.ore;
2+
3+
import net.minecraft.util.Identifier;
4+
import motherlode.base.api.Motherlode;
5+
import motherlode.base.api.assets.CommonData;
6+
import motherlode.base.api.varianttype.MotherlodeVariantType;
7+
import com.swordglowsblue.artifice.api.ArtificeResourcePack;
8+
import com.swordglowsblue.artifice.api.builder.TypedJsonBuilder;
9+
10+
public class OreDropsExtension implements MotherlodeVariantType.Extension<Object, OreType> {
11+
private final Drop drop;
12+
private String materialName;
13+
14+
public OreDropsExtension(Drop drop) {
15+
this.drop = drop;
16+
}
17+
18+
@Override
19+
public void registerExtension(Identifier id, OreType oreType) {
20+
this.materialName = oreType.getMaterialName();
21+
}
22+
23+
@Override
24+
public void accept(ArtificeResourcePack.ClientResourcePackBuilder pack, Identifier id) {
25+
}
26+
27+
@Override
28+
public void accept(ArtificeResourcePack.ServerResourcePackBuilder pack, Identifier id) {
29+
Identifier oresTagId = new Identifier(CommonData.COMMON_NAMESPACE, id.getPath() + "_ores");
30+
Identifier stoneOreId = Motherlode.id(id, name -> name + "_ore");
31+
Identifier deepslateOreId = Motherlode.id(id, name -> "deepslate_" + name + "_ore");
32+
Identifier mineralId = new Identifier(id.getNamespace(), this.materialName);
33+
34+
pack.addLootTable(stoneOreId, table -> table
35+
.type(new Identifier("minecraft", "block"))
36+
.pool(pool -> pool
37+
.rolls(1)
38+
.entry(entry -> entry
39+
.type(new Identifier("minecraft", "item"))
40+
.name(this.drop.choose(mineralId, stoneOreId))
41+
)
42+
.condition(new Identifier("minecraft", "survives_explosion"), TypedJsonBuilder::build)
43+
)
44+
);
45+
46+
pack.addLootTable(deepslateOreId, table -> table
47+
.type(new Identifier("minecraft", "block"))
48+
.pool(pool -> pool
49+
.rolls(1)
50+
.entry(entry -> entry
51+
.type(new Identifier("minecraft", "item"))
52+
.name(this.drop.choose(mineralId, deepslateOreId))
53+
)
54+
.condition(new Identifier("minecraft", "survives_explosion"), TypedJsonBuilder::build)
55+
)
56+
);
57+
58+
pack.addSmeltingRecipe(Motherlode.id(id, name -> this.materialName + "_smelting"), recipe -> recipe
59+
.ingredientTag(oresTagId)
60+
.result(new Identifier(id.getNamespace(), this.materialName))
61+
.experience(1)
62+
.cookingTime(200)
63+
);
64+
65+
pack.addBlastingRecipe(Motherlode.id(id, name -> this.materialName + "_blasting"), recipe -> recipe
66+
.ingredientTag(oresTagId)
67+
.result(new Identifier(id.getNamespace(), this.materialName))
68+
.experience(1)
69+
.cookingTime(100)
70+
);
71+
}
72+
73+
@Override
74+
public void registerOnClient(Identifier id) {
75+
}
76+
77+
@Override
78+
public Object[] variants() {
79+
return new Object[0];
80+
}
81+
82+
enum Drop {
83+
MINERAL, THEMSELVES;
84+
85+
public Identifier choose(Identifier mineralId, Identifier oreId) {
86+
switch (this) {
87+
case MINERAL:
88+
return mineralId;
89+
case THEMSELVES:
90+
return oreId;
91+
}
92+
93+
return oreId;
94+
}
95+
}
96+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package motherlode.base.api.varianttypes.ore;
2+
3+
import net.minecraft.block.Block;
4+
import net.minecraft.block.Material;
5+
import net.minecraft.item.Item;
6+
import net.minecraft.item.ItemGroup;
7+
import net.minecraft.util.Identifier;
8+
import motherlode.base.api.Motherlode;
9+
import motherlode.base.api.Registerable;
10+
import motherlode.base.api.assets.CommonAssets;
11+
import motherlode.base.api.assets.CommonData;
12+
import motherlode.base.api.varianttype.MotherlodeVariantType;
13+
import com.swordglowsblue.artifice.api.ArtificeResourcePack;
14+
import com.swordglowsblue.artifice.api.builder.TypedJsonBuilder;
15+
16+
public class RawOreExtension implements MotherlodeVariantType.Extension<Object, OreType> {
17+
private Item rawOreItem;
18+
private Block rawOreBlock;
19+
private String materialName;
20+
21+
@Override
22+
public void registerExtension(Identifier id, OreType oreType) {
23+
this.rawOreItem = new Item(new Item.Settings().group(ItemGroup.MATERIALS));
24+
this.rawOreBlock = new Block(Block.Settings.of(Material.STONE, oreType.getStoneOreBlock().getDefaultMapColor()).requiresTool().strength(5.0F, 6.0F));
25+
26+
Registerable.item(this.rawOreItem).register(Motherlode.id(id, name -> "raw_" + name));
27+
Registerable.block(this.rawOreBlock, ItemGroup.BUILDING_BLOCKS).register(Motherlode.id(id, name -> "raw_" + name + "_block"));
28+
29+
this.materialName = oreType.getMaterialName();
30+
}
31+
32+
@Override
33+
public void accept(ArtificeResourcePack.ClientResourcePackBuilder pack, Identifier id) {
34+
CommonAssets.DEFAULT_ITEM_MODEL.accept(pack, Motherlode.id(id, name -> "raw_" + name));
35+
CommonAssets.DEFAULT_BLOCK.accept(pack, Motherlode.id(id, name -> "raw_" + name + "_block"));
36+
}
37+
38+
@Override
39+
public void accept(ArtificeResourcePack.ServerResourcePackBuilder pack, Identifier id) {
40+
Identifier rawItemId = Motherlode.id(id, name -> "raw_" + name);
41+
Identifier rawBlockId = Motherlode.id(id, name -> "raw_" + name + "_block");
42+
Identifier stoneOreId = Motherlode.id(id, name -> name + "_ore");
43+
Identifier deepslateOreId = Motherlode.id(id, name -> "deepslate_" + name + "_ore");
44+
45+
CommonData.DEFAULT_BLOCK_LOOT_TABLE.accept(pack, rawBlockId);
46+
47+
pack.addLootTable(stoneOreId, table -> table
48+
.type(new Identifier("minecraft", "block"))
49+
.pool(pool -> pool
50+
.rolls(1)
51+
.entry(entry -> entry
52+
.type(new Identifier("minecraft", "item"))
53+
.name(rawItemId)
54+
)
55+
.condition(new Identifier("minecraft", "survives_explosion"), TypedJsonBuilder::build)
56+
)
57+
);
58+
59+
pack.addLootTable(deepslateOreId, table -> table
60+
.type(new Identifier("minecraft", "block"))
61+
.pool(pool -> pool
62+
.rolls(1)
63+
.entry(entry -> entry
64+
.type(new Identifier("minecraft", "item"))
65+
.name(rawItemId)
66+
)
67+
.condition(new Identifier("minecraft", "survives_explosion"), TypedJsonBuilder::build)
68+
)
69+
);
70+
71+
pack.addShapedRecipe(rawBlockId, recipe -> recipe
72+
.pattern(
73+
"###",
74+
"###",
75+
"###"
76+
)
77+
.ingredientTag('#', new Identifier(CommonData.COMMON_NAMESPACE, id.getPath() + "_ores"))
78+
.result(rawBlockId, 1)
79+
);
80+
81+
pack.addShapelessRecipe(Motherlode.id(rawItemId, name -> name + "_from_block"), recipe -> recipe
82+
.ingredientItem(rawBlockId)
83+
.result(rawItemId, 9)
84+
);
85+
86+
pack.addSmeltingRecipe(Motherlode.id(id, name -> this.materialName + "_from_raw_" + name + "_smelting"), recipe -> recipe
87+
.ingredientTag(rawItemId)
88+
.result(new Identifier(id.getNamespace(), this.materialName))
89+
.experience(1)
90+
.cookingTime(200)
91+
);
92+
93+
pack.addBlastingRecipe(Motherlode.id(id, name -> this.materialName + "_from_raw_" + name + "_blasting"), recipe -> recipe
94+
.ingredientTag(rawItemId)
95+
.result(new Identifier(id.getNamespace(), this.materialName))
96+
.experience(1)
97+
.cookingTime(100)
98+
);
99+
}
100+
101+
@Override
102+
public void registerOnClient(Identifier id) {
103+
}
104+
105+
public Item getRawOreItem() {
106+
return this.rawOreItem;
107+
}
108+
109+
public Block getRawOreBlock() {
110+
return this.rawOreBlock;
111+
}
112+
113+
@Override
114+
public Object[] variants() {
115+
return new Object[] { this.rawOreItem, this.rawOreBlock };
116+
}
117+
}

0 commit comments

Comments
 (0)