Skip to content

Commit

Permalink
Add support for part builder recipes to charge a different pattern an…
Browse files Browse the repository at this point in the history
…d reusable patterns

Could allow gating part builder recipes behind higher tier of patterns. Used by default to make gold patterns reusable (at the cost of more limited button selection)
  • Loading branch information
KnightMiner committed Feb 13, 2022
1 parent 142fa34 commit b8afc70
Show file tree
Hide file tree
Showing 27 changed files with 240 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"type": "tconstruct:part_builder",
"pattern": "tconstruct:broad_axe_head",
"pattern_item": [
{
"tag": "tconstruct:patterns/default"
},
{
"item": "tconstruct:broad_axe_head_cast"
}
],
"cost": 8,
"result": {
"item": "tconstruct:broad_axe_head"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"type": "tconstruct:part_builder",
"pattern": "tconstruct:broad_blade",
"pattern_item": [
{
"tag": "tconstruct:patterns/default"
},
{
"item": "tconstruct:broad_blade_cast"
}
],
"cost": 8,
"result": {
"item": "tconstruct:broad_blade"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"type": "tconstruct:part_builder",
"pattern": "tconstruct:hammer_head",
"pattern_item": [
{
"tag": "tconstruct:patterns/default"
},
{
"item": "tconstruct:hammer_head_cast"
}
],
"cost": 8,
"result": {
"item": "tconstruct:hammer_head"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"type": "tconstruct:part_builder",
"pattern": "tconstruct:large_plate",
"pattern_item": [
{
"tag": "tconstruct:patterns/default"
},
{
"item": "tconstruct:large_plate_cast"
}
],
"cost": 4,
"result": {
"item": "tconstruct:large_plate"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"type": "tconstruct:part_builder",
"pattern": "tconstruct:pick_head",
"pattern_item": [
{
"tag": "tconstruct:patterns/default"
},
{
"item": "tconstruct:pick_head_cast"
}
],
"cost": 2,
"result": {
"item": "tconstruct:pick_head"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"type": "tconstruct:part_builder",
"pattern": "tconstruct:repair_kit",
"pattern_item": [
{
"tag": "tconstruct:patterns/default"
},
{
"item": "tconstruct:repair_kit_cast"
}
],
"cost": 2,
"result": {
"item": "tconstruct:repair_kit"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"type": "tconstruct:part_builder",
"pattern": "tconstruct:round_plate",
"pattern_item": [
{
"tag": "tconstruct:patterns/default"
},
{
"item": "tconstruct:round_plate_cast"
}
],
"cost": 2,
"result": {
"item": "tconstruct:round_plate"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"type": "tconstruct:part_builder",
"pattern": "tconstruct:small_axe_head",
"pattern_item": [
{
"tag": "tconstruct:patterns/default"
},
{
"item": "tconstruct:small_axe_head_cast"
}
],
"cost": 2,
"result": {
"item": "tconstruct:small_axe_head"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"type": "tconstruct:part_builder",
"pattern": "tconstruct:small_blade",
"pattern_item": [
{
"tag": "tconstruct:patterns/default"
},
{
"item": "tconstruct:small_blade_cast"
}
],
"cost": 2,
"result": {
"item": "tconstruct:small_blade"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"type": "tconstruct:part_builder",
"pattern": "tconstruct:tool_binding",
"pattern_item": [
{
"tag": "tconstruct:patterns/default"
},
{
"item": "tconstruct:tool_binding_cast"
}
],
"cost": 1,
"result": {
"item": "tconstruct:tool_binding"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"type": "tconstruct:part_builder",
"pattern": "tconstruct:tool_handle",
"pattern_item": [
{
"tag": "tconstruct:patterns/default"
},
{
"item": "tconstruct:tool_handle_cast"
}
],
"cost": 1,
"result": {
"item": "tconstruct:tool_handle"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"type": "tconstruct:part_builder",
"pattern": "tconstruct:tough_handle",
"pattern_item": [
{
"tag": "tconstruct:patterns/default"
},
{
"item": "tconstruct:tough_handle_cast"
}
],
"cost": 3,
"result": {
"item": "tconstruct:tough_handle"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"#tconstruct:patterns/default",
"#tconstruct:patterns/reusable"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"tconstruct:pattern"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"#tconstruct:casts/gold"
]
}
7 changes: 7 additions & 0 deletions src/main/java/slimeknights/tconstruct/common/TinkerTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ private static void init() {}
/** Items that count as empty in a casting basin */
public static final IOptionalNamedTag<Item> BASIN_EMPTY_CASTS = tag("casts/empty/basin");

/** Items that can be placed in the pattern slot in the part builder */
public static final IOptionalNamedTag<Item> PATTERNS = tag("patterns");
/** Items that work in all basic part builder recipes, when unspecified this tag is used for the input */
public static final IOptionalNamedTag<Item> DEFAULT_PATTERNS = tag("patterns/default");
/** Pattern items that are not consumed in the part builder */
public static final IOptionalNamedTag<Item> REUSABLE_PATTERNS = tag("patterns/reusable");

/** All basic tinkers tanks */
public static final IOptionalNamedTag<Item> SEARED_TANKS = tag("seared_tanks");
public static final IOptionalNamedTag<Item> SCORCHED_TANKS = tag("scorched_tanks");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import slimeknights.tconstruct.shared.TinkerMaterials;
import slimeknights.tconstruct.shared.block.SlimeType;
import slimeknights.tconstruct.smeltery.TinkerSmeltery;
import slimeknights.tconstruct.tables.TinkerTables;
import slimeknights.tconstruct.tools.TinkerModifiers;
import slimeknights.tconstruct.tools.TinkerToolParts;
import slimeknights.tconstruct.tools.TinkerTools;
Expand Down Expand Up @@ -286,6 +287,11 @@ private void addTools() {
.add(Items.OAK_PLANKS, Items.SPRUCE_PLANKS, Items.BIRCH_PLANKS, Items.JUNGLE_PLANKS, Items.DARK_OAK_PLANKS, Items.ACACIA_PLANKS, Items.CRIMSON_PLANKS, Items.WARPED_PLANKS)
.addTag(TinkerTags.Items.SLIMY_PLANKS);
this.tag(TinkerTags.Items.VARIANT_LOGS).addTags(ItemTags.OAK_LOGS, ItemTags.SPRUCE_LOGS, ItemTags.BIRCH_LOGS, ItemTags.JUNGLE_LOGS, ItemTags.DARK_OAK_LOGS, ItemTags.ACACIA_LOGS, ItemTags.CRIMSON_STEMS, ItemTags.WARPED_STEMS, TinkerTags.Items.SLIMY_LOGS);

// part builder
this.tag(TinkerTags.Items.DEFAULT_PATTERNS).add(TinkerTables.pattern.get());
this.tag(TinkerTags.Items.REUSABLE_PATTERNS).addTag(TinkerTags.Items.GOLD_CASTS);
this.tag(TinkerTags.Items.PATTERNS).addTags(TinkerTags.Items.DEFAULT_PATTERNS, TinkerTags.Items.REUSABLE_PATTERNS);
}

private void addSmeltery() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package slimeknights.tconstruct.library.data.recipe;

import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.world.item.crafting.Ingredient;
import slimeknights.mantle.recipe.data.CompoundIngredient;
import slimeknights.tconstruct.common.TinkerTags;
import slimeknights.tconstruct.common.registration.CastItemObject;
import slimeknights.tconstruct.library.recipe.casting.material.CompositeCastingRecipeBuilder;
import slimeknights.tconstruct.library.recipe.casting.material.MaterialCastingRecipeBuilder;
Expand Down Expand Up @@ -54,6 +57,7 @@ default void partRecipes(Consumer<FinishedRecipe> consumer, IMaterialItem part,
// Part Builder
PartRecipeBuilder.partRecipe(part)
.setPattern(modResource(name))
.setPatternItem(CompoundIngredient.from(Ingredient.of(TinkerTags.Items.DEFAULT_PATTERNS), Ingredient.of(cast.get())))
.setCost(cost)
.save(consumer, modResource(partFolder + "builder/" + name));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package slimeknights.tconstruct.library.recipe.partbuilder;

import net.minecraft.world.item.ItemStack;
import slimeknights.tconstruct.common.TinkerTags;
import slimeknights.tconstruct.library.materials.definition.MaterialVariant;
import slimeknights.tconstruct.tables.TinkerTables;

import java.util.Collections;
import java.util.List;

/**
Expand All @@ -19,6 +18,6 @@ public interface IDisplayPartBuilderRecipe extends IPartBuilderRecipe {
* @return Pattern items
*/
default List<ItemStack> getPatternItems() {
return Collections.singletonList(new ItemStack(TinkerTables.pattern));
return TinkerTags.Items.DEFAULT_PATTERNS.getValues().stream().map(ItemStack::new).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.level.Level;
import slimeknights.mantle.recipe.helper.ItemOutput;
import slimeknights.mantle.recipe.helper.LoggingRecipeSerializer;
import slimeknights.mantle.util.JsonHelper;
import slimeknights.tconstruct.common.TinkerTags;
import slimeknights.tconstruct.library.materials.definition.MaterialVariant;
import slimeknights.tconstruct.library.materials.definition.MaterialVariantId;
import slimeknights.tconstruct.library.recipe.material.MaterialRecipe;
import slimeknights.tconstruct.tables.TinkerTables;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;

/**
* Recipe to craft an ordinary item using the part builder
Expand All @@ -28,22 +32,24 @@ public class ItemPartRecipe implements IDisplayPartBuilderRecipe {
private final MaterialVariant material;
@Getter
private final Pattern pattern;
private final Ingredient patternItem;
@Getter
private final int cost;
private final ItemOutput result;

public ItemPartRecipe(ResourceLocation id, MaterialVariantId material, Pattern pattern, int cost, ItemOutput result) {
public ItemPartRecipe(ResourceLocation id, MaterialVariantId material, Pattern pattern, Ingredient patternItem, int cost, ItemOutput result) {
this.id = id;
this.material = MaterialVariant.of(material);
this.pattern = pattern;
this.patternItem = patternItem;
this.cost = cost;
this.result = result;
}

@Override
public boolean partialMatch(IPartBuilderContainer inv) {
// first, must have a pattern
if (inv.getPatternStack().getItem() != TinkerTables.pattern.get()) {
if (!patternItem.test(inv.getPatternStack())) {
return false;
}
// if there is a material item, it must have a valid material and be craftable
Expand Down Expand Up @@ -72,30 +78,46 @@ public RecipeSerializer<?> getSerializer() {
return TinkerTables.itemPartBuilderSerializer.get();
}


/* JEI */

@Override
public List<ItemStack> getPatternItems() {
return Arrays.asList(patternItem.getItems());
}

public static class Serializer extends LoggingRecipeSerializer<ItemPartRecipe> {
@Override
public ItemPartRecipe fromJson(ResourceLocation id, JsonObject json) {
MaterialVariantId materialId = MaterialVariantId.fromJson(json, "material");
Pattern pattern = new Pattern(GsonHelper.getAsString(json, "pattern"));
Ingredient patternItem;
if (json.has("pattern_item")) {
patternItem = Ingredient.fromJson(json.get("pattern_item"));
} else {
patternItem = Ingredient.of(TinkerTags.Items.DEFAULT_PATTERNS);
}
int cost = GsonHelper.getAsInt(json, "cost");
ItemOutput result = ItemOutput.fromJson(JsonHelper.getElement(json, "result"));
return new ItemPartRecipe(id, materialId, pattern, cost, result);
return new ItemPartRecipe(id, materialId, pattern, patternItem, cost, result);
}

@Nullable
@Override
protected ItemPartRecipe fromNetworkSafe(ResourceLocation id, FriendlyByteBuf buffer) {
MaterialVariantId materialId = MaterialVariantId.parse(buffer.readUtf(Short.MAX_VALUE));
Pattern pattern = new Pattern(buffer.readUtf(Short.MAX_VALUE));
Ingredient patternItem = Ingredient.fromNetwork(buffer);
int cost = buffer.readVarInt();
ItemOutput result = ItemOutput.read(buffer);
return new ItemPartRecipe(id, materialId, pattern, cost, result);
return new ItemPartRecipe(id, materialId, pattern, patternItem, cost, result);
}

@Override
protected void toNetworkSafe(FriendlyByteBuf buffer, ItemPartRecipe recipe) {
buffer.writeUtf(recipe.material.getVariant().toString());
buffer.writeUtf(recipe.pattern.toString());
recipe.patternItem.toNetwork(buffer);
buffer.writeVarInt(recipe.cost);
recipe.result.write(buffer);
}
Expand Down

0 comments on commit b8afc70

Please sign in to comment.