Search in sources :

Example 1 with InterpBezier3D

use of com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D in project Wizardry by TeamWizardry.

the class TileManaInteracter method suckManaFrom.

public boolean suckManaFrom(TileManaInteracter interacterFrom, SuckRule suckRule) {
    if (getWizardryCap() == null || interacterFrom.getWizardryCap() == null)
        return false;
    if (!isAllowOutsideSucking() && interacterFrom.isAllowOutsideSucking())
        return false;
    if (!suckRule.condition.test(this, interacterFrom))
        return false;
    CapManager thisManager = new CapManager(getWizardryCap());
    CapManager theirManager = new CapManager(interacterFrom.getWizardryCap());
    if (thisManager.isManaFull())
        return false;
    if (theirManager.isManaEmpty())
        return false;
    if (suckRule.equalize && Math.abs(thisManager.getMana() - theirManager.getMana()) <= suckRule.idealAmount)
        return false;
    Vec3d thisPos = new Vec3d(getPos()).addVector(0.5, 0.5, 0.5);
    Vec3d theirPos = new Vec3d(interacterFrom.getPos()).addVector(0.5, 0.5, 0.5);
    // DEBUG
    // ParticleBuilder helix = new ParticleBuilder(200);
    // helix.setRender(new ResourceLocation(Wizardry.MODID, Constants.MISC.SPARKLE_BLURRED));
    // helix.setAlphaFunction(new InterpFadeInOut(0.1f, 0.1f));
    // ParticleSpawner.spawn(helix, world, new StaticInterp<>(thisPos), 1, 0, (someFloat, particleBuilder) -> {
    // particleBuilder.setColor(ColorUtils.changeColorAlpha(new Color(0xFF0000), RandUtil.nextInt(50, 200)));
    // particleBuilder.setScale(RandUtil.nextFloat(0.3f, 0.8f));
    // particleBuilder.disableRandom();
    // particleBuilder.setPositionFunction(new InterpLine(Vec3d.ZERO, theirPos.subtract(thisPos)));
    // particleBuilder.setLifetime(RandUtil.nextInt(50, 60));
    // });
    double ratio = theirManager.getMana() / thisManager.getMana();
    if (suckRule.equalize && Double.isFinite(ratio) && ratio <= 1.2)
        return false;
    if (getCachedDistanceSq(interacterFrom) > ConfigValues.networkLinkDistance * ConfigValues.networkLinkDistance)
        return false;
    if (!suckRule.ignoreTrace) {
        Vec3d thisSub = theirPos.subtract(thisPos.add(getOffset()));
        Vec3d thisNorm = thisSub.normalize();
        RayTraceResult trace = new RayTrace(world, thisNorm, thisPos.add(getOffset() == Vec3d.ZERO ? thisNorm : getOffset()), ConfigValues.networkLinkDistance * ConfigValues.networkLinkDistance).setSkipEntities(true).setIgnoreBlocksWithoutBoundingBoxes(true).trace();
        if (!trace.getBlockPos().equals(interacterFrom.getPos()))
            return false;
    }
    double amount = interacterFrom.drainMana(suckRule.idealAmount);
    if (amount <= 0)
        return false;
    thisManager.addMana(amount);
    ClientRunnable.run(new ClientRunnable() {

        @Override
        @SideOnly(Side.CLIENT)
        public void runIfClient() {
            ParticleBuilder helix = new ParticleBuilder(200);
            helix.setRender(new ResourceLocation(Wizardry.MODID, Constants.MISC.SPARKLE_BLURRED));
            helix.setAlphaFunction(new InterpFadeInOut(0.1f, 0.1f));
            ParticleSpawner.spawn(helix, world, new StaticInterp<>(new Vec3d(interacterFrom.getPos()).addVector(0.5, 1, 0.5)), 1, 0, (someFloat, particleBuilder) -> {
                particleBuilder.setColor(ColorUtils.changeColorAlpha(new Color(0x0097FF), RandUtil.nextInt(50, 200)));
                particleBuilder.setScale(RandUtil.nextFloat(0.3f, 0.8f));
                particleBuilder.setPositionFunction(new InterpBezier3D(Vec3d.ZERO, new Vec3d(getPos().subtract(interacterFrom.getPos())), new Vec3d(0, 5, 0), new Vec3d(0, -5, 0)));
                particleBuilder.setLifetime(RandUtil.nextInt(50, 60));
            });
        }
    });
    return true;
}
Also used : CapManager(com.teamwizardry.wizardry.api.capability.CapManager) java.util(java.util) InterpFadeInOut(com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut) StaticInterp(com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp) ParticleSpawner(com.teamwizardry.librarianlib.features.particle.ParticleSpawner) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) RayTraceResult(net.minecraft.util.math.RayTraceResult) BiPredicate(java.util.function.BiPredicate) Module(com.teamwizardry.librarianlib.features.saving.Module) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) ITickable(net.minecraft.util.ITickable) TilePearlHolder(com.teamwizardry.wizardry.common.tile.TilePearlHolder) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) Save(com.teamwizardry.librarianlib.features.saving.Save) Nullable(javax.annotation.Nullable) ConfigValues(com.teamwizardry.wizardry.api.ConfigValues) InterpBezier3D(com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D) TileCraftingPlate(com.teamwizardry.wizardry.common.tile.TileCraftingPlate) ClientRunnable(com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable) IWizardryCapability(com.teamwizardry.wizardry.api.capability.IWizardryCapability) Wizardry(com.teamwizardry.wizardry.Wizardry) TileMod(com.teamwizardry.librarianlib.features.base.block.tile.TileMod) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) BlockPos(net.minecraft.util.math.BlockPos) ColorUtils(com.teamwizardry.wizardry.api.util.ColorUtils) CustomWizardryCapability(com.teamwizardry.wizardry.api.capability.CustomWizardryCapability) java.awt(java.awt) ManaModule(com.teamwizardry.wizardry.api.capability.ManaModule) TileManaBattery(com.teamwizardry.wizardry.common.tile.TileManaBattery) MathHelper(net.minecraft.util.math.MathHelper) ResourceLocation(net.minecraft.util.ResourceLocation) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) Constants(com.teamwizardry.wizardry.api.Constants) RayTraceResult(net.minecraft.util.math.RayTraceResult) StaticInterp(com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ClientRunnable(com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable) InterpFadeInOut(com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) Vec3d(net.minecraft.util.math.Vec3d) CapManager(com.teamwizardry.wizardry.api.capability.CapManager) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) ResourceLocation(net.minecraft.util.ResourceLocation) InterpBezier3D(com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D)

