Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
299 additions
and
19 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -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; | ||
} | ||
} |
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
87 changes: 87 additions & 0 deletions
87
src/main/java/tconstruct/modifiers/armor/AModMoveSpeed.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,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; | ||
} | ||
} |
Oops, something went wrong.