use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance 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.ModuleInstance 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.ModuleInstance 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();
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.
the class CommandListModules method execute.
@Override
public void execute(@NotNull MinecraftServer server, @NotNull ICommandSender sender, @NotNull String[] args) {
notifyCommandListener(sender, this, TextFormatting.YELLOW + " ________________________________________________\\\\");
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | " + TextFormatting.GRAY + "Module List");
for (ModuleInstance module : ModuleRegistry.INSTANCE.modules) notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + module.getNBTKey() + TextFormatting.RESET + ": " + TextFormatting.GRAY + module.getReadableName());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " |________________________________________________//");
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.
the class SpellUtils method deserializeModuleList.
public static List<List<ModuleInstance>> deserializeModuleList(@Nonnull NBTTagList list) {
List<List<ModuleInstance>> modules = new ArrayList<>();
List<ModuleInstance> moduleList = new ArrayList<>();
for (int i = 0; i < list.tagCount(); i++) {
NBTBase base = list.get(i);
if (!(base instanceof NBTTagString))
continue;
NBTTagString string = (NBTTagString) base;
if (string.isEmpty()) {
if (!moduleList.isEmpty())
modules.add(moduleList);
moduleList = new ArrayList<>();
}
ModuleInstance module = ModuleInstance.deserialize(string);
if (module == null)
continue;
moduleList.add(module);
}
if (!moduleList.isEmpty())
modules.add(moduleList);
return modules;
}
Aggregations