use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.
the class WorktableGui method addModules.
private void addModules(ComponentSprite parent, ModuleType type) {
int column = 0, row = 0;
for (ModuleInstance module : ModuleRegistry.INSTANCE.getModules(type)) {
TableModule tableModule = new TableModule(this, module, false, false);
tableModule.setPos(new Vec2d(row * 16, column * 16));
parent.add(tableModule);
if (++row >= 3) {
row = 0;
column++;
}
}
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.
the class ComponentModifiers method set.
public void set() {
List<GuiComponent> children = new ArrayList<>(getChildren());
// units: none (modifier)
int childrenSize = children.size();
// units: pixels
float slideInDist = childrenSize * PIXELS_PER_BAR;
for (int i = 0; i < childrenSize; i++) {
// units: pixels
int lengthToTravel = (i + 1) * PIXELS_PER_BAR;
// units: ticks
float slideDuration = SLIDE_IN_DURATION * lengthToTravel / slideInDist;
// units: ticks
float waitDuration = SLIDE_IN_DURATION - slideDuration;
GuiComponent bar = children.get(i);
BasicAnimation<GuiComponent> animPlate = new BasicAnimation<>(bar, "pos.y");
// Use Easing.easeInOutBack for the sexiest effect. Important: do it for BOTH!
animPlate.setEasing(Easing.easeInBack);
// units: pixels
animPlate.setFrom(lengthToTravel - PIXELS_PER_BAR);
// units: pixels
animPlate.setTo(-PIXELS_PER_BAR);
// units: ticks
animPlate.setDuration(slideDuration);
animPlate.setCompletion(bar::invalidate);
add(new ScheduledEventAnimation(waitDuration, () -> add(animPlate)));
}
Runnable begin = () -> {
TableModule selectedModule = worktable.selectedModule;
if (selectedModule == null) {
animationPlaying = false;
return;
}
ModuleInstance module = selectedModule.getModule();
ModuleInstanceModifier[] applicableModifiers = module.applicableModifiers();
if (applicableModifiers == null || applicableModifiers.length <= 0) {
animationPlaying = false;
return;
}
ModuleInstanceModifier[] modifiers = module.applicableModifiers();
if (modifiers == null) {
animationPlaying = false;
return;
}
// units: none
int modifiersSize = modifiers.length;
// units: pixels
float slideOutDist = modifiersSize * PIXELS_PER_BAR;
// units: ticks
float outDuration = SLIDE_OUT_DURATION * modifiersSize;
add(new ScheduledEventAnimation(SLIDE_IN_DURATION, () -> animationPlaying = false));
for (int i = 0; i < modifiers.length; i++) {
// units: pixels
int lengthToTravel = (i + 1) * PIXELS_PER_BAR;
// units: ticks
float slideDuration = outDuration * lengthToTravel / slideOutDist;
ModuleInstanceModifier modifier = modifiers[i];
ComponentRect bar = new ComponentRect(0, 0, getSize().getXi(), PIXELS_PER_BAR);
bar.getColor().setValue(new Color(0x80000000, true));
TableModule tableModifier = new TableModule(worktable, modifier, false, true);
tableModifier.setEnableTooltip(true);
tableModifier.getTransform().setTranslateZ(80);
bar.add(tableModifier);
ComponentText text = new ComponentText(20, 4, ComponentText.TextAlignH.LEFT, ComponentText.TextAlignV.TOP);
text.getText().setValue(TextFormatting.GREEN + modifier.getShortHandName());
bar.add(text);
bar.setVisible(true);
BasicAnimation<ComponentRect> animPlate = new BasicAnimation<>(bar, "pos.y");
// Use Easing.easeInOutBack for the sexiest effect. Important: do it for BOTH!
animPlate.setEasing(Easing.easeOutBack);
// units: pixels
animPlate.setFrom(-PIXELS_PER_BAR);
// units: pixels
animPlate.setTo(lengthToTravel - PIXELS_PER_BAR);
// units: ticks
animPlate.setDuration(slideDuration);
animPlate.setCompletion(() -> Minecraft.getMinecraft().player.playSound(ModSounds.WHOOSH, 1f, 1f));
add(animPlate);
bar.render.getTooltip().func((Function<GuiComponent, List<String>>) t -> {
List<String> txt = new ArrayList<>();
if (worktable.animationPlaying || tableModifier.getMouseOver())
return txt;
txt.add(TextFormatting.GOLD + modifier.getReadableName());
if (GuiScreen.isShiftKeyDown())
txt.add(TextFormatting.GRAY + modifier.getDescription());
else
txt.add(TextFormatting.GRAY + LibrarianLib.PROXY.translate("wizardry.misc.sneak"));
return txt;
});
bar.BUS.hook(GuiComponentEvents.MouseInEvent.class, event -> {
bar.getColor().setValue(new Color(0x66000000, true));
});
bar.BUS.hook(GuiComponentEvents.MouseOutEvent.class, event -> {
bar.getColor().setValue(new Color(0x80000000, true));
});
bar.BUS.hook(GuiComponentEvents.MouseDownEvent.class, event -> {
if (event.component.getMouseOver()) {
bar.getColor().setValue(new Color(0x4D000000, true));
}
});
bar.BUS.hook(GuiComponentEvents.MouseUpEvent.class, event -> {
if (event.component.getMouseOver()) {
bar.getColor().setValue(new Color(0x80000000, true));
}
});
bar.BUS.hook(GuiComponentEvents.MouseClickEvent.class, (event) -> {
if (!event.component.getMouseOver())
return;
if (worktable.selectedModule == null)
return;
int j = worktable.selectedModule.hasData(Integer.class, modifier.getNBTKey()) ? worktable.selectedModule.getData(Integer.class, modifier.getNBTKey()) : 0;
int status = -1;
if (event.getButton() == EnumMouseButton.LEFT) {
AttributeRange cap = null;
for (AttributeRegistry.Attribute modifiersAssigned : worktable.selectedModule.getModule().getAttributeRanges().keySet()) {
for (AttributeModifier attribute : modifier.getAttributeModifiers()) {
if (modifiersAssigned.getNbtName().equals(attribute.getAttribute().getNbtName())) {
cap = worktable.selectedModule.getModule().getAttributeRanges().get(modifiersAssigned);
break;
}
}
}
if (cap != null && cap.max <= j) {
Minecraft.getMinecraft().player.playSound(ModSounds.SPELL_FAIL, 1f, 1f);
return;
}
Minecraft.getMinecraft().player.playSound(ModSounds.POP, 1f, 1f);
worktable.selectedModule.setData(Integer.class, modifier.getNBTKey(), ++j);
status = 0;
worktable.setToastMessage("", Color.GREEN);
worktable.syncToServer();
} else if (event.getButton() == EnumMouseButton.RIGHT) {
if (worktable.selectedModule.hasData(Integer.class, modifier.getNBTKey())) {
if (j > 0) {
Minecraft.getMinecraft().player.playSound(ModSounds.ZOOM, 1f, 1f);
worktable.selectedModule.setData(Integer.class, modifier.getNBTKey(), --j);
if (j <= 0) {
Minecraft.getMinecraft().player.playSound(ModSounds.SPELL_FAIL, 1f, 1f);
worktable.selectedModule.removeData(Integer.class, modifier.getNBTKey());
}
status = 1;
worktable.syncToServer();
}
worktable.setToastMessage("", Color.GREEN);
} else
Minecraft.getMinecraft().player.playSound(ModSounds.SPELL_FAIL, 1f, 1f);
}
if (status == -1)
return;
TableModule fakePlate = new TableModule(worktable, modifier, false, true);
fakePlate.getTransform().setTranslateZ(80);
worktable.getMainComponents().add(fakePlate);
Vec2d from = tableModifier.thisPosToOtherContext(worktable.getMainComponents());
Vec2d to = worktable.selectedModule.thisPosToOtherContext(worktable.getMainComponents()).add(worktable.selectedModule.getSize().sub(tableModifier.getSize()).mul(0.5f));
KeyframeAnimation<TableModule> anim = new KeyframeAnimation<>(fakePlate, "pos");
anim.setDuration(20);
if (status == 0) {
Vec2d rand = from.add(RandUtil.nextDouble(-10, 10), RandUtil.nextDouble(-10, 10));
anim.setKeyframes(new Keyframe[] { new Keyframe(0, from, Easing.easeOutQuint), new Keyframe(0.3f, rand, Easing.easeOutQuint), new Keyframe(0.35f, rand, Easing.easeOutQuint), new Keyframe(1f, to, Easing.easeInOutQuint) });
} else {
Vec2d rand = to.add(RandUtil.nextDouble(-10, 10), RandUtil.nextDouble(-10, 10));
anim.setKeyframes(new Keyframe[] { new Keyframe(0, to, Easing.easeOutQuint), new Keyframe(0.3f, rand, Easing.easeOutQuint), new Keyframe(0.35f, rand, Easing.easeOutQuint), new Keyframe(1f, from, Easing.easeInOutQuint) });
}
anim.setCompletion(fakePlate::invalidate);
worktable.getMainComponents().add(anim);
worktable.paper.BUS.fire(new TableModule.ModuleUpdateEvent());
});
add(bar);
}
};
if (childrenSize > 0)
add(new ScheduledEventAnimation(SLIDE_IN_DURATION + SPACER_DURATION, begin));
else
begin.run();
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.
the class ComponentSpellRecipe method components.
public static List<PaginationContext> components(GuiBook book) {
List<PaginationContext> contexts = Lists.newArrayList();
if (book.getBookItemStack().isEmpty())
return contexts;
ItemStack bookStack = book.getBookItemStack();
if (!NBTHelper.getBoolean(bookStack, "has_spell", false))
return contexts;
NBTTagList moduleList = NBTHelper.getList(bookStack, NBTConstants.NBT.SPELL, net.minecraftforge.common.util.Constants.NBT.TAG_STRING);
if (moduleList == null)
return contexts;
List<List<ModuleInstance>> spellModules = SpellUtils.deserializeModuleList(moduleList);
List<ItemStack> spellItems = SpellUtils.getSpellItems(spellModules);
spellModules = SpellUtils.getEssentialModules(spellModules);
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
int widthOfSpace = fr.getStringWidth(" ");
StringBuilder builder = new StringBuilder(LibrarianLib.PROXY.translate("wizardry.book.spell_recipe_structure") + "\n");
for (List<ModuleInstance> spellModuleList : spellModules) {
String margin = null;
for (ModuleInstance module : spellModuleList) {
if (margin == null) {
margin = " - ";
builder.append(margin).append(module.getReadableName()).append("\n");
} else {
int realLength = fr.getStringWidth(margin);
int nbOfSpace = MathHelper.clamp(realLength / widthOfSpace, 0, 17);
margin = StringUtils.repeat(" ", nbOfSpace) + "|_ ";
builder.append(margin).append(module.getReadableName()).append("\n");
if (nbOfSpace >= 16) {
builder.append(" ________________|").append("\n");
margin = " ";
}
}
}
}
String[] lines = builder.toString().split("\n");
StringBuilder pageChunk = new StringBuilder();
int count = 0;
for (String line : lines) {
pageChunk.append(line).append("\n");
if (++count >= 16) {
count = 0;
pageFromString(book, contexts, pageChunk);
pageChunk = new StringBuilder();
}
}
if (count != 0)
pageFromString(book, contexts, pageChunk);
Consumer<ComponentVoid> applier = component -> {
};
for (int i = 0; i < spellItems.size(); i++) {
ItemStack stack = spellItems.get(i);
int index = i;
applier = applier.andThen(component -> {
ComponentStack componentStack = new ComponentStack((index % 4) * 32, (index / 4) * 16);
componentStack.getStack().setValue(stack);
component.add(componentStack);
if (index != spellItems.size() - 1 && (index % 4) < 3) {
ComponentSprite nextItem = new ComponentSprite(book.getHomeSprite(), 32 + (index % 4) * 32, (index / 4) * 16 + 13, 16, 8);
nextItem.getColor().setValue(book.getBook().getHighlightColor());
nextItem.getTransform().setRotate(Math.toRadians(180));
component.add(nextItem);
}
});
if ((index / 4) >= 9) {
Consumer<ComponentVoid> spellApplier = applier;
contexts.add(new PaginationContext(() -> {
ComponentVoid component = new ComponentVoid(16, 16, book.getMainBookComponent().getSize().getXi() - 32, book.getMainBookComponent().getSize().getYi() - 32);
spellApplier.accept(component);
return component;
}));
applier = component -> {
};
}
}
Consumer<ComponentVoid> spellApplier = applier;
contexts.add(new PaginationContext(() -> {
ComponentVoid component = new ComponentVoid(16, 16, book.getMainBookComponent().getSize().getXi() - 32, book.getMainBookComponent().getSize().getYi() - 32);
spellApplier.accept(component);
return component;
}));
return contexts;
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.
the class RenderCodex method getSpellStructureLines.
public String[] getSpellStructureLines(ItemStack stack) {
NBTTagList moduleList = NBTHelper.getList(stack, NBTConstants.NBT.SPELL, net.minecraftforge.common.util.Constants.NBT.TAG_STRING);
if (moduleList == null)
return new String[0];
List<List<ModuleInstance>> spellModules = SpellUtils.deserializeModuleList(moduleList);
spellModules = SpellUtils.getEssentialModules(spellModules);
int page = NBTHelper.getInt(stack, "page", 0);
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
int widthOfSpace = fr.getStringWidth(" ");
StringBuilder builder = new StringBuilder("Spell Structure:\n");
for (List<ModuleInstance> spellModuleList : spellModules) {
String margin = null;
for (ModuleInstance module : spellModuleList) {
if (margin == null) {
margin = " - ";
builder.append(margin).append(module.getReadableName()).append("\n");
} else {
int realLength = fr.getStringWidth(margin);
int nbOfSpace = MathHelper.clamp(realLength / widthOfSpace, 0, 17);
margin = StringUtils.repeat(" ", nbOfSpace) + "|_ ";
builder.append(margin).append(module.getReadableName()).append("\n");
if (nbOfSpace >= 16) {
builder.append(" ________________|").append("\n");
margin = " ";
}
}
}
}
String[] lines = builder.toString().split("\n");
StringBuilder pageChunk = new StringBuilder();
int count = 0;
int currentPage = 0;
for (String line : lines) {
pageChunk.append(line).append("\n");
if (++count >= 16) {
count = 0;
if (currentPage >= page)
return pageChunk.toString().split("\n");
pageChunk = new StringBuilder();
}
}
return pageChunk.toString().split("\n");
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.
the class CommandDebug method execute.
@Override
public void execute(@NotNull MinecraftServer server, @NotNull ICommandSender sender, @NotNull String[] args) throws WrongUsageException {
if (args.length < 2)
throw new WrongUsageException(getUsage(sender));
ModuleInstance module = ModuleRegistry.INSTANCE.getModule(args[1]);
if (module == null) {
notifyCommandListener(sender, this, "wizardry.command." + getName() + ".module_not_found");
return;
}
notifyCommandListener(sender, this, TextFormatting.YELLOW + " ________________________________________________\\\\");
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | " + TextFormatting.GRAY + "Module " + module.getReadableName() + ":");
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Description " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getDescription());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Item Stack " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getItemStack().getDisplayName());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Burnout Fill " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getBurnoutFill());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | | |_ " + TextFormatting.DARK_GREEN + "Burnout Multiplier" + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getBurnoutMultiplier());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Mana Drain " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getManaDrain());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | | |_" + TextFormatting.DARK_GREEN + "Mana Multiplier " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getManaMultiplier());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Power Multiplier " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getPowerMultiplier());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Charge Up Time " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getChargeupTime());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Cooldown Time " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getCooldownTime());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Primary Color " + TextFormatting.GRAY + " | " + TextFormatting.RED + module.getPrimaryColor().getRed() + TextFormatting.GRAY + ", " + TextFormatting.GREEN + module.getPrimaryColor().getGreen() + TextFormatting.GRAY + ", " + TextFormatting.BLUE + module.getPrimaryColor().getBlue());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Secondary Color " + TextFormatting.GRAY + " | " + TextFormatting.RED + module.getSecondaryColor().getRed() + TextFormatting.GRAY + ", " + TextFormatting.GREEN + module.getSecondaryColor().getGreen() + TextFormatting.GRAY + ", " + TextFormatting.BLUE + module.getSecondaryColor().getBlue());
if (!module.getAttributeModifiers().isEmpty())
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Default AttributeRegistry");
for (AttributeModifier attributeModifier : module.getAttributeModifiers()) notifyCommandListener(sender, this, TextFormatting.YELLOW + " | | |_ " + TextFormatting.GRAY + attributeModifier.toString());
ModuleInstanceModifier[] modifierList = module.applicableModifiers();
if (modifierList != null) {
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Applicable Modifiers ");
for (ModuleInstanceModifier modifier : modifierList) notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.DARK_GREEN + modifier.getNBTKey());
}
notifyCommandListener(sender, this, TextFormatting.YELLOW + " |________________________________________________//");
}
Aggregations