Rewrote ModAttack to accept multiple items

This commit is contained in:
mDiyo committed 2013-12-12 03:08:05 -08:00
1 parent 977287e440
commit 086cc97ddc
12 files changed
+152 -50

No files matched your search

+1 -3
View File
@@ -70,7 +70,7 @@ public class TConstruct
}
EnvironmentChecks.verifyEnvironmentSanity();
MinecraftForge.EVENT_BUS.register(events = new TEventHandler());
PluginController.getController().registerBuiltins();
}
@@ -89,8 +89,6 @@ public class TConstruct
content = new TContent();
events = new TEventHandler();
MinecraftForge.EVENT_BUS.register(events);
MinecraftForge.EVENT_BUS.register(new TEventHandlerAchievement());
TRecipes.oreRegistry();
@@ -19,8 +19,7 @@ import tconstruct.library.tools.ToolCore;
public class CraftingStationLogic extends InventoryLogic implements ISidedInventory
{
public WeakReference<IInventory> chest;
public WeakReference<IInventory> chest; //TODO: These are prototypes
public WeakReference<IInventory> doubleChest;
public WeakReference<IInventory> patternChest;
public WeakReference<IInventory> furnace;
@@ -57,7 +57,6 @@ public class ToolStationLogic extends InventoryLogic implements ISidedInventory
public void onInventoryChanged ()
{
System.out.println("Changed");
buildTool(toolName);
if (this.worldObj != null)
{
@@ -49,10 +49,10 @@ public class CraftingStationGui extends GuiContainer
if (logic.tinkerTable)
{
/*if (logic.isStackInSlot(0))
if (logic.isStackInSlot(0))
drawToolStats();
else*/
drawToolInformation();
else
drawToolInformation();
}
}
+10 -10
View File
@@ -239,8 +239,8 @@ public class TRecipes
tb.registerToolMod(new ModDurability(new ItemStack[] { diamond }, 0, 500, 0f, 3, "Diamond", "\u00a7bDurability +500", "\u00a7b"));
tb.registerToolMod(new ModDurability(new ItemStack[] { new ItemStack(Item.emerald) }, 1, 0, 0.5f, 2, "Emerald", "\u00a72Durability +50%", "\u00a72"));
TRepo.modF = new ModFlux();
tb.registerToolMod(TRepo.modF);
TRepo.modFlux = new ModFlux();
tb.registerToolMod(TRepo.modFlux);
ItemStack redstoneItem = new ItemStack(Item.redstone);
ItemStack redstoneBlock = new ItemStack(Block.blockRedstone);
@@ -252,8 +252,8 @@ public class TRecipes
ItemStack lapisItem = new ItemStack(Item.dyePowder, 1, 4);
ItemStack lapisBlock = new ItemStack(Block.blockLapis);
TRepo.modL = new ModLapis(new ItemStack[] { lapisItem }, 10, 1);
tb.registerToolMod(TRepo.modL);
TRepo.modLapis = new ModLapis(new ItemStack[] { lapisItem }, 10, 1);
tb.registerToolMod(TRepo.modLapis);
tb.registerToolMod(new ModLapis(new ItemStack[] { lapisItem, lapisItem }, 10, 2));
tb.registerToolMod(new ModLapis(new ItemStack[] { lapisBlock }, 10, 9));
tb.registerToolMod(new ModLapis(new ItemStack[] { lapisItem, lapisBlock }, 10, 10));
@@ -266,13 +266,13 @@ public class TRecipes
tb.registerToolMod(new ModAutoSmelt(new ItemStack[] { new ItemStack(TRepo.materials, 1, 7) }, 6, "Lava", "\u00a74", "Auto-Smelt"));
tb.registerToolMod(new ModInteger(new ItemStack[] { new ItemStack(TRepo.materials, 1, 8) }, 8, "Necrotic", 1, "\u00a78", "Life Steal"));
ItemStack quartzItem = new ItemStack(Item.netherQuartz);
ItemStack quartzBlock = new ItemStack(Block.blockNetherQuartz, 1, Short.MAX_VALUE);
tb.registerToolMod(new ModAttack("Quartz", new ItemStack[] { quartzItem }, 11, 1));
TRepo.modAttack = new ModAttack("Quartz", 11, new ItemStack[] { new ItemStack(Item.netherQuartz), new ItemStack(Block.blockNetherQuartz, 1, Short.MAX_VALUE) }, new int[] { 1, 4 });
tb.registerToolMod(TRepo.modAttack);
/*tb.registerToolMod(new ModAttack("Quartz", new ItemStack[] { new ItemStack(Item.netherQuartz), new ItemStack(Block.blockNetherQuartz, 1, Short.MAX_VALUE) }, 11, 1));
tb.registerToolMod(new ModAttack("Quartz", new ItemStack[] { quartzItem, quartzItem }, 11, 2));
tb.registerToolMod(new ModAttack("Quartz", new ItemStack[] { quartzBlock }, 11, 4));
tb.registerToolMod(new ModAttack("Quartz", new ItemStack[] { quartzItem, quartzBlock }, 11, 5));
tb.registerToolMod(new ModAttack("Quartz", new ItemStack[] { quartzBlock, quartzBlock }, 11, 8));
tb.registerToolMod(new ModAttack("Quartz", new ItemStack[] { quartzBlock, quartzBlock }, 11, 8));*/
tb.registerToolMod(new ModExtraModifier(new ItemStack[] { diamond, new ItemStack(Block.blockGold) }, "Tier1Free"));
tb.registerToolMod(new ModExtraModifier(new ItemStack[] { new ItemStack(Item.netherStar) }, "Tier2Free"));
@@ -1259,12 +1259,12 @@ public class TRecipes
ItemStack batHardened = GameRegistry.findItemStack("ThermalExpansion", "capacitorHardened", 1);
if (batHardened != null)
{
TRepo.modF.batteries.add(batHardened);
TRepo.modFlux.batteries.add(batHardened);
}
ItemStack basicCell = GameRegistry.findItemStack("ThermalExpansion", "cellBasic", 1);
if (basicCell != null)
{
TRepo.modF.batteries.add(basicCell);
TRepo.modFlux.batteries.add(basicCell);
}
if (batHardened != null)
TConstructClientRegistry.registerManualModifier("fluxmod", ironpick.copy(), (ItemStack) batHardened);
+4 -4
View File
@@ -4,8 +4,7 @@ import tconstruct.blocks.OreberryBush;
import tconstruct.blocks.slime.SlimeLeaves;
import tconstruct.blocks.slime.SlimeSapling;
import tconstruct.library.tools.ToolCore;
import tconstruct.modifiers.tools.ModFlux;
import tconstruct.modifiers.tools.ModLapis;
import tconstruct.modifiers.tools.*;
import net.minecraft.block.Block;
import net.minecraft.block.StepSound;
import net.minecraft.block.material.Material;
@@ -234,8 +233,9 @@ public class TRepo
public static Item oreBerries;
//Tool modifiers
public static ModFlux modF;
public static ModLapis modL;
public static ModFlux modFlux;
public static ModLapis modLapis;
public static ModAttack modAttack;
//Wearables
public static Item heavyHelmet;
@@ -7,6 +7,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.world.World;
@@ -94,21 +95,20 @@ public class CraftingStationContainer extends Container
else
this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
}
public ItemStack modifyTool ()
{
ItemStack input = craftResult.getStackInSlot(5);
ItemStack input = craftMatrix.getStackInSlot(4);
if (input != null)
{
if (input.getItem() instanceof ToolCore)
Item item = input.getItem();
if (item instanceof ToolCore)
{
ItemStack[] slots = new ItemStack[8];
for (int i = 0; i < 0; i++)
for (int i = 0; i < 4; i++)
{
slots[i] = craftResult.getStackInSlot(i + 1);
slots[i + 4] = craftResult.getStackInSlot(i + 6);
slots[i] = craftMatrix.getStackInSlot(i);
slots[i + 4] = craftMatrix.getStackInSlot(i + 5);
}
ItemStack output = ToolBuilder.instance.modifyTool(input, slots, "");
if (output != null)
@@ -70,8 +70,8 @@ public abstract class ToolMod
return list.isEmpty();
}
protected String getTagName()
protected String getTagName ()
{
return "InfiTool";
}
@@ -211,4 +211,13 @@ public abstract class ToolMod
{
return true;
}
protected boolean areItemStacksEquivalent (ItemStack stack1, ItemStack stack2)
{
if (stack1.itemID != stack2.itemID)
return false;
if (stack1.getItemDamage() != stack2.getItemDamage())
return false;
return ItemStack.areItemStackTagsEqual(stack1, stack2);
}
}
@@ -3,25 +3,21 @@ package tconstruct.modifiers.tools;
import java.util.Arrays;
import java.util.List;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.tools.ToolMod;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.tools.ToolCore;
public class ModAttack extends ToolMod
public class ModAttack extends ToolModTypeFilter
{
String tooltipName;
int increase;
int max = 72;
String guiType;
public ModAttack(String type, ItemStack[] items, int effect, int inc)
public ModAttack(String type, int effect, ItemStack[] items, int[] value)
{
super(items, effect, "ModAttack");
super(effect, "ModAttack", items, value);
tooltipName = "\u00a7fSharpness";
guiType = type;
increase = inc;
}
@Override
@@ -36,14 +32,13 @@ public class ModAttack extends ToolMod
return tags.getInteger("Modifiers") > 0;
int keyPair[] = tags.getIntArray(key);
if (keyPair[0] + increase <= keyPair[1])
if (keyPair[0] + matchingAmount(input) <= keyPair[1])
return true;
else if (keyPair[0] == keyPair[1])
return tags.getInteger("Modifiers") > 0;
else
return false;
return false;
}
@Override
@@ -58,6 +53,7 @@ public class ModAttack extends ToolMod
amount = 36;
int[] keyPair = tags.getIntArray(key);
int increase = matchingAmount(input);
int leftToBoost = amount - (keyPair[0] % amount);
if (increase >= leftToBoost)
@@ -90,6 +86,7 @@ public class ModAttack extends ToolMod
int modifiers = tags.getInteger("Modifiers");
modifiers -= 1;
tags.setInteger("Modifiers", modifiers);
int increase = matchingAmount(input);
String modName = "\u00a7f" + guiType + " (" + increase + "/" + max + ")";
int tooltipIndex = addToolTip(tool, tooltipName, modName);
int[] keyPair = new int[] { increase, max, tooltipIndex };
@@ -112,8 +109,6 @@ public class ModAttack extends ToolMod
public boolean validType (ToolCore tool)
{
return true;
/*List list = Arrays.asList(tool.toolCategories());
return list.contains("melee") || list.contains("harvest") || list.contains("ammo");*/
}
public boolean nerfType (ToolCore tool)
@@ -55,7 +55,7 @@ public class TActiveOmniMod extends ActiveToolMod
{
if (entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.isCreativeMode)
return false;
TRepo.modL.midStreamModify(stack, tool);
TRepo.modLapis.midStreamModify(stack, tool);
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
World world = entity.worldObj;
@@ -151,7 +151,7 @@ public class TActiveOmniMod extends ActiveToolMod
@Override
public int baseAttackDamage (int earlyModDamage, int damage, ToolCore tool, NBTTagCompound tags, NBTTagCompound toolTags, ItemStack stack, EntityLivingBase player, Entity entity)
{
TRepo.modL.midStreamModify(stack, tool);
TRepo.modLapis.midStreamModify(stack, tool);
return 0;
}
@@ -0,0 +1,103 @@
package tconstruct.modifiers.tools;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import tconstruct.library.tools.ToolMod;
public abstract class ToolModTypeFilter extends ToolMod//boobs.java
{
public final List<Integer> increase;
public ToolModTypeFilter(int effect, String dataKey, ItemStack[] items, int[] values)
{
super(items, effect, dataKey);
assert items.length == values.length : "Itemstacks and their values for tool modifiers must be the same length";
this.increase = new ArrayList<Integer>();
for (int i = 0; i < values.length; i++)
{
increase.add(values[i]);
}
}
/** Checks to see if the inputs match the stored items
* Note: Filters types, doesn't care about amount
*
* @param input The ItemStacks to compare against
* @param tool Item to modify, used for restrictions
* @return Whether the recipe matches the input
*/
@Override
public boolean matches (ItemStack[] input, ItemStack tool)
{
if (!canModify(tool, input))
return false;
boolean minimumMatch = false;
for (ItemStack inputStack : input)
{
if (inputStack == null)
continue;
boolean match = false;
for (Object check : stacks)
{
ItemStack stack = (ItemStack) check;
System.out.println("First stack: "+stack);
System.out.println("Second stack: "+inputStack);
if (stack.getItemDamage() == Short.MAX_VALUE)
{
if (inputStack.isItemEqual(stack))
match = true;
}
else
{
if (this.areItemStacksEquivalent(inputStack, stack))
match = true;
}
}
if (!match)
{
System.out.println("Not a match");
return false;
}
minimumMatch = true;
}
System.out.println("Object: " + minimumMatch);
return minimumMatch;
}
public int matchingAmount (ItemStack[] input)
{
int amount = 0;
for (ItemStack i : input)
{
if (i == null)
continue;
else
{
for (int iter = 0; iter < stacks.size(); iter++)
{
ItemStack check = (ItemStack) stacks.get(iter);
if (ItemStack.areItemStacksEqual(i, check))
amount += increase.get(iter);
}
}
}
return amount;
}
/** Adds a new itemstack to the list of increases
*
* @param stack ItemStack to compare against
* @param increase Amount to increase
*/
public void addStackToMatchList (ItemStack stack, int amount)
{
if (stack == null)
throw new NullPointerException("ItemStack added to " + this.getClass().getSimpleName() + " cannot be null.");
stacks.add(stack);
increase.add(amount);
}
}
@@ -63,7 +63,6 @@ import tconstruct.util.player.TPlayerStats;
public class TEventHandler
{
Random random = new Random();
private Object evt;
/* Crafting */
@ForgeSubscribe
@@ -535,12 +534,12 @@ public class TEventHandler
if (evt.Name == "crystalQuartz")
{
ToolBuilder.instance.registerToolMod(new ModAttack("Quartz", new ItemStack[] { evt.Ore }, 11, 2));
TRepo.modAttack.addStackToMatchList(evt.Ore, 2);
}
else if (evt.Name == "crystalCerusQuartz")
{
ToolBuilder.instance.registerToolMod(new ModAttack("Quartz", new ItemStack[] { evt.Ore }, 11, 24));
TRepo.modAttack.addStackToMatchList(evt.Ore, 24);
}
}