Skip to content

Commit cc13697

Browse files
committed
Fix battery upgrade (Closes #1)
1 parent 2b7d0d1 commit cc13697

File tree

12 files changed

+62
-43
lines changed

12 files changed

+62
-43
lines changed

src/generated/resources/data/constructionstick/recipe/smithing_upgrade/copper_stick_with_template_battery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"result": {
1010
"components": {
11-
"constructionstick:battery": 0
11+
"constructionstick:battery_enabled": true
1212
},
1313
"count": 1,
1414
"id": "constructionstick:copper_stick"

src/generated/resources/data/constructionstick/recipe/smithing_upgrade/diamond_stick_with_template_battery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"result": {
1010
"components": {
11-
"constructionstick:battery": 0
11+
"constructionstick:battery_enabled": true
1212
},
1313
"count": 1,
1414
"id": "constructionstick:diamond_stick"

src/generated/resources/data/constructionstick/recipe/smithing_upgrade/iron_stick_with_template_battery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"result": {
1010
"components": {
11-
"constructionstick:battery": 0
11+
"constructionstick:battery_enabled": true
1212
},
1313
"count": 1,
1414
"id": "constructionstick:iron_stick"

src/generated/resources/data/constructionstick/recipe/smithing_upgrade/netherite_stick_with_template_battery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"result": {
1010
"components": {
11-
"constructionstick:battery": 0
11+
"constructionstick:battery_enabled": true
1212
},
1313
"count": 1,
1414
"id": "constructionstick:netherite_stick"

src/generated/resources/data/constructionstick/recipe/smithing_upgrade/wooden_stick_with_template_battery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"result": {
1010
"components": {
11-
"constructionstick:battery": 0
11+
"constructionstick:battery_enabled": true
1212
},
1313
"count": 1,
1414
"id": "constructionstick:wooden_stick"

src/main/java/mrbysco/constructionstick/data/server/RecipeGenerator.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package mrbysco.constructionstick.data.server;
22

3+
import mrbysco.constructionstick.data.server.recipe.IngredientPredicate;
34
import mrbysco.constructionstick.data.server.recipe.SmithingApplyUpgradeRecipeBuilder;
45
import mrbysco.constructionstick.items.stick.ItemStick;
56
import mrbysco.constructionstick.items.template.ItemUpgradeTemplate;
@@ -30,22 +31,22 @@ public RecipeGenerator(PackOutput packOutput, CompletableFuture<HolderLookup.Pro
3031

3132
@Override
3233
protected void buildRecipes(RecipeOutput output, HolderLookup.Provider provider) {
33-
stickRecipe(output, ModItems.STICK_WOODEN.get(), Inp.fromTag(Tags.Items.RODS_WOODEN));
34-
stickRecipe(output, ModItems.STICK_COPPER.get(), Inp.fromTag(ItemTags.STONE_TOOL_MATERIALS));
35-
stickRecipe(output, ModItems.STICK_IRON.get(), Inp.fromTag(Tags.Items.INGOTS_IRON));
36-
stickRecipe(output, ModItems.STICK_DIAMOND.get(), Inp.fromTag(Tags.Items.GEMS_DIAMOND));
37-
stickRecipe(output, ModItems.STICK_NETHERITE.get(), Inp.fromTag(Tags.Items.INGOTS_NETHERITE));
34+
stickRecipe(output, ModItems.STICK_WOODEN.get(), IngredientPredicate.fromTag(Tags.Items.RODS_WOODEN));
35+
stickRecipe(output, ModItems.STICK_COPPER.get(), IngredientPredicate.fromTag(ItemTags.STONE_TOOL_MATERIALS));
36+
stickRecipe(output, ModItems.STICK_IRON.get(), IngredientPredicate.fromTag(Tags.Items.INGOTS_IRON));
37+
stickRecipe(output, ModItems.STICK_DIAMOND.get(), IngredientPredicate.fromTag(Tags.Items.GEMS_DIAMOND));
38+
stickRecipe(output, ModItems.STICK_NETHERITE.get(), IngredientPredicate.fromTag(Tags.Items.INGOTS_NETHERITE));
3839

39-
templateRecipe(output, ModItems.TEMPLATE_ANGEL.get(), Inp.fromTag(Tags.Items.FEATHERS), Inp.fromTag(Tags.Items.INGOTS_GOLD));
40-
templateRecipe(output, ModItems.TEMPLATE_DESTRUCTION.get(), Inp.fromItem(Items.TNT), Inp.fromItem(Items.DIAMOND_PICKAXE));
40+
templateRecipe(output, ModItems.TEMPLATE_ANGEL.get(), IngredientPredicate.fromTag(Tags.Items.FEATHERS), IngredientPredicate.fromTag(Tags.Items.INGOTS_GOLD));
41+
templateRecipe(output, ModItems.TEMPLATE_DESTRUCTION.get(), IngredientPredicate.fromItem(Items.TNT), IngredientPredicate.fromItem(Items.DIAMOND_PICKAXE));
4142

42-
templateUpgradeRecipe(output, ModItems.TEMPLATE_ANGEL, Inp.fromTag(Tags.Items.FEATHERS), ModDataComponents.ANGEL, true);
43-
templateUpgradeRecipe(output, ModItems.TEMPLATE_DESTRUCTION, Inp.fromTag(Tags.Items.STORAGE_BLOCKS_REDSTONE), ModDataComponents.DESTRUCTION, true);
44-
templateUpgradeRecipe(output, ModItems.TEMPLATE_UNBREAKABLE, Inp.fromTag(Tags.Items.OBSIDIANS_CRYING), ModDataComponents.UNBREAKABLE, true);
45-
templateUpgradeRecipe(output, ModItems.TEMPLATE_BATTERY, Inp.fromTag(Tags.Items.STORAGE_BLOCKS_COPPER), ModDataComponents.BATTERY, 0);
43+
templateUpgradeRecipe(output, ModItems.TEMPLATE_ANGEL, IngredientPredicate.fromTag(Tags.Items.FEATHERS), ModDataComponents.ANGEL, true);
44+
templateUpgradeRecipe(output, ModItems.TEMPLATE_DESTRUCTION, IngredientPredicate.fromTag(Tags.Items.STORAGE_BLOCKS_REDSTONE), ModDataComponents.DESTRUCTION, true);
45+
templateUpgradeRecipe(output, ModItems.TEMPLATE_UNBREAKABLE, IngredientPredicate.fromTag(Tags.Items.OBSIDIANS_CRYING), ModDataComponents.UNBREAKABLE, true);
46+
templateUpgradeRecipe(output, ModItems.TEMPLATE_BATTERY, IngredientPredicate.fromTag(Tags.Items.STORAGE_BLOCKS_COPPER), ModDataComponents.BATTERY_ENABLED, true);
4647
}
4748

48-
private void stickRecipe(RecipeOutput output, ItemLike stick, Inp material) {
49+
private void stickRecipe(RecipeOutput output, ItemLike stick, IngredientPredicate material) {
4950
ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, stick)
5051
.define('X', material.ingredient())
5152
.define('#', Tags.Items.RODS_WOODEN)
@@ -57,7 +58,7 @@ private void stickRecipe(RecipeOutput output, ItemLike stick, Inp material) {
5758
}
5859

5960
private <T> void templateUpgradeRecipe(RecipeOutput output, DeferredItem<? extends ItemUpgradeTemplate> template,
60-
Inp item1, Supplier<DataComponentType<T>> component, T defaultValue) {
61+
IngredientPredicate item1, Supplier<DataComponentType<T>> component, T defaultValue) {
6162
for (DeferredItem<? extends ItemStick> stickHolder : ModItems.STICKS) {
6263
ItemStack stack = stickHolder.toStack();
6364
stack.set(component, defaultValue);
@@ -71,7 +72,7 @@ private <T> void templateUpgradeRecipe(RecipeOutput output, DeferredItem<? exten
7172

7273
}
7374

74-
private void templateRecipe(RecipeOutput output, ItemLike template, Inp item1, Inp item2) {
75+
private void templateRecipe(RecipeOutput output, ItemLike template, IngredientPredicate item1, IngredientPredicate item2) {
7576
ShapedRecipeBuilder.shaped(RecipeCategory.MISC, template)
7677
.define('O', item1.ingredient())
7778
.define('X', item2.ingredient())
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package mrbysco.constructionstick.data.server.recipe;
2+
3+
import net.minecraft.advancements.critereon.ItemPredicate;
4+
import net.minecraft.tags.TagKey;
5+
import net.minecraft.world.item.Item;
6+
import net.minecraft.world.item.crafting.Ingredient;
7+
import net.minecraft.world.level.ItemLike;
8+
9+
public record IngredientPredicate(Ingredient ingredient, ItemPredicate predicate) {
10+
11+
public static IngredientPredicate fromItem(ItemLike in) {
12+
return new IngredientPredicate(Ingredient.of(in), ItemPredicate.Builder.item().of(in).build());
13+
}
14+
15+
public static IngredientPredicate fromTag(TagKey<Item> in) {
16+
return new IngredientPredicate(Ingredient.of(in), ItemPredicate.Builder.item().of(in).build());
17+
}
18+
}

src/main/java/mrbysco/constructionstick/data/server/recipe/Inp.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/main/java/mrbysco/constructionstick/items/template/ItemBatteryTemplate.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import mrbysco.constructionstick.api.IStickUpgrade;
66
import mrbysco.constructionstick.registry.ModDataComponents;
77
import mrbysco.constructionstick.stick.action.ActionAngel;
8+
import mrbysco.constructionstick.stick.action.ActionConstruction;
89
import net.minecraft.core.component.DataComponentType;
910
import net.minecraft.resources.ResourceLocation;
1011

@@ -17,12 +18,12 @@ public ItemBatteryTemplate(Properties properties) {
1718

1819
@Override
1920
public IStickAction getStickAction() {
20-
return new ActionAngel();
21+
return new ActionConstruction();
2122
}
2223

2324
@Override
24-
public DataComponentType<Integer> getStickComponent() {
25-
return ModDataComponents.BATTERY.get();
25+
public DataComponentType<Boolean> getStickComponent() {
26+
return ModDataComponents.BATTERY_ENABLED.get();
2627
}
2728

2829
@Override

src/main/java/mrbysco/constructionstick/items/template/ItemUnbreakableTemplate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import mrbysco.constructionstick.api.IStickUpgrade;
66
import mrbysco.constructionstick.registry.ModDataComponents;
77
import mrbysco.constructionstick.stick.action.ActionAngel;
8+
import mrbysco.constructionstick.stick.action.ActionConstruction;
89
import net.minecraft.core.component.DataComponentType;
910
import net.minecraft.resources.ResourceLocation;
1011

@@ -17,7 +18,7 @@ public ItemUnbreakableTemplate(Properties properties) {
1718

1819
@Override
1920
public IStickAction getStickAction() {
20-
return new ActionAngel();
21+
return new ActionConstruction();
2122
}
2223

2324
@Override

0 commit comments

Comments
 (0)