Example 2 with InterpBezier3D

use of com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D in project Wizardry by TeamWizardry.

the class LibParticles method SHAPE_BEAM.

public static void SHAPE_BEAM(World world, Vec3d target, Vec3d origin, Color color) {
    ParticleBuilder beam = new ParticleBuilder(10);
    beam.setRender(new ResourceLocation(Wizardry.MODID, MISC.SPARKLE_BLURRED));
    beam.setAlphaFunction(new InterpFadeInOut(0.3f, 1f));
    // beam.disableRandom();
    beam.setColor(ColorUtils.shiftColorHueRandomly(color, 10));
    beam.setCollision(true);
    Vec3d look = target.subtract(origin).normalize();
    double dist = target.distanceTo(origin);
    ParticleSpawner.spawn(beam, world, new StaticInterp<>(origin), 1, 0, (aFloat1, particleBuilder1) -> {
        particleBuilder1.setPositionOffset(look.scale(RandUtil.nextDouble(0, dist)));
        particleBuilder1.setScale(RandUtil.nextFloat(0.1f, 0.5f));
        final int life = RandUtil.nextInt(50, 60);
        particleBuilder1.setLifetime(life);
        particleBuilder1.enableMotionCalculation();
        particleBuilder1.setCollision(true);
        particleBuilder1.setCanBounce(true);
        particleBuilder1.setAcceleration(new Vec3d(0, -0.03, 0));
        double radius = 2;
        double theta = 2.0f * (float) Math.PI * RandUtil.nextFloat();
        double r = radius * RandUtil.nextFloat();
        double x = r * MathHelper.cos((float) theta);
        double z = r * MathHelper.sin((float) theta);
        Vec3d dest = new Vec3d(x, RandUtil.nextDouble(-1, 2), z);
        particleBuilder1.setPositionFunction(new InterpBezier3D(Vec3d.ZERO, dest, dest.scale(2), new Vec3d(dest.x, RandUtil.nextDouble(-2, 2), dest.z)));
        particleBuilder1.setTick(particle -> {
            if (particle.getAge() >= particle.getLifetime() / RandUtil.nextDouble(2, 5)) {
                if (particle.getAcceleration().y == 0)
                    particle.setAcceleration(new Vec3d(0, RandUtil.nextDouble(-0.05, -0.01), 0));
            } else if (particle.getAcceleration().x != 0 || particle.getAcceleration().y != 0 || particle.getAcceleration().z != 0) {
                particle.setAcceleration(Vec3d.ZERO);
            }
        });
    });
    ParticleSpawner.spawn(beam, world, new StaticInterp<>(origin), 10, 0, (aFloat, particleBuilder) -> {
        particleBuilder.setTick(particle -> particle.setAcceleration(Vec3d.ZERO));
        particleBuilder.setScaleFunction(new InterpFadeInOut(0, 1f));
        particleBuilder.setAlphaFunction(new InterpFadeInOut(0.3f, 0.2f));
        particleBuilder.setScale(RandUtil.nextFloat(0.5f, 1.5f));
        particleBuilder.setLifetime(RandUtil.nextInt(10, 20));
        particleBuilder.disableMotionCalculation();
        particleBuilder.setMotion(Vec3d.ZERO);
        particleBuilder.setCanBounce(false);
        particleBuilder.setPositionOffset(Vec3d.ZERO);
        particleBuilder.setPositionFunction(new InterpLine(Vec3d.ZERO, target.subtract(origin)));
    });
}
Also used : InterpLine(com.teamwizardry.librarianlib.features.math.interpolate.position.InterpLine) ResourceLocation(net.minecraft.util.ResourceLocation) InterpBezier3D(com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D) InterpFadeInOut(com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) Vec3d(net.minecraft.util.math.Vec3d)

