-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathInfusionDisguiseArmor.java
134 lines (117 loc) · 4.73 KB
/
InfusionDisguiseArmor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package makeo.gadomancy.common.crafting;
import makeo.gadomancy.common.research.SimpleResearchItem;
import makeo.gadomancy.common.utils.NBTHelper;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.common.config.ConfigItems;
import thaumcraft.common.lib.crafting.InfusionRunicAugmentRecipe;
import thaumcraft.common.lib.research.ResearchManager;
import java.util.*;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
* <p/>
* Created by makeo @ 25.12.2015 15:35
*/
public class InfusionDisguiseArmor extends InfusionRunicAugmentRecipe {
public static final ItemStack[] COMPONENTS = new ItemStack[] {new ItemStack(Items.slime_ball), new ItemStack(ConfigItems.itemResource, 1, 3), new ItemStack(Items.slime_ball), new ItemStack(ConfigItems.itemResource, 1, 3)};
public static final AspectList ASPECTS = new AspectList().add(Aspect.SLIME, 12).add(Aspect.ARMOR, 10).add(Aspect.MAGIC, 8);
private Map<ItemStack, List<ItemStack>> cachedItems = new HashMap<ItemStack, List<ItemStack>>();
@Override
public boolean matches(ArrayList<ItemStack> input, ItemStack central, World world, EntityPlayer player) {
if(input.size() != COMPONENTS.length + 1 || !ResearchManager.isResearchComplete(player.getCommandSenderName(), SimpleResearchItem.getFullName("STICKYJAR"))) {
return false;
}
List<ItemStack> copy = (List<ItemStack>) input.clone();
List<ItemStack> result = new ArrayList<ItemStack>(copy.size());
for(ItemStack required : COMPONENTS) {
boolean contains = false;
for(int i = 0; i < copy.size(); i++) {
if(areItemStacksEqual(required, copy.get(i), true)) {
contains = true;
result.add(copy.get(i));
copy.remove(i);
break;
}
}
if(!contains) {
return false;
}
}
ItemStack disguise = copy.get(0);
if(!isValidDisguise(central, disguise)) {
return false;
}
result.add(0, disguise);
cachedItems.put(central, result);
return true;
}
@Override
public ItemStack[] getComponents(ItemStack input) {
List<ItemStack> components = cachedItems.get(input);
if(components != null) {
return components.toArray(new ItemStack[components.size()]);
}
return new ItemStack[0];
}
@Override
public AspectList getAspects(ItemStack input) {
cachedItems.remove(input);
return ASPECTS;
}
@Override
public int getInstability(ItemStack input) {
return -20;
}
@Override
public Object getRecipeOutput(ItemStack input) {
List<ItemStack> components = cachedItems.get(input);
if(components != null) {
return disguiseStack(input, components.get(0));
}
return input;
}
public static ItemStack disguiseStack(ItemStack stack, ItemStack disguise) {
ItemStack out = stack.copy();
NBTTagCompound compound = NBTHelper.getPersistentData(out);
if(disguise.getItem() == Items.potionitem) {
compound.setBoolean("disguise", true);
} else {
compound.setTag("disguise", disguise.writeToNBT(new NBTTagCompound()));
}
return out;
}
private boolean isValidDisguise(ItemStack armor, ItemStack disguise) {
if(isDisguised(armor) || isDisguised(disguise)) {
return false;
}
int armorPos = EntityLiving.getArmorPosition(armor);
return armorPos != 0 && (isInvisItem(disguise) || EntityLiving.getArmorPosition(disguise) == armorPos);
}
private boolean isDisguised(ItemStack stack) {
return NBTHelper.hasPersistentData(stack) && NBTHelper.getPersistentData(stack).hasKey("disguise");
}
private boolean isInvisItem(ItemStack disguise) {
if(disguise.getItem() == Items.potionitem) {
List effects = Items.potionitem.getEffects(disguise);
for(Object obj : effects) {
if(obj instanceof PotionEffect) {
if(((PotionEffect)obj).getPotionID() == Potion.invisibility.getId()) {
return true;
}
}
}
}
return false;
}
}