use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier in project Wizardry by TeamWizardry.
the class SpellBuilder method toSpell.
private List<SpellRing> toSpell(List<ItemStack> inventory, double constructorFriendlyThing) {
List<SpellRing> spellList = new ArrayList<>();
Set<List<SpellRing>> spellChains = new HashSet<>();
List<List<ItemStack>> lines = brancher(inventory, SpellUtils.CODE_LINE_BREAK);
// Spell chain from multiple chains
for (List<ItemStack> line : lines) {
// List is made of all modules that aren't modifiers for this spellData chain.
Deque<SpellRing> uncompressedChain = new ArrayDeque<>();
// Step through each item in line. If modifier, add to lastModule, if not, add to compiled.
for (ItemStack stack : line) {
ModuleInstance module = ModuleRegistry.INSTANCE.getModule(stack);
if (module == null)
continue;
if (module instanceof ModuleInstanceModifier) {
if (!uncompressedChain.isEmpty()) {
for (int i = 0; i < stack.getCount(); i++) {
SpellRing lastRing = uncompressedChain.peekLast();
lastRing.addModifier((ModuleInstanceModifier) module);
}
}
} else {
for (int i = 0; i < stack.getCount(); i++) {
SpellRing ring = new SpellRing(module);
uncompressedChain.add(ring);
}
}
}
spellChains.add(new ArrayList<>(uncompressedChain));
}
// We now have a code line of modules. link them as children in order.
for (List<SpellRing> rings : spellChains) {
if (rings.isEmpty())
continue;
Deque<SpellRing> deque = new ArrayDeque<>(rings);
SpellRing ringHead = deque.pop();
SpellRing lastRing = ringHead;
while (!deque.isEmpty()) {
SpellRing child = deque.pop();
lastRing.setChildRing(child);
child.setParentRing(lastRing);
lastRing = child;
}
spellList.add(ringHead);
}
for (SpellRing ring : spellList) {
SpellRing chainEnd = ring;
while (chainEnd != null) {
if (chainEnd.getChildRing() == null) {
if (chainEnd.getModule() != null) {
chainEnd.setPrimaryColor(chainEnd.getModule().getPrimaryColor());
chainEnd.setSecondaryColor(chainEnd.getModule().getSecondaryColor());
}
chainEnd.updateColorChain();
}
chainEnd.processModifiers();
chainEnd = chainEnd.getChildRing();
}
}
return spellList;
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier in project Wizardry by TeamWizardry.
the class CommonWorktableModule method deserializeNBT.
@Override
public void deserializeNBT(NBTTagCompound nbt) {
if (nbt.hasKey("module")) {
module = ModuleInstance.deserialize(nbt.getString("module"));
}
if (nbt.hasKey("x") && nbt.hasKey("y")) {
pos = new Vec2d(nbt.getDouble("x"), nbt.getDouble("y"));
}
if (nbt.hasKey("linksTo")) {
linksTo = deserailize(nbt.getCompoundTag("linksTo"));
}
if (nbt.hasKey("modifiers")) {
modifiers = new HashMap<>();
for (String base : nbt.getCompoundTag("modifiers").getKeySet()) {
ModuleInstance module = ModuleRegistry.INSTANCE.getModule(base);
if (!(module instanceof ModuleInstanceModifier))
continue;
int count = nbt.getCompoundTag("modifiers").getInteger(base);
modifiers.put((ModuleInstanceModifier) module, count);
}
}
if (nbt.hasKey("hash")) {
hash = nbt.getInteger("hash");
}
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier in project Wizardry by TeamWizardry.
the class CommonWorktableModule method serializeNBT.
@Override
public NBTTagCompound serializeNBT() {
NBTTagCompound compound = new NBTTagCompound();
if (hash != -1) {
compound.setInteger("hash", hash);
}
if (module != null)
compound.setString("module", module.getNBTKey());
if (pos != null) {
compound.setDouble("x", pos.getX());
compound.setDouble("y", pos.getY());
}
if (linksTo != null)
compound.setTag("linksTo", linksTo.serializeNBT());
NBTTagCompound modifierNBT = new NBTTagCompound();
for (ModuleInstanceModifier modifier : modifiers.keySet()) {
int count = modifiers.get(modifier);
modifierNBT.setInteger(modifier.getNBTKey(), count);
}
compound.setTag("modifiers", modifierNBT);
return compound;
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier in project Wizardry by TeamWizardry.
the class WorktableGui method load.
public void load() {
TileEntity tile = Minecraft.getMinecraft().world.getTileEntity(pos);
if (tile instanceof TileMagiciansWorktable) {
if (((TileMagiciansWorktable) tile).commonModules != null) {
Set<CommonWorktableModule> commonModules = ((TileMagiciansWorktable) tile).getCommonModules();
for (CommonWorktableModule commonHead : commonModules) {
if (commonHead != null) {
// ADDED HERE
CommonWorktableModule commonModule = commonHead;
TableModule lastModule = new TableModule(this, commonHead.module, true, false);
lastModule.setPos(commonHead.pos);
while (commonModule != null) {
lastModule.radius = 10;
lastModule.textRadius = 0;
paper.add(lastModule);
DragMixin drag = new DragMixin(lastModule, vec2d -> vec2d);
drag.setDragOffset(new Vec2d(6, 6));
for (ModuleInstanceModifier modifier : commonModule.modifiers.keySet()) {
lastModule.setData(Integer.class, modifier.getNBTKey(), commonModule.modifiers.get(modifier));
}
if (commonModule.linksTo != null) {
if (commonModule.linksTo.module != null) {
TableModule childModule = new TableModule(this, commonModule.linksTo.module, true, false);
childModule.setPos(commonModule.linksTo.pos);
lastModule.setLinksTo(childModule);
lastModule = childModule;
} else {
// If a module was removed from the mod, try and clear the table.
// This doesn't clear the whole table, but it's good enough.
((TileMagiciansWorktable) tile).setCommonModules(new NBTTagList());
syncToServer();
Minecraft.getMinecraft().player.sendMessage(new TextComponentString(TextFormatting.RED + "wizardry.table.no_component_error"));
return;
}
}
commonModule = commonModule.linksTo;
}
}
}
}
}
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier in project Wizardry by TeamWizardry.
the class WorktableGui method getSpellName.
public String getSpellName() {
List<List<ModuleInstance>> chains = new ArrayList<>();
for (TableModule head : getSpellHeads()) {
List<ModuleInstance> chain = new ArrayList<>();
TableModule lastModule = head;
while (lastModule != null) {
chain.add(lastModule.getModule());
for (ModuleInstance module : ModuleRegistry.INSTANCE.getModules(ModuleType.MODIFIER)) {
if (!(module instanceof ModuleInstanceModifier))
continue;
if (!lastModule.hasData(Integer.class, module.getNBTKey()))
continue;
int count = lastModule.getData(Integer.class, module.getNBTKey());
for (int i = 0; i < count; i++) {
chain.add(module);
}
}
lastModule = lastModule.getLinksTo();
}
chains.add(chain);
}
SpellBuilder builder = new SpellBuilder(SpellUtils.getSpellItems(chains));
StringBuilder spellNameBuilder = new StringBuilder();
SpellRing lastRing = null;
for (SpellRing ring : builder.getSpell()) {
if (lastRing == null)
lastRing = ring;
if (ring != null) {
if (ring != lastRing)
spellNameBuilder.append(TextFormatting.GRAY).append(" | ");
SpellRing tmpRing = ring;
while (tmpRing != null) {
spellNameBuilder.append(TextFormatting.YELLOW).append(tmpRing.getModuleReadableName()).append(TextFormatting.GRAY).append("(").append(TextFormatting.BLUE).append(Math.round(tmpRing.getManaDrain(null) * tmpRing.getManaMultiplier())).append(TextFormatting.GRAY).append("/").append(TextFormatting.RED).append(Math.round(tmpRing.getBurnoutFill(null) * tmpRing.getBurnoutMultiplier())).append(TextFormatting.GRAY).append(")");
tmpRing = tmpRing.getChildRing();
if (tmpRing != null) {
spellNameBuilder.append(TextFormatting.GRAY).append(" > ");
}
}
}
}
return spellNameBuilder.toString();
}
Aggregations