Example 3 with InterpBezier3D

use of com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D in project Wizardry by TeamWizardry.

the class LibParticles method COLORFUL_BATTERY_BEZIER.

public static void COLORFUL_BATTERY_BEZIER(World world, BlockPos pedestal, BlockPos center) {
    ParticleBuilder glitter = new ParticleBuilder(200);
    glitter.setRender(new ResourceLocation(Wizardry.MODID, MISC.SPARKLE_BLURRED));
    glitter.setAlphaFunction(new InterpFadeInOut(0.5f, 0.3f));
    ParticleSpawner.spawn(glitter, world, new StaticInterp<>(new Vec3d(pedestal).addVector(0.5, 1, 0.5)), 1, 0, (aFloat, particleBuilder) -> {
        glitter.setColorFunction(new InterpColorHSV(ColorUtils.changeColorAlpha(Color.BLUE, RandUtil.nextInt(100, 150)), ColorUtils.changeColorAlpha(Color.CYAN, RandUtil.nextInt(100, 150))));
        glitter.setScale(RandUtil.nextFloat());
        glitter.setPositionFunction(new InterpBezier3D(Vec3d.ZERO, new Vec3d(center.subtract(pedestal)), new Vec3d(0, 3, 0), new Vec3d(0, 5, 0)));
        glitter.setScaleFunction(new InterpScale(1, 0.4f));
        glitter.setLifetime(RandUtil.nextInt(10, 30));
    });
}
Also used : InterpColorHSV(com.teamwizardry.librarianlib.features.particle.functions.InterpColorHSV) InterpScale(com.teamwizardry.wizardry.api.util.interp.InterpScale) ResourceLocation(net.minecraft.util.ResourceLocation) InterpBezier3D(com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D) InterpFadeInOut(com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) Vec3d(net.minecraft.util.math.Vec3d)

Example 4 with InterpBezier3D

use of com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D in project Wizardry by TeamWizardry.

the class LibParticles method EFFECT_REGENERATE.

