use of am2.api.spell.component.interfaces.ISpellPart in project ArsMagica2 by Mithion.
the class TileEntityInscriptionTable method GetUpdatePacketForServer.
private byte[] GetUpdatePacketForServer() {
AMDataWriter writer = new AMDataWriter();
writer.add(FULL_UPDATE);
writer.add(this.currentPlayerUsing == null);
if (this.currentPlayerUsing != null)
writer.add(this.currentPlayerUsing.getEntityId());
writer.add(this.currentRecipe.size());
for (int i = 0; i < this.currentRecipe.size(); ++i) {
ISpellPart part = this.currentRecipe.get(i);
int id = part.getID();
if (part instanceof ISpellComponent)
id += SkillManager.COMPONENT_OFFSET;
else if (part instanceof ISpellModifier)
id += SkillManager.MODIFIER_OFFSET;
writer.add(id);
}
writer.add(this.shapeGroups.size());
for (ArrayList<ISpellPart> shapeGroup : this.shapeGroups) {
int[] groupData = new int[shapeGroup.size()];
for (int i = 0; i < shapeGroup.size(); ++i) {
groupData[i] = SkillManager.instance.getShiftedPartID(shapeGroup.get(i));
}
writer.add(groupData);
}
writer.add(currentSpellName);
writer.add(currentSpellIsReadOnly);
return writer.generate();
}
use of am2.api.spell.component.interfaces.ISpellPart in project ArsMagica2 by Mithion.
the class GuiArcaneCompendium method getAndAnalyzeRecipe.
private void getAndAnalyzeRecipe() {
if (renderStack == null)
return;
if (renderStack.getItem() == ItemsCommonProxy.essence || renderStack.getItem() == ItemsCommonProxy.deficitCrystal) {
RecipeArsMagica essenceRecipe = RecipesEssenceRefiner.essenceRefinement().recipeFor(renderStack);
if (essenceRecipe != null) {
craftingComponents = essenceRecipe.getRecipeItems();
recipeHeight = 2;
} else {
craftingComponents = null;
}
} else if (renderStack.getItem() instanceof ItemSpellPart) {
ISkillTreeEntry part = SkillManager.instance.getSkill(this.entryName);
if (part == null)
return;
ArrayList<Object> recipe = new ArrayList<Object>();
if (part instanceof ISpellPart) {
Object[] recipeItems = ((ISpellPart) part).getRecipeItems();
SpellRecipeItemsEvent event = new SpellRecipeItemsEvent(SkillManager.instance.getSkillName(part), SkillManager.instance.getShiftedPartID(part), recipeItems);
MinecraftForge.EVENT_BUS.post(event);
recipeItems = event.recipeItems;
if (recipeItems != null) {
for (int i = 0; i < recipeItems.length; ++i) {
Object o = recipeItems[i];
boolean matches = false;
if (o instanceof ItemStack) {
recipe.add(o);
} else if (o instanceof Item) {
recipe.add(new ItemStack((Item) o));
} else if (o instanceof Block) {
recipe.add(new ItemStack((Block) o));
} else if (o instanceof String) {
if (((String) o).startsWith("P:")) {
// potion
String s = ((String) o).substring(2);
int pfx = SpellRecipeManager.parsePotionMeta(s);
recipe.add(new ItemStack(Items.potionitem, 1, pfx));
} else if (((String) o).startsWith("E:")) {
// essence
String s = ((String) o);
try {
int[] types = SpellRecipeManager.ParseEssenceIDs(s);
int type = 0;
for (int t : types) type |= t;
int amount = (Integer) recipeItems[++i];
recipe.add(new ItemStack(ItemsCommonProxy.essence, amount, ItemsCommonProxy.essence.META_MAX + type));
} catch (Throwable t) {
continue;
}
} else {
recipe.add(OreDictionary.getOres((String) o));
}
}
}
}
}
craftingComponents = recipe.toArray();
} else {
IRecipe recipe = RecipeUtilities.getRecipeFor(renderStack);
if (recipe != null) {
renderStack = recipe.getRecipeOutput();
if (recipe instanceof ShapedRecipes) {
recipeWidth = ((ShapedRecipes) recipe).recipeWidth;
recipeHeight = ((ShapedRecipes) recipe).recipeHeight;
craftingComponents = ((ShapedRecipes) recipe).recipeItems;
} else if (recipe instanceof ShapedOreRecipe) {
recipeWidth = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, ((ShapedOreRecipe) recipe), "width");
recipeHeight = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, ((ShapedOreRecipe) recipe), "height");
craftingComponents = ((ShapedOreRecipe) recipe).getInput();
} else if (recipe instanceof ShapelessRecipes) {
recipeWidth = ((ShapelessRecipes) recipe).getRecipeSize();
recipeHeight = -1;
craftingComponents = ((ShapelessRecipes) recipe).recipeItems.toArray();
} else if (recipe instanceof ShapelessOreRecipe) {
recipeWidth = ((ShapelessOreRecipe) recipe).getRecipeSize();
recipeHeight = -1;
craftingComponents = ((ShapelessOreRecipe) recipe).getInput().toArray();
} else {
craftingComponents = null;
}
} else {
craftingComponents = null;
}
}
}
use of am2.api.spell.component.interfaces.ISpellPart in project ArsMagica2 by Mithion.
the class TileEntityCraftingAltar method readFromNBT.
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
if (!nbttagcompound.hasKey("altarData"))
return;
NBTTagCompound altarCompound = nbttagcompound.getCompoundTag("altarData");
NBTTagList allAddedItems = altarCompound.getTagList("allAddedItems", Constants.NBT.TAG_COMPOUND);
NBTTagList currentAddedItems = altarCompound.getTagList("currentAddedItems", Constants.NBT.TAG_COMPOUND);
this.isCrafting = altarCompound.getBoolean("isCrafting");
this.currentKey = altarCompound.getInteger("currentKey");
this.currentSpellName = altarCompound.getString("currentSpellName");
if (altarCompound.hasKey("phylactery")) {
NBTTagCompound phylactery = altarCompound.getCompoundTag("phylactery");
if (phylactery != null)
this.addedPhylactery = ItemStack.loadItemStackFromNBT(phylactery);
}
if (altarCompound.hasKey("catalyst")) {
NBTTagCompound catalyst = altarCompound.getCompoundTag("catalyst");
if (catalyst != null)
this.addedBindingCatalyst = ItemStack.loadItemStackFromNBT(catalyst);
}
this.allAddedItems.clear();
for (int i = 0; i < allAddedItems.tagCount(); ++i) {
NBTTagCompound addedItem = (NBTTagCompound) allAddedItems.getCompoundTagAt(i);
if (addedItem == null)
continue;
ItemStack stack = ItemStack.loadItemStackFromNBT(addedItem);
if (stack == null)
continue;
this.allAddedItems.add(stack);
}
this.currentAddedItems.clear();
for (int i = 0; i < currentAddedItems.tagCount(); ++i) {
NBTTagCompound addedItem = (NBTTagCompound) currentAddedItems.getCompoundTagAt(i);
if (addedItem == null)
continue;
ItemStack stack = ItemStack.loadItemStackFromNBT(addedItem);
if (stack == null)
continue;
this.currentAddedItems.add(stack);
}
this.spellDef.clear();
for (ArrayList<KeyValuePair<ISpellPart, byte[]>> groups : shapeGroups) groups.clear();
NBTTagCompound currentSpellDef = altarCompound.getCompoundTag("spellDef");
this.spellDef.addAll(NBTToISpellPartList(currentSpellDef));
NBTTagList currentShapeGroups = altarCompound.getTagList("shapeGroups", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < currentShapeGroups.tagCount(); ++i) {
NBTTagCompound compound = (NBTTagCompound) currentShapeGroups.getCompoundTagAt(i);
shapeGroups.get(i).addAll(NBTToISpellPartList(compound));
}
}
use of am2.api.spell.component.interfaces.ISpellPart in project ArsMagica2 by Mithion.
the class TileEntityCraftingAltar method writeToNBT.
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
NBTTagCompound altarCompound = new NBTTagCompound();
altarCompound.setBoolean("isCrafting", this.isCrafting);
altarCompound.setInteger("currentKey", this.currentKey);
altarCompound.setString("currentSpellName", currentSpellName);
NBTTagList allAddedItemsList = new NBTTagList();
for (ItemStack stack : allAddedItems) {
NBTTagCompound addedItem = new NBTTagCompound();
stack.writeToNBT(addedItem);
allAddedItemsList.appendTag(addedItem);
}
altarCompound.setTag("allAddedItems", allAddedItemsList);
NBTTagList currentAddedItemsList = new NBTTagList();
for (ItemStack stack : currentAddedItems) {
NBTTagCompound addedItem = new NBTTagCompound();
stack.writeToNBT(addedItem);
currentAddedItemsList.appendTag(addedItem);
}
altarCompound.setTag("currentAddedItems", currentAddedItemsList);
if (addedPhylactery != null) {
NBTTagCompound phylactery = new NBTTagCompound();
addedPhylactery.writeToNBT(phylactery);
altarCompound.setTag("phylactery", phylactery);
}
if (addedBindingCatalyst != null) {
NBTTagCompound catalyst = new NBTTagCompound();
addedBindingCatalyst.writeToNBT(catalyst);
altarCompound.setTag("catalyst", catalyst);
}
NBTTagList shapeGroupData = new NBTTagList();
for (ArrayList<KeyValuePair<ISpellPart, byte[]>> list : shapeGroups) {
shapeGroupData.appendTag(ISpellPartListToNBT(list));
}
altarCompound.setTag("shapeGroups", shapeGroupData);
NBTTagCompound spellDefSave = ISpellPartListToNBT(this.spellDef);
altarCompound.setTag("spellDef", spellDefSave);
nbttagcompound.setTag("altarData", altarCompound);
}
use of am2.api.spell.component.interfaces.ISpellPart in project ArsMagica2 by Mithion.
the class TileEntityCraftingAltar method NBTToISpellPartList.
private ArrayList<KeyValuePair<ISpellPart, byte[]>> NBTToISpellPartList(NBTTagCompound compound) {
int[] ids = compound.getIntArray("group_ids");
ArrayList<KeyValuePair<ISpellPart, byte[]>> list = new ArrayList<KeyValuePair<ISpellPart, byte[]>>();
for (int i = 0; i < ids.length; ++i) {
int partID = ids[i];
ISkillTreeEntry part = SkillManager.instance.getSkill(i);
byte[] partMeta = compound.getByteArray("meta_" + i);
if (part instanceof ISpellPart) {
list.add(new KeyValuePair<ISpellPart, byte[]>((ISpellPart) part, partMeta));
}
}
return list;
}
Aggregations