Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change StencilTable from hardcoded patterns to a flexible system
- Loading branch information
Showing
4 changed files
with
92 additions
and
36 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/main/java/tconstruct/library/crafting/StencilBuilder.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,64 @@ | ||
package tconstruct.library.crafting; | ||
|
||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.oredict.OreDictionary; | ||
|
||
import java.util.*; | ||
|
||
public class StencilBuilder { | ||
public static StencilBuilder instance = new StencilBuilder(); | ||
|
||
public List<ItemStack> blanks = new LinkedList<ItemStack>(); // i wish ItemStack would support equals so i could use a Set here... | ||
public List<ItemStack> stencils = new ArrayList<ItemStack>(); | ||
|
||
/** | ||
* Returns whether the given ItemStack is a blank pattern and therefore usable for stencil crafting. | ||
*/ | ||
public static boolean isBlank(ItemStack stack) | ||
{ | ||
for(ItemStack blank : instance.blanks) | ||
if(OreDictionary.itemMatches(stack, blank, false)) // this has nothing to do with the oredictionary. | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
public static void registerBlankStencil(ItemStack itemStack) | ||
{ | ||
instance.blanks.add(itemStack); | ||
} | ||
|
||
public static void registerStencil(Item item, int meta) | ||
{ | ||
instance.stencils.add(new ItemStack(item, 1, meta)); | ||
} | ||
|
||
public static void registerStencil(ItemStack pattern) | ||
{ | ||
instance.stencils.add(pattern); | ||
} | ||
|
||
public static List<ItemStack> getStencils() { return instance.stencils; } | ||
|
||
/** | ||
* Returns the index of the given stencil. If no stencil is found, returns -1. | ||
*/ | ||
public static int getIndex(ItemStack stencil) { | ||
for(int i = 0; i < instance.stencils.size(); i++) | ||
if(ItemStack.areItemStackTagsEqual(stencil, getStencil(i))) | ||
return i; | ||
|
||
return -1; | ||
} | ||
|
||
// returns the stencil with the given index | ||
public static ItemStack getStencil(int num) { | ||
if(num >= instance.stencils.size()) | ||
return null; | ||
|
||
return instance.stencils.get(num).copy(); | ||
} | ||
|
||
public static int getStencilCount() { return instance.stencils.size(); } | ||
} |
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