public static void EFFECT_REGENERATE(World world, @Nonnull Vec3d pos, Color color) {
    ParticleBuilder glitter = new ParticleBuilder(50);
    glitter.setColor(ColorUtils.changeColorAlpha(color, RandUtil.nextInt(200, 255)));
    glitter.setScale(1);
    glitter.setRender(new ResourceLocation(Wizardry.MODID, Constants.MISC.SPARKLE_BLURRED));
    glitter.disableRandom();
    ParticleSpawner.spawn(glitter, world, new StaticInterp<>(pos), 20, 0, (aFloat, particleBuilder) -> {
        glitter.setLifetime(RandUtil.nextInt(10, 40));
        glitter.setScale(RandUtil.nextFloat());
        glitter.setAlphaFunction(new InterpFadeInOut(0.3f, RandUtil.nextFloat()));
        double radius = 1;
        double theta = 2.0f * (float) Math.PI * RandUtil.nextFloat();
        double r = radius * RandUtil.nextFloat();
        double x = r * MathHelper.cos((float) theta);
        double z = r * MathHelper.sin((float) theta);
        Vec3d dest = new Vec3d(x, RandUtil.nextDouble(-1, 1), z);
        glitter.setPositionFunction(new InterpBezier3D(Vec3d.ZERO, dest, dest.scale(2), new Vec3d(dest.x, RandUtil.nextDouble(-2, 2), dest.z)));
    });
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) InterpBezier3D(com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D) InterpFadeInOut(com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) Vec3d(net.minecraft.util.math.Vec3d)

Example 5 with InterpBezier3D

use of com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D in project Wizardry by TeamWizardry.

the class TileCraftingPlateRenderer method render.

