mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-21 20:42:12 +00:00
-Added visual recipe for disguise armor
-Added crafting components to infusion for disguise armor
This commit is contained in:
1 parent
1ba42a0247
commit
113c770fc3
2 files changed
+128
-11
No files matched your search
@@ -14,6 +14,7 @@ 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;
|
||||
|
||||
@@ -28,8 +29,8 @@ import java.util.*;
|
||||
* Created by makeo @ 25.12.2015 15:35
|
||||
*/
|
||||
public class InfusionDisguiseArmor extends InfusionRunicAugmentRecipe {
|
||||
private static final ItemStack[] COMPONENTS = new ItemStack[] {new ItemStack(Items.slime_ball), new ItemStack(Items.slime_ball)};
|
||||
private static final AspectList ASPECTS = new AspectList().add(Aspect.WATER, 1);
|
||||
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>>();
|
||||
|
||||
@@ -90,19 +91,22 @@ public class InfusionDisguiseArmor extends InfusionRunicAugmentRecipe {
|
||||
public Object getRecipeOutput(ItemStack input) {
|
||||
List<ItemStack> components = cachedItems.get(input);
|
||||
if(components != null) {
|
||||
ItemStack disguise = components.get(0);
|
||||
ItemStack out = input.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;
|
||||
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;
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package makeo.gadomancy.common.crafting;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import thaumcraft.api.ThaumcraftApi;
|
||||
import thaumcraft.api.crafting.InfusionRecipe;
|
||||
import thaumcraft.api.internal.DummyInternalMethodHandler;
|
||||
import thaumcraft.api.internal.IInternalMethodHandler;
|
||||
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 @ 26.12.2015 18:10
|
||||
*/
|
||||
public class InfusionVisualDisguiseArmor extends InfusionRecipe {
|
||||
private static final IInternalMethodHandler FAKE_HANDLER = new FakeMethodHandler();
|
||||
|
||||
private final ItemStack[] armorItems;
|
||||
private final ItemStack[] components;
|
||||
|
||||
public InfusionVisualDisguiseArmor() {
|
||||
super("", new ItemStack(Blocks.cobblestone), 0, InfusionDisguiseArmor.ASPECTS, new ItemStack(Blocks.dirt), new ItemStack[0]);
|
||||
|
||||
components = new ItemStack[InfusionDisguiseArmor.COMPONENTS.length + 1];
|
||||
System.arraycopy(InfusionDisguiseArmor.COMPONENTS, 0, components, 1, InfusionDisguiseArmor.COMPONENTS.length);
|
||||
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
for (Object o : Item.itemRegistry) {
|
||||
if (o instanceof Item && ((Item) o).getCreativeTab() != null) {
|
||||
List list = new ArrayList();
|
||||
|
||||
try {
|
||||
((Item) o).getSubItems((Item) o, ((Item) o).getCreativeTab(), list);
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
for (Object o2 : list) {
|
||||
if (o2 != null && o2 instanceof ItemStack
|
||||
&& EntityLiving.getArmorPosition((ItemStack) o2) != 0) {
|
||||
items.add((ItemStack) o2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
armorItems = items.toArray(new ItemStack[items.size()]);
|
||||
}
|
||||
|
||||
private boolean canSee(ItemStack stack) {
|
||||
String research = getResearchKey(stack);
|
||||
return research == null || ResearchManager.isResearchComplete(Minecraft.getMinecraft().thePlayer.getCommandSenderName(), research);
|
||||
}
|
||||
|
||||
private ItemStack getCurrentDisguise() {
|
||||
Random random = new Random(System.currentTimeMillis() / 1000);
|
||||
int first = getRecipeInput(random);
|
||||
int firstPos = EntityLiving.getArmorPosition(armorItems[first]);
|
||||
|
||||
int next;
|
||||
do {
|
||||
next = random.nextInt(armorItems.length);
|
||||
}
|
||||
while (next == first || EntityLiving.getArmorPosition(armorItems[next]) != firstPos || !canSee(armorItems[next]));
|
||||
return armorItems[next];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRecipeInput() {
|
||||
return armorItems[getRecipeInput(new Random(System.currentTimeMillis() / 1000))];
|
||||
}
|
||||
|
||||
private int getRecipeInput(Random random) {
|
||||
int index;
|
||||
do {
|
||||
index = random.nextInt(armorItems.length);
|
||||
} while (!canSee(armorItems[index]));
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRecipeOutput(ItemStack input) {
|
||||
return InfusionDisguiseArmor.disguiseStack(input, getCurrentDisguise());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getComponents() {
|
||||
components[0] = getCurrentDisguise();
|
||||
return components;
|
||||
}
|
||||
|
||||
private static String getResearchKey(ItemStack stack) {
|
||||
IInternalMethodHandler old = ThaumcraftApi.internalMethods;
|
||||
ThaumcraftApi.internalMethods = FAKE_HANDLER;
|
||||
Object[] result = ThaumcraftApi.getCraftingRecipeKey(Minecraft.getMinecraft().thePlayer, stack);
|
||||
ThaumcraftApi.internalMethods = old;
|
||||
return result == null ? null : (String)result[0];
|
||||
}
|
||||
|
||||
private static class FakeMethodHandler extends DummyInternalMethodHandler {
|
||||
@Override
|
||||
public boolean isResearchComplete(String username, String researchkey) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user