Skip to content

Commit

Permalink
Change how leaf fletchlings are handled to be more general. Basically…
Browse files Browse the repository at this point in the history
… ALL leaves can be used for leaf fletchlings now.
  • Loading branch information
bonii-xx committed Aug 23, 2014
1 parent 1dd13c5 commit 1753521
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 38 deletions.
10 changes: 2 additions & 8 deletions src/main/java/tconstruct/library/TConstructRegistry.java
Expand Up @@ -217,7 +217,7 @@ public static ArrayList<ToolCore> getToolMapping ()
* multiple times the parts are added to the recipe's input list Valid part
* amounts are 2, 3, and 4.
*
* @see ToolBuidler
* @see ToolBuilder
* @param output
* The ToolCore to craft
* @param parts
Expand All @@ -241,8 +241,6 @@ public static void addToolRecipe (ToolCore output, Item... parts)
*
* @param materialID
* Unique ID, stored for each part
* @exception materialID
* must be unique
* @param materialName
* Unique name for data lookup purposes
* @param harvestLevel
Expand Down Expand Up @@ -283,8 +281,6 @@ public static void addToolMaterial (int materialID, String materialName, int har
*
* @param materialID
* Unique ID, stored for each part
* @exception materialID
* must be unique
* @param materialName
* Unique name for data lookup purposes
* @param displayName
Expand Down Expand Up @@ -327,8 +323,6 @@ public static void addToolMaterial (int materialID, String materialName, String
*
* @param materialID
* Unique ID, stored for each part
* @exception materialID
* must be unique
* @param material
* Complete tool material to add. Uses the name in the material
* for lookup purposes.
Expand Down Expand Up @@ -456,7 +450,7 @@ public static CustomMaterial getCustomMaterial (ItemStack input, Class<? extends
{
for (CustomMaterial mat : customMaterials)
{
if (mat.getClass().equals(clazz) && input.isItemEqual(mat.input))
if (mat.getClass().equals(clazz) && mat.matches(input))
return mat;
}
return null;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/tconstruct/library/tools/FletchingMaterial.java
Expand Up @@ -15,4 +15,12 @@ public FletchingMaterial(int materialID, int value, ItemStack input, ItemStack c
this.breakChance = breakChance;
this.mass = mass;
}

public FletchingMaterial(int materialID, int value, String oredict, ItemStack craftingItem, float accuracy, float breakChance, float mass)
{
super(materialID, value, oredict, craftingItem);
this.accuracy = accuracy;
this.breakChance = breakChance;
this.mass = mass;
}
}
@@ -1,4 +1,34 @@
package tconstruct.library.tools;

public class FletchlingLeafMaterial {
import mantle.blocks.BlockUtils;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import tconstruct.tools.TinkerToolEvents;

public class FletchlingLeafMaterial extends FletchingMaterial {
public FletchlingLeafMaterial(int materialID, int value, String oredict, ItemStack craftingItem, float accuracy, float breakChance, float mass) {
super(materialID, value, oredict, craftingItem, accuracy, breakChance, mass);
}

@Override
public boolean matches(ItemStack stack) {
if(matchesLeaves(stack))
return true;

return super.matches(stack);
}

public static boolean matchesLeaves (ItemStack stack)
{
if (stack != null)
{
Block block = BlockUtils.getBlockFromItemStack(stack);
if (block != null)
{
if (block.isLeaves(null, 0, 0, 0))
return true;
}
}
return false;
}
}
31 changes: 4 additions & 27 deletions src/main/java/tconstruct/tools/TinkerToolEvents.java
Expand Up @@ -25,12 +25,7 @@
import tconstruct.armor.player.TPlayerStats;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.event.*;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.library.tools.ArrowMaterial;
import tconstruct.library.tools.BowMaterial;
import tconstruct.library.tools.BowstringMaterial;
import tconstruct.library.tools.FletchingMaterial;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.tools.*;
import tconstruct.util.ItemHelper;
import tconstruct.util.config.PHConstruct;
import cpw.mods.fml.common.eventhandler.Event.Result;
Expand Down Expand Up @@ -222,33 +217,15 @@ public static ItemStack craftBowString (ItemStack stack)

public static ItemStack craftFletching (ItemStack stack)
{
if (matchesLeaves(stack))
{
FletchingMaterial leaves = (FletchingMaterial) TConstructRegistry.getCustomMaterial(new ItemStack(Blocks.leaves), FletchingMaterial.class);
return leaves.craftingItem.copy();
}

FletchingMaterial mat = (FletchingMaterial) TConstructRegistry.getCustomMaterial(stack, FletchingMaterial.class);
// maybe it's a leaf fletchling
if(mat == null)
mat = (FletchingMaterial) TConstructRegistry.getCustomMaterial(stack, FletchlingLeafMaterial.class);
if (mat != null)
return mat.craftingItem.copy();
return null;
}

public static boolean matchesLeaves (ItemStack stack)
{
if (stack != null)
{
Block block = BlockUtils.getBlockFromItemStack(stack);
if (block != null)
{
if (block.isLeaves(null, 0, 0, 0))
return true;
}
}
return false;
}



@SubscribeEvent
public void onAttack (LivingAttackEvent event)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tconstruct/tools/TinkerTools.java
Expand Up @@ -44,6 +44,7 @@
import tconstruct.library.TConstructRegistry;
import tconstruct.library.client.TConstructClientRegistry;
import tconstruct.library.crafting.*;
import tconstruct.library.tools.FletchlingLeafMaterial;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.util.IPattern;
import tconstruct.modifiers.tools.ModAntiSpider;
Expand Down Expand Up @@ -877,8 +878,7 @@ void registerMaterials ()

TConstructRegistry.addBowstringMaterial(0, 2, new ItemStack(Items.string), new ItemStack(TinkerTools.bowstring, 1, 0), 1F, 1F, 1f); // String
TConstructRegistry.addFletchingMaterial(0, 2, new ItemStack(Items.feather), new ItemStack(TinkerTools.fletching, 1, 0), 100F, 0F, 0.05F); // Feather
for (int i = 0; i < 4; i++)
TConstructRegistry.addFletchingMaterial(1, 2, new ItemStack(Blocks.leaves, 1, i), new ItemStack(TinkerTools.fletching, 1, 1), 75F, 0F, 0.2F); // All four vanialla Leaves
TConstructRegistry.addCustomMaterial(new FletchlingLeafMaterial(1, 2, "treeLeaves", new ItemStack(TinkerTools.fletching, 1, 1), 75F, 0F, 0.2F)); // all vanilla and oredicted leaves. and all leaves in general.
TConstructRegistry.addFletchingMaterial(2, 2, new ItemStack(TinkerTools.materials, 1, 1), new ItemStack(TinkerTools.fletching, 1, 2), 100F, 0F, 0.12F); // Slime
TConstructRegistry.addFletchingMaterial(3, 2, new ItemStack(TinkerTools.materials, 1, 17), new ItemStack(TinkerTools.fletching, 1, 3), 100F, 0F, 0.12F); // BlueSlime

Expand Down

0 comments on commit 1753521

Please sign in to comment.