@Override
public void render(float partialTicks, int destroyStage, float alpha) {
    HashSet<BlockPos> errors = ((IStructure) tile.getBlockType()).getErroredBlocks(tile.getWorld(), tile.getPos());
    if (tile.revealStructure && tile.getBlockType() instanceof IStructure && !errors.isEmpty()) {
        IStructure structure = ((IStructure) tile.getBlockType());
        GlStateManager.pushMatrix();
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.enablePolygonOffset();
        GlStateManager.doPolygonOffset(1f, -0.05f);
        GlStateManager.translate(-structure.offsetToCenter().getX(), -structure.offsetToCenter().getY(), -structure.offsetToCenter().getZ());
        Minecraft mc = Minecraft.getMinecraft();
        Tessellator tes = Tessellator.getInstance();
        BufferBuilder buffer = tes.getBuffer();
        mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        for (BlockRenderLayer layer : cachedStructure.blocks.keySet()) {
            buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
            buffer.addVertexData(cachedStructure.vboCaches.get(layer));
            for (int i = 0; i < buffer.getVertexCount(); i++) {
                int idx = buffer.getColorIndex(i + 1);
                buffer.putColorRGBA(idx, 255, 255, 255, 200);
            }
            tes.draw();
        }
        GlStateManager.disablePolygonOffset();
        GlStateManager.color(1F, 1F, 1F, 1F);
        GlStateManager.enableDepth();
        GlStateManager.popMatrix();
        return;
    } else if (!tile.revealStructure && !errors.isEmpty()) {
        for (BlockPos error : errors) StructureErrorRenderer.INSTANCE.addError(error);
    }
    // render each item at its current position
    for (int i = 0; i < index; i++) {
        ItemStack stack = tile.realInventory.getHandler().getStackInSlot(i);
        LocationAndAngle locationsAndAngle = locationsAndAngles[i];
        if (!stack.isEmpty() && locationsAndAngle != null) {
            {
                GlStateManager.pushMatrix();
                GlStateManager.translate(0.5 + locationsAndAngle.location.x, 1 + locationsAndAngle.location.y, 0.5 + locationsAndAngle.location.z);
                GlStateManager.scale(0.3, 0.3, 0.3);
                GlStateManager.rotate((locationsAndAngle.randX + tile.getWorld().getTotalWorldTime()) + ClientTickHandler.getPartialTicks(), 0, 1, 0);
                GlStateManager.rotate((locationsAndAngle.randY + tile.getWorld().getTotalWorldTime()) + ClientTickHandler.getPartialTicks(), 1, 0, 0);
                GlStateManager.rotate((locationsAndAngle.randZ + tile.getWorld().getTotalWorldTime()) + ClientTickHandler.getPartialTicks(), 0, 0, 1);
                GlStateManager.enableLighting();
                GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
                RenderHelper.disableStandardItemLighting();
                Minecraft.getMinecraft().getRenderItem().renderItem(stack, TransformType.NONE);
                RenderHelper.enableStandardItemLighting();
                GlStateManager.popMatrix();
            }
            if (tile.suckingCooldown <= 0) {
                if (RandUtil.nextInt(index / 2) == 0) {
                    LibParticles.CLUSTER_DRAPE(tile.getWorld(), locationsAndAngle.location.add(new Vec3d(tile.getPos())).addVector(0.5, 0.5, 0.5));
                }
            } else {
                if (RandUtil.nextInt(index / 4) == 0) {
                    LibParticles.CRAFTING_ALTAR_CLUSTER_SUCTION(tile.getWorld(), new Vec3d(tile.getPos()).addVector(0.5, 0.75, 0.5), new InterpBezier3D(locationsAndAngle.location, new Vec3d(0, 0, 0)));
                }
            }
        }
    }
    ItemStack pearlToRender = tile.getInputPearl();
    if (pearlToRender.isEmpty()) {
        pearlToRender = tile.getOutputPearl();
        if (pearlToRender.isEmpty()) {
            pearlToRender = ItemStack.EMPTY;
        }
    }
    if (!pearlToRender.isEmpty()) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(0.5, 1, 0.5);
        GlStateManager.scale(0.4, 0.4, 0.4);
        GlStateManager.rotate((float) (tile.getWorld().getTotalWorldTime() * 10.0), 0, 1, 0);
        GlStateManager.translate(0, 0.5 + Math.sin((tile.getWorld().getTotalWorldTime() + partialTicks) / 5) / 10.0, 0);
        Minecraft.getMinecraft().getRenderItem().renderItem(pearlToRender, TransformType.NONE);
        GlStateManager.popMatrix();
    } else if (errors.isEmpty() && RandUtil.nextInt(4) == 0) {
        LibParticles.CRAFTING_ALTAR_IDLE(tile.getWorld(), new Vec3d(tile.getPos()).addVector(0.5, 0.7, 0.5));
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) InterpBezier3D(com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D) BlockPos(net.minecraft.util.math.BlockPos) IStructure(com.teamwizardry.wizardry.api.block.IStructure) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) ItemStack(net.minecraft.item.ItemStack) Minecraft(net.minecraft.client.Minecraft) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

InterpBezier3D (com.teamwizardry.librarianlib.features.math.interpolate.position.InterpBezier3D)5 Vec3d (net.minecraft.util.math.Vec3d)5 ParticleBuilder (com.teamwizardry.librarianlib.features.particle.ParticleBuilder)4 InterpFadeInOut (com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 BlockPos (net.minecraft.util.math.BlockPos)2 TileMod (com.teamwizardry.librarianlib.features.base.block.tile.TileMod)1 StaticInterp (com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp)1 InterpLine (com.teamwizardry.librarianlib.features.math.interpolate.position.InterpLine)1 ParticleSpawner (com.teamwizardry.librarianlib.features.particle.ParticleSpawner)1 InterpColorHSV (com.teamwizardry.librarianlib.features.particle.functions.InterpColorHSV)1 Module (com.teamwizardry.librarianlib.features.saving.Module)1 Save (com.teamwizardry.librarianlib.features.saving.Save)1 ClientRunnable (com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable)1 Wizardry (com.teamwizardry.wizardry.Wizardry)1 ConfigValues (com.teamwizardry.wizardry.api.ConfigValues)1 Constants (com.teamwizardry.wizardry.api.Constants)1 IStructure (com.teamwizardry.wizardry.api.block.IStructure)1 CapManager (com.teamwizardry.wizardry.api.capability.CapManager)1 CustomWizardryCapability (com.teamwizardry.wizardry.api.capability.CustomWizardryCapability)1