-
Notifications
You must be signed in to change notification settings - Fork 788
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to break down a tool in the part builder
- Loading branch information
1 parent
1485a9f
commit 4b13e1f
Showing
20 changed files
with
484 additions
and
89 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/generated/resources/data/tconstruct/recipes/tables/tool_recycling.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "tconstruct:part_builder_tool_recycling", | ||
"pattern": { | ||
"tag": "tconstruct:patterns" | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/slimeknights/tconstruct/library/recipe/material/IMaterialValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package slimeknights.tconstruct.library.recipe.material; | ||
|
||
import net.minecraft.world.item.ItemStack; | ||
import slimeknights.mantle.recipe.container.ISingleStackContainer; | ||
import slimeknights.tconstruct.library.materials.definition.MaterialVariant; | ||
|
||
/** | ||
* Represents a material with an amount and a cost | ||
*/ | ||
public interface IMaterialValue { | ||
/** Gets the material represented in this cost */ | ||
MaterialVariant getMaterial(); | ||
|
||
/** Gets the number of items needed for a single craft */ | ||
default int getNeeded() { | ||
return 1; | ||
} | ||
|
||
/** Gets the value of a single item of this material */ | ||
int getValue(); | ||
|
||
/** | ||
* Gets a copy of the leftover stack for this recipe | ||
* @return Leftover stack | ||
*/ | ||
default ItemStack getLeftover() { | ||
return ItemStack.EMPTY; | ||
} | ||
|
||
|
||
/* Helpers */ | ||
|
||
/** | ||
* Gets the amount of material present in the inventory as a float for display | ||
* @param inv Inventory reference | ||
* @return Number of material present as a float | ||
*/ | ||
default float getMaterialValue(ISingleStackContainer inv) { | ||
return inv.getStack().getCount() * this.getValue() / (float)this.getNeeded(); | ||
} | ||
|
||
/** | ||
* Gets the number of items in order to craft a material with the given cost | ||
* @param itemCost Cost of the item being crafted | ||
* @return Number of the input to consume | ||
*/ | ||
default int getItemsUsed(int itemCost) { | ||
int needed = itemCost * getNeeded(); | ||
int value = getValue(); | ||
int cost = needed / value; | ||
if (needed % value != 0) { | ||
cost++; | ||
} | ||
return cost; | ||
} | ||
|
||
/** | ||
* Gets the number of leftover material from crafting a part with this material | ||
* @param itemCost Cost of the item being crafted | ||
* @return Number of input to consume | ||
*/ | ||
default int getRemainder(int itemCost) { | ||
return itemCost * this.getNeeded() % this.getValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/slimeknights/tconstruct/library/recipe/material/MaterialValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package slimeknights.tconstruct.library.recipe.material; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import slimeknights.tconstruct.library.materials.definition.MaterialVariant; | ||
import slimeknights.tconstruct.library.materials.definition.MaterialVariantId; | ||
|
||
/** | ||
* Constant material value used for tool parts | ||
*/ | ||
@RequiredArgsConstructor | ||
public class MaterialValue implements IMaterialValue { | ||
@Getter | ||
private final MaterialVariant material; | ||
@Getter | ||
private final int value; | ||
|
||
public MaterialValue(MaterialVariantId material, int value) { | ||
this(MaterialVariant.of(material), value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.