Skip to content

Commit

Permalink
First armor modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
mDiyo committed Dec 13, 2013
1 parent 8b154a9 commit 90f09b7
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 19 deletions.
7 changes: 7 additions & 0 deletions src/main/java/tconstruct/TConstruct.java
Expand Up @@ -9,6 +9,8 @@
import cpw.mods.fml.common.network.*;
import cpw.mods.fml.common.registry.*;
import cpw.mods.fml.relauncher.Side;

import java.util.UUID;
import java.util.logging.Logger;
import net.minecraft.crash.CallableMinecraftVersion;
import net.minecraft.world.gen.structure.MapGenStructureIO;
Expand Down Expand Up @@ -68,6 +70,11 @@ public TConstruct()
{
System.out.println("[TConstruct] Preparing to take over the world");
}

System.out.println("[UUID] Armor Speed: "+UUID.randomUUID());
System.out.println("[UUID] Armor Attack: "+UUID.randomUUID());
System.out.println("[UUID] Armor Health: "+UUID.randomUUID());
System.out.println("[UUID] Armor Knockback: "+UUID.randomUUID());

EnvironmentChecks.verifyEnvironmentSanity();
MinecraftForge.EVENT_BUS.register(events = new TEventHandler());
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/tconstruct/client/gui/CraftingStationGui.java
Expand Up @@ -17,6 +17,7 @@
import org.lwjgl.opengl.GL11;

import tconstruct.blocks.logic.CraftingStationLogic;
import tconstruct.library.armor.ArmorCore;
import tconstruct.library.tools.ToolCore;

public class CraftingStationGui extends GuiContainer
Expand Down Expand Up @@ -67,6 +68,26 @@ void drawToolStats ()

drawModularToolStats(stack, tool, tags);
}
else if (stack.getItem() instanceof ArmorCore)
{
ArmorCore armor = (ArmorCore) stack.getItem();
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("TinkerArmor");
this.drawCenteredString(fontRenderer, "\u00A7n" + armor.getClass().getSimpleName(), xSize + 63, 8, 0xffffff);

drawModularArmorStats(stack, armor, tags);
}
}

void drawModularArmorStats (ItemStack stack, ArmorCore tool, NBTTagCompound tags)
{
int modifiers = tags.getInteger("Modifiers");
int base = 24;
int offset = 0;
if (modifiers > 0)
{
fontRenderer.drawString(StatCollector.translateToLocal("gui.toolstation18") + tags.getInteger("Modifiers"), xSize + 8, base + offset * 10, 0xffffff);
offset++;
}
}

void drawModularToolStats (ItemStack stack, ToolCore tool, NBTTagCompound tags)
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/tconstruct/common/TContent.java
Expand Up @@ -590,9 +590,9 @@ void registerItems ()
GameRegistry.registerItem(TRepo.bootsWood, "bootsWood");

TRepo.exoGoggles = new ExoArmor(PHConstruct.exoGoggles, EnumArmorPart.HELMET, "exosuit").setUnlocalizedName("tconstruct.exoGoggles");
TRepo.exoChest = new ExoArmor(PHConstruct.exoChest, EnumArmorPart.CHESTPLATE, "exosuit").setUnlocalizedName("tconstruct.exoChest");
TRepo.exoPants = new ExoArmor(PHConstruct.exoPants, EnumArmorPart.LEGGINGS, "exosuit").setUnlocalizedName("tconstruct.exoPants");
TRepo.exoShoes = new ExoArmor(PHConstruct.exoShoes, EnumArmorPart.BOOTS, "exosuit").setUnlocalizedName("tconstruct.exoShoes");
TRepo.exoChest = new ExoArmor(PHConstruct.exoChest, EnumArmorPart.CHEST, "exosuit").setUnlocalizedName("tconstruct.exoChest");
TRepo.exoPants = new ExoArmor(PHConstruct.exoPants, EnumArmorPart.PANTS, "exosuit").setUnlocalizedName("tconstruct.exoPants");
TRepo.exoShoes = new ExoArmor(PHConstruct.exoShoes, EnumArmorPart.SHOES, "exosuit").setUnlocalizedName("tconstruct.exoShoes");

String[] materialStrings = { "paperStack", "greenSlimeCrystal", "searedBrick", "ingotCobalt", "ingotArdite", "ingotManyullyn", "mossBall", "lavaCrystal", "necroticBone", "ingotCopper",
"ingotTin", "ingotAluminum", "rawAluminum", "ingotBronze", "ingotAluminumBrass", "ingotAlumite", "ingotSteel", "blueSlimeCrystal", "ingotObsidian", "nuggetIron", "nuggetCopper",
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/tconstruct/common/TRecipes.java
Expand Up @@ -3,6 +3,7 @@
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;

Expand All @@ -24,9 +25,12 @@
import tconstruct.blocks.logic.*;
import tconstruct.items.blocks.*;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.armor.ArmorMod;
import tconstruct.library.armor.EnumArmorPart;
import tconstruct.library.client.TConstructClientRegistry;
import tconstruct.library.crafting.*;
import tconstruct.library.util.IPattern;
import tconstruct.modifiers.armor.AModMoveSpeed;
import tconstruct.modifiers.tools.*;
import tconstruct.util.RecipeRemover;
import tconstruct.util.TDispenserBehaviorArrow;
Expand Down Expand Up @@ -241,9 +245,11 @@ protected static void addRecipesForToolBuilder ()
TRepo.modFlux = new ModFlux();
tb.registerToolMod(TRepo.modFlux);

EnumSet<EnumArmorPart> allArmors = EnumSet.of(EnumArmorPart.HELMET, EnumArmorPart.CHEST, EnumArmorPart.PANTS, EnumArmorPart.SHOES);
ItemStack redstoneItem = new ItemStack(Item.redstone);
ItemStack redstoneBlock = new ItemStack(Block.blockRedstone);
tb.registerToolMod(new ModRedstone(2, new ItemStack[] { redstoneItem, redstoneBlock }, new int[] { 1, 9 }));
tb.registerArmorMod(new AModMoveSpeed(2, allArmors, new ItemStack[] { redstoneItem, redstoneBlock }, new int[] { 1, 9 }, false));

ItemStack lapisItem = new ItemStack(Item.dyePowder, 1, 4);
ItemStack lapisBlock = new ItemStack(Block.blockLapis);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/tconstruct/inventory/CraftingStationContainer.java
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.world.World;
import tconstruct.blocks.logic.CraftingStationLogic;
import tconstruct.library.armor.ArmorCore;
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.tools.ToolCore;

Expand Down Expand Up @@ -114,6 +115,18 @@ public ItemStack modifyTool ()
if (output != null)
return output;
}
else if (item instanceof ArmorCore)
{
ItemStack[] slots = new ItemStack[8];
for (int i = 0; i < 4; i++)
{
slots[i] = craftMatrix.getStackInSlot(i);
slots[i + 4] = craftMatrix.getStackInSlot(i + 5);
}
ItemStack output = ToolBuilder.instance.modifyArmor(input, slots, "");
if (output != null)
return output;
}
}
return null;
}
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/tconstruct/items/armor/ExoArmor.java
Expand Up @@ -49,12 +49,16 @@ public void getSubItems (int par1, CreativeTabs par2CreativeTabs, List par3List)
NBTTagCompound baseTag = new NBTTagCompound();
NBTTagList list = new NBTTagList();

list.appendTag(getAttributeTag("generic.attackDamage", "ExoAttack", 10.0, true, knockback));
list.appendTag(getAttributeTag("generic.movementSpeed", "ExoSpeed", 1.5, false, speed));
list.appendTag(getAttributeTag("generic.maxHealth", "ExoHealth", 10.0, true, health));
list.appendTag(getAttributeTag("generic.knockbackResistance", "ExoKnockback", 0.5, false, knockback));
//list.appendTag(getAttributeTag("generic.attackDamage", "ExoAttack", 10.0, true, knockback));
//list.appendTag(getAttributeTag("generic.movementSpeed", "ExoSpeed", 1.5, false, speed));
//list.appendTag(getAttributeTag("generic.maxHealth", "ExoHealth", 10.0, true, health));
//list.appendTag(getAttributeTag("generic.knockbackResistance", "ExoKnockback", 0.5, false, knockback));
//baseTag.setTag("AttributeModifiers", list);

NBTTagCompound armorTag = new NBTTagCompound();
armorTag.setInteger("Modifiers", 30);
baseTag.setTag(SET_NAME, armorTag);

baseTag.setTag("AttributeModifiers", list);
armor.setTagCompound(baseTag);
par3List.add(armor);
}
Expand Down
43 changes: 34 additions & 9 deletions src/main/java/tconstruct/library/armor/ArmorMod.java
@@ -1,29 +1,54 @@
package tconstruct.library.armor;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.EnumSet;
import java.util.UUID;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.tools.ToolMod;

public abstract class ArmorMod extends ToolMod
{
public ArmorMod(ItemStack[] items, int effect, String dataKey)
protected final EnumSet<EnumArmorPart> armorTypes;

public ArmorMod(int effect, String dataKey, EnumSet<EnumArmorPart> armorTypes, ItemStack[] items)
{
super(items, effect, dataKey);
this.armorTypes = armorTypes;
}


@Override
protected boolean canModify (ItemStack armor, ItemStack[] input)
{
ArmorCore item = (ArmorCore) armor.getItem();
if (armorTypes.contains(item.armorPart))
{
NBTTagCompound tags = armor.getTagCompound().getCompoundTag(getTagName());
return tags.getInteger("Modifiers") > 0;
}
return false;
}

@Override
protected String getTagName()
protected String getTagName ()
{
return "TinkerArmor";
}
public boolean validArmorType(ArmorCore armor)

public boolean validArmorType (ArmorCore armor)
{
return true;
}

protected NBTTagCompound getAttributeTag(String attributeType, String modifierName, double amount, boolean flat, UUID uuid)
{
NBTTagCompound tag = new NBTTagCompound();
tag.setString("AttributeName", attributeType);
tag.setString("Name", modifierName);
tag.setDouble("Amount", amount);
tag.setInteger("Operation", flat ? 0 : 1);//0 = flat increase, 1 = % increase
tag.setLong("UUIDMost", uuid.getMostSignificantBits());
tag.setLong("UUIDLeast", uuid.getLeastSignificantBits());
return tag;
}
}
2 changes: 1 addition & 1 deletion src/main/java/tconstruct/library/armor/EnumArmorPart.java
Expand Up @@ -3,7 +3,7 @@
public enum EnumArmorPart
{

HELMET(0), CHESTPLATE(1), LEGGINGS(2), BOOTS(3);
HELMET(0), CHEST(1), PANTS(2), SHOES(3);

private final int partID;

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/tconstruct/library/crafting/ToolBuilder.java
Expand Up @@ -493,6 +493,15 @@ float buildShoddy (ToolMaterial headMat, ToolMaterial handleMat, ToolMaterial ac

public static void registerToolMod (ToolMod mod)
{
if (mod == null)
throw new NullPointerException("Tool modifier cannot be null.");
instance.toolMods.add(mod);
}

public static void registerArmorMod(ArmorMod mod)
{
if (mod == null)
throw new NullPointerException("Armor modifier cannot be null.");
instance.armorMods.add(mod);
}
}
87 changes: 87 additions & 0 deletions src/main/java/tconstruct/modifiers/armor/AModMoveSpeed.java
@@ -0,0 +1,87 @@
package tconstruct.modifiers.armor;

import java.util.EnumSet;
import java.util.UUID;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import tconstruct.library.armor.ArmorCore;
import tconstruct.library.armor.EnumArmorPart;

public class AModMoveSpeed extends ArmorModTypeFilter
{
final boolean modifierType;

public AModMoveSpeed(int effect, EnumSet<EnumArmorPart> armorTypes, ItemStack[] items, int[] values, boolean type)
{
super(effect, "ExoSpeed" + (type ? "Percent" : "Flat"), armorTypes, items, values);
this.modifierType = type;
}

@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
NBTTagCompound tags = tool.getTagCompound().getCompoundTag(getTagName());
int amount = matchingAmount(input);
return tags.getInteger("Modifiers") >= amount;
}

@Override
public void modify (ItemStack[] input, ItemStack armor)
{
NBTTagCompound baseTag = armor.getTagCompound();
NBTTagCompound armorTag = armor.getTagCompound().getCompoundTag(getTagName());

int amount = matchingAmount(input);
int modifiers = armorTag.getInteger("Modifiers");
modifiers -= amount;
armorTag.setInteger("Modifiers", modifiers);

if (armorTag.hasKey(key))
{
amount += armorTag.getInteger(key);
}
armorTag.setInteger(key, amount);

NBTTagList attributes;
if (baseTag.hasKey("AttributeModifiers"))
{
attributes = baseTag.getTagList("AttributeModifiers");
for (int iter = 0; iter < attributes.tagCount(); iter++)
{
NBTTagCompound tag = (NBTTagCompound) attributes.tagAt(iter);
if (tag.getString("AttributeName").equals(key))
attributes.removeTag(iter);
}
}
else
{
attributes = new NBTTagList();
baseTag.setTag("AttributeModifiers", attributes);
}
attributes.appendTag(getAttributeTag("generic.movementSpeed", key, amount / 100d, modifierType, getUUIDFromItem(armor)));
}

private static final UUID head = UUID.fromString("2ba6c8ae-4a19-49c6-aab4-ca3a5eb7c730");
private static final UUID chest = UUID.fromString("2ba6c8ae-4a19-49c6-aab4-ca3a5eb7c731");
private static final UUID pants = UUID.fromString("2ba6c8ae-4a19-49c6-aab4-ca3a5eb7c732");
private static final UUID shoes = UUID.fromString("2ba6c8ae-4a19-49c6-aab4-ca3a5eb7c733");

UUID getUUIDFromItem (ItemStack stack)
{
ArmorCore item = (ArmorCore) stack.getItem();
switch (item.armorPart)
{
case HELMET:
return head;
case CHEST:
return chest;
case PANTS:
return pants;
case SHOES:
return shoes;
}
return null;
}
}

0 comments on commit 90f09b7

Please sign in to comment.