use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.
the class SpellUtils method getSpellItems.
/**
* Gets a list of items required to create the given list of spell module chains.
*
* @param modules The list of spell module chains.
* @return A list of required items.
*/
public static List<ItemStack> getSpellItems(List<List<ModuleInstance>> modules) {
Deque<ItemStack> items = new ArrayDeque<>();
for (List<ModuleInstance> moduleList : modules) {
for (ModuleInstance module : moduleList) {
ItemStack stack = module.getItemStack();
ItemStack last = items.peekLast();
if (last == null)
items.add(stack.copy());
else if (items.peekLast().isItemEqual(stack))
last.grow(stack.getCount());
else
items.add(stack.copy());
}
items.add(new ItemStack(CODE_LINE_BREAK));
}
items.add(new ItemStack(ModItems.PEARL_NACRE));
return new ArrayList<>(items);
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.
the class GuiPearlSwap method renderParasol.
private void renderParasol(Tessellator tess, BufferBuilder bb, ItemStack holderStack, IPearlStorageHolder holder, double radius) {
int pearlCount = holder.getPearlCount(holderStack);
IItemHandler handler = holder.getPearls(holderStack);
if (pearlCount != 0 && handler != null) {
double innerRadius = radius + 0.5;
int numSegmentsPerArc = (int) Math.ceil(360d / pearlCount);
float anglePerColor = (float) (2 * PI / pearlCount);
float anglePerSegment = anglePerColor / numSegmentsPerArc;
float angle = 0;
for (int j = 0; j < pearlCount; j++) {
ItemStack pearl = handler.getStackInSlot(j);
if (!(pearl.getItem() instanceof INacreProduct))
continue;
INacreProduct product = (INacreProduct) pearl.getItem();
Function2<ItemStack, Integer, Integer> function = product.getItemColorFunction();
if (function == null)
continue;
int colorInt = function.invoke(pearl, 0);
Color color = new Color(colorInt);
// + (scrollSlot == j ? SELECTOR_SHIFT : 0);
double outerRadius = parasolGradientRadius + (slotRadii[j]);
GlStateManager.pushMatrix();
int thing1 = GL11.glGetInteger(GL11.GL_ALPHA_TEST_FUNC);
float thing2 = GL11.glGetFloat(GL11.GL_ALPHA_TEST_REF);
GlStateManager.shadeModel(GL11.GL_SMOOTH);
GlStateManager.alphaFunc(GL11.GL_ALWAYS, 1);
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
GlStateManager.disableTexture2D();
GlStateManager.translate(getGuiWidth() / 2.0, getGuiHeight() / 2.0, 0);
bb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
for (int i = 0; i < numSegmentsPerArc; i++) {
float currentAngle = i * anglePerSegment + angle;
bb.pos(innerRadius * MathHelper.cos(currentAngle), innerRadius * MathHelper.sin(currentAngle), 0).color(color.getRed(), color.getGreen(), color.getBlue(), (int) (itemDilaters[j] * 255)).endVertex();
bb.pos(innerRadius * MathHelper.cos(currentAngle + anglePerSegment), innerRadius * MathHelper.sin(currentAngle + anglePerSegment), 0).color(color.getRed(), color.getGreen(), color.getBlue(), (int) (itemDilaters[j] * 255)).endVertex();
bb.pos(outerRadius * MathHelper.cos(currentAngle + anglePerSegment), outerRadius * MathHelper.sin(currentAngle + anglePerSegment), 0).color(color.getRed(), color.getGreen(), color.getBlue(), 0).endVertex();
bb.pos(outerRadius * MathHelper.cos(currentAngle), outerRadius * MathHelper.sin(currentAngle), 0).color(color.getRed(), color.getGreen(), color.getBlue(), 0).endVertex();
}
tess.draw();
float centerAngle = angle + anglePerColor / 2;
Vec3d inner = new Vec3d(innerRadius * MathHelper.cos(centerAngle), innerRadius * MathHelper.sin(centerAngle), 0);
Vec3d outer = new Vec3d(outerRadius * MathHelper.cos(centerAngle), outerRadius * MathHelper.sin(centerAngle), 0);
Vec3d center = new Vec3d((inner.x + outer.x) / 2, (inner.y + outer.y) / 2, 0);
Vec3d normal = center.normalize();
Vec3d pearlOffset = normal.scale(radius / 2).scale(itemDilaters[j]);
// GlStateManager.translate(pearlOffset.x, pearlOffset.y, 0);
RenderUtils.renderItemStackWithOpacity(pearl, itemDilaters[j], () -> GlStateManager.translate(pearlOffset.x - 8, pearlOffset.y - 8, 0));
GlStateManager.translate(-pearlOffset.x + 8, -pearlOffset.y + 8, 0);
GlStateManager.translate(0, 0, 20);
GlStateManager.color(1f, 1f, 1f, itemDilaters[j]);
// GlStateManager.scale(2.0, 2.0, 2.0);
GlStateManager.enableTexture2D();
List<SpellRing> rings = SpellUtils.getSpellChains(pearl);
float startAngle = angle + 0.25f;
float endAngle = angle + anglePerColor - 0.25f;
float anglePerRing = (endAngle - startAngle) / (rings.size() + 1);
float size = 10;
for (int i = 0; i < rings.size(); i++) {
float currentAngle = startAngle + (i + 1) * anglePerRing;
double x = MathHelper.cos(currentAngle);
double y = MathHelper.sin(currentAngle);
Vec3d chainNormal = new Vec3d(x, y, 0).normalize();
Vec3d chainOffset = chainNormal.scale((radius / 2.0) * itemDilaters[j]).add(chainNormal.scale(size).scale(itemDilaters[j]));
List<SpellRing> allSpellRings = SpellUtils.getAllSpellRings(rings.get(i));
for (int k = 0; k < allSpellRings.size(); k++) {
SpellRing ring = allSpellRings.get(k);
ModuleInstance module = ring.getModule();
if (module == null)
continue;
Sprite moduleSprite = new Sprite(module.getIconLocation());
Vec3d moduleVec = chainOffset.add(chainNormal.scale(size * 1.5).scale(k).scale(itemDilaters[j]));
spritePlate.bind();
spritePlate.draw(0, (float) moduleVec.x - (size / 2f), (float) moduleVec.y - (size / 2f), size, size);
moduleSprite.bind();
moduleSprite.draw(0, (float) moduleVec.x - ((size - 1) / 2f), (float) moduleVec.y - ((size - 1) / 2f), size - 1, size - 1);
if (k + 1 < allSpellRings.size()) {
SpellRing linksTo = allSpellRings.get(k + 1);
ModuleInstance linksToModule = linksTo.getModule();
if (linksToModule == null)
continue;
Vec3d linksToVec = chainOffset.add(chainNormal.scale(size * 1.5).scale(k + 1).scale(itemDilaters[j]));
TableModule.drawWire(new Vec2d(moduleVec.x, moduleVec.y), new Vec2d(linksToVec.x, linksToVec.y), TableModule.getColorForModule(module.getModuleType()), TableModule.getColorForModule(linksToModule.getModuleType()));
}
}
}
GlStateManager.alphaFunc(thing1, thing2);
GlStateManager.translate(-getGuiWidth() / 2.0, -getGuiHeight() / 2.0, 0);
GlStateManager.popMatrix();
angle += anglePerColor;
}
}
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.
the class TableModule method drawComponent.
@Override
public void drawComponent(@NotNull Vec2d mousePos, float partialTicks) {
super.drawComponent(mousePos, partialTicks);
GlStateManager.color(1f, 1f, 1f, 1f);
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();
Sprite plate;
plate = isErrored() ? PLATE_HIGHLIGHTED_ERROR : (worktable.selectedModule == this ? PLATE_HIGHLIGHTED : PLATE);
Vec2d pos = Vec2d.ZERO;
GlStateManager.translate(0, 0, -20);
if (hasTag("connecting")) {
drawWire(pos.add(getSize().getX() / 2.0, getSize().getY() / 2.0), mousePos, getColorForModule(module.getModuleType()), Color.WHITE);
}
if (linksTo != null) {
Vec2d posTo = linksTo.thisPosToOtherContext(this);
drawWire(pos.add(getSize().getX() / 2.0, getSize().getY() / 2.0), posTo.add(getSize().getX() / 2.0, getSize().getY() / 2.0), getColorForModule(module.getModuleType()), getColorForModule(linksTo.getModule().getModuleType()));
}
GlStateManager.translate(0, 0, 20);
if (isErrored() || worktable.selectedModule == this || (!benign && !worktable.animationPlaying && getMouseOver() && !hasTag("connecting"))) {
GlStateManager.translate(0, 0, 80);
}
plate.bind();
plate.draw(0, 0, 0, getSize().getXf(), getSize().getYf());
float shrink = 4;
icon.bind();
icon.draw(0, shrink / 2.0f, shrink / 2.0f, getSize().getXf() - shrink, getSize().getYf() - shrink);
HashMap<ModuleInstanceModifier, Integer> modifiers = new HashMap<>();
List<ModuleInstanceModifier> modifierList = new ArrayList<>();
for (ModuleInstance module : ModuleRegistry.INSTANCE.getModules(ModuleType.MODIFIER)) {
if (!(module instanceof ModuleInstanceModifier))
continue;
if (!hasData(Integer.class, module.getNBTKey()))
continue;
modifiers.put((ModuleInstanceModifier) module, getData(Integer.class, module.getNBTKey()));
modifierList.add((ModuleInstanceModifier) module);
}
int count = modifierList.size();
for (int i = 0; i < count; i++) {
ModuleInstanceModifier modifier = modifierList.get(i);
Vec2d modSize = getSize().mul(0.75f);
float angle = (float) (i * Math.PI * 2.0 / count);
// RENDER PLATE
{
float x = (getSize().getXf() / 2f - modSize.getXf() / 2f) + MathHelper.cos(angle) * radius;
float y = (getSize().getYf() / 2f - modSize.getYf() / 2f) + MathHelper.sin(angle) * radius;
GlStateManager.pushMatrix();
GlStateManager.translate(x, y, -10);
plate.bind();
plate.draw(0, 0, 0, modSize.getXf(), modSize.getYf());
float modShrink = 4;
Sprite modICon = new Sprite(new ResourceLocation(Wizardry.MODID, "textures/gui/worktable/icons/" + modifier.getNBTKey() + ".png"));
modICon.bind();
modICon.draw(0, modShrink / 2.0f, modShrink / 2.0f, modSize.getXf() - modShrink, modSize.getYf() - modShrink);
GlStateManager.translate(-x, -y, 10);
GlStateManager.popMatrix();
}
// RENDER TEXT
{
FontRenderer font = Minecraft.getMinecraft().fontRenderer;
String txt = "x" + modifiers.get(modifier);
float txtWidth = font.getStringWidth(txt);
float txtHeight = font.FONT_HEIGHT;
float x = (getSize().getXf() / 2f - txtWidth / 2f) + MathHelper.cos(angle) * textRadius;
float y = (getSize().getYf() / 2f - txtHeight / 2f) + MathHelper.sin(angle) * textRadius;
GlStateManager.pushMatrix();
GlStateManager.translate(x, y, -15);
font.drawString(txt, 0, 0, 0x000000);
GlStateManager.color(1f, 1f, 1f, 1f);
GlStateManager.translate(-x, -y, 15);
GlStateManager.popMatrix();
}
}
if (isErrored() || worktable.selectedModule == this || (!benign && !worktable.animationPlaying && getMouseOver() && !hasTag("connecting"))) {
GlStateManager.translate(0, 0, -80);
}
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.
the class WorktableGui method syncToServer.
public void syncToServer() {
Set<CommonWorktableModule> commonModules = new HashSet<>();
for (TableModule head : getSpellHeads()) {
TableModule lastModule = head;
CommonWorktableModule lastCommonModule = new CommonWorktableModule(lastModule.hashCode(), lastModule.getModule(), lastModule.getPos(), null, new HashMap<>());
commonModules.add(lastCommonModule);
while (lastModule != null) {
if (lastModule != head) {
CommonWorktableModule commonModule = new CommonWorktableModule(lastModule.hashCode(), lastModule.getModule(), lastModule.getPos(), null, new HashMap<>());
lastCommonModule.setLinksTo(commonModule);
lastCommonModule = commonModule;
}
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());
lastCommonModule.addModifier((ModuleInstanceModifier) module, count);
}
lastModule = lastModule.getLinksTo();
}
}
int dim = Minecraft.getMinecraft().world.provider.getDimension();
PacketHandler.NETWORK.sendToServer(new PacketSyncWorktable(dim, pos, commonModules));
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.
the class WorktableGui method playSaveAnimation.
public void playSaveAnimation(@Nullable Runnable finish) {
animationPlaying = true;
resetSelectedModule();
Runnable runnable = () -> {
ComponentVoid fakePaper = new ComponentVoid(180, 19, 180, 188);
fakePaper.getTransform().setTranslateZ(100);
getMainComponents().add(fakePaper);
ComponentVoid bookIconMask = new ComponentVoid(0, -100, 180, 100);
fakePaper.add(bookIconMask);
// GRAY BACKGROUND
{
ComponentRect grayBackground = new ComponentRect(0, 0, tableComponent.getSize().getXi(), tableComponent.getSize().getYi());
grayBackground.getColor().setValue(new Color(0.05f, 0.05f, 0.05f, 0f));
grayBackground.getTransform().setTranslateZ(200);
grayBackground.BUS.hook(GuiComponentEvents.ComponentTickEvent.class, event -> {
grayBackground.getColor().setValue(new Color(0.05f, 0.05f, 0.05f, backgroundAlpha));
});
tableComponent.add(grayBackground);
KeyframeAnimation<WorktableGui> anim = new KeyframeAnimation<>(this, "backgroundAlpha");
anim.setDuration(100);
anim.setKeyframes(new Keyframe[] { new Keyframe(0, 0f, Easing.easeInOutQuint), new Keyframe(0.2f, 0.65f, Easing.easeInOutQuint), new Keyframe(0.7f, 0.65f, Easing.easeInOutQuint), new Keyframe(1f, 0f, Easing.easeInOutQuint) });
anim.setCompletion(grayBackground::invalidate);
getMainComponents().add(anim);
}
// BOOK PEAK ANIMATION
{
ComponentSprite bookIcon = new ComponentSprite(BOOK_ICON, (int) ((bookIconMask.getSize().getX() / 2.0) - 16), (int) (bookIconMask.getSize().getY() + 50), 32, 32);
bookIconMask.add(bookIcon);
bookIcon.getTransform().setTranslateZ(200);
bookIconMask.clipping.setClipToBounds(true);
bookIconMask.getTransform().setTranslateZ(250);
final Vec2d originalPos = bookIcon.getPos();
KeyframeAnimation<ComponentSprite> anim = new KeyframeAnimation<>(bookIcon, "pos.y");
anim.setDuration(120);
anim.setKeyframes(new Keyframe[] { new Keyframe(0, originalPos.getY(), Easing.linear), new Keyframe(0.4f, (bookIconMask.getSize().getY() / 2.0) - 25, Easing.easeInBack), new Keyframe(0.5f, (bookIconMask.getSize().getY() / 2.0) - 10, Easing.easeOutBack), new Keyframe(0.8f, (bookIconMask.getSize().getY() / 2.0) - 10, Easing.easeInBack), new Keyframe(1f, originalPos.getY(), Easing.easeInBack) });
anim.setCompletion(() -> {
fakePaper.invalidate();
if (finish == null)
animationPlaying = false;
else {
finish.run();
}
});
ScheduledEventAnimation animSound = new ScheduledEventAnimation(120 * 0.5f, () -> Minecraft.getMinecraft().player.playSound(ModSounds.SCRIBBLING, 1f, 1f));
bookIcon.add(anim, animSound);
}
// PAPER ITEMS ANIMATION
{
HashMap<TableModule, UUID> links = new HashMap<>();
for (GuiComponent component : paper.getChildren()) {
if (!(component instanceof TableModule))
continue;
TableModule tableModule = (TableModule) component;
TableModule fakeModule = new TableModule(this, tableModule.getModule(), false, true);
fakeModule.setPos(tableModule.getPos());
for (Object tag : tableModule.getTagList()) fakeModule.addTag(tag);
fakeModule.getTransform().setTranslateZ(230);
fakePaper.add(fakeModule);
for (ModuleInstance module : ModuleRegistry.INSTANCE.getModules(ModuleType.MODIFIER)) {
if (tableModule.hasData(Integer.class, module.getNBTKey())) {
fakeModule.setData(Integer.class, module.getNBTKey(), tableModule.getData(Integer.class, module.getNBTKey()));
}
}
UUID uuid = tableModule.getData(UUID.class, "uuid");
if (uuid != null)
fakeModule.setData(UUID.class, "uuid", uuid);
TableModule linkedModule = tableModule.getLinksTo();
if (linkedModule == null)
continue;
UUID linkTo = linkedModule.getData(UUID.class, "uuid");
if (linkTo != null)
links.put(fakeModule, linkTo);
}
for (TableModule module : links.keySet()) {
if (!links.containsKey(module))
continue;
UUID linkTo = links.get(module);
if (linkTo == null)
continue;
for (GuiComponent child : fakePaper.getChildren()) {
UUID uuid = child.getData(UUID.class, "uuid");
if (uuid == null)
continue;
if (!linkTo.equals(uuid))
continue;
if (!(child instanceof TableModule))
continue;
TableModule reverseUUIDLink = (TableModule) child;
module.setLinksTo(reverseUUIDLink);
break;
}
}
for (GuiComponent component : fakePaper.getChildren()) {
if (!(component instanceof TableModule))
continue;
TableModule fakeModule = (TableModule) component;
Vec2d random = fakeModule.getPos().add(RandUtil.nextDouble(-20, 20), RandUtil.nextDouble(-20, 20));
float delay = RandUtil.nextFloat(0.2f, 0.3f);
float dur = RandUtil.nextFloat(70, 100);
ScheduledEventAnimation animSound1 = new ScheduledEventAnimation(dur * delay, () -> Minecraft.getMinecraft().player.playSound(ModSounds.POP, 1f, 1f));
ScheduledEventAnimation animSound2 = new ScheduledEventAnimation(dur * 0.75f, () -> Minecraft.getMinecraft().player.playSound(ModSounds.WHOOSH, 1f, 1f));
KeyframeAnimation<TableModule> animX = new KeyframeAnimation<>(fakeModule, "pos.x");
animX.setDuration(dur);
animX.setKeyframes(new Keyframe[] { new Keyframe(delay, fakeModule.getPos().getX(), Easing.easeOutQuint), new Keyframe(0.45f, random.getX(), Easing.easeOutQuint), new Keyframe(0.6f, random.getX(), Easing.easeOutQuint), new Keyframe(1f, (bookIconMask.getSize().getX() / 2.0) - 8, Easing.easeInOutQuint) });
KeyframeAnimation<TableModule> animY = new KeyframeAnimation<>(fakeModule, "pos.y");
animY.setDuration(dur);
animY.setKeyframes(new Keyframe[] { new Keyframe(delay, fakeModule.getPos().getY(), Easing.easeOutQuint), new Keyframe(0.45f, random.getY(), Easing.easeOutQuint), new Keyframe(0.6f, random.getY(), Easing.easeOutQuint), new Keyframe(1f, -(bookIconMask.getSize().getY() / 2.0) - 4, Easing.easeInOutQuint) });
BasicAnimation<TableModule> animRadius = new BasicAnimation<>(fakeModule, "radius");
animRadius.setDuration(20);
animRadius.setEasing(Easing.easeOutCubic);
animRadius.setTo(0);
BasicAnimation<TableModule> animText = new BasicAnimation<>(fakeModule, "textRadius");
animText.setDuration(40);
animText.setEasing(Easing.easeOutCubic);
animText.setTo(0);
animY.setCompletion(fakeModule::invalidate);
fakeModule.add(animX, animY, animSound1, animSound2, animRadius, animText);
}
}
};
if (selectedModule != null) {
selectedModule = null;
getMainComponents().add(new ScheduledEventAnimation(5, runnable));
} else
runnable.run();
}
Aggregations