Search in sources :

Example 1 with IShapeOverrides

use of com.teamwizardry.wizardry.common.module.shapes.IShapeOverrides in project Wizardry by TeamWizardry.

the class EntitySpellProjectile method onUpdate.

@Override
public void onUpdate() {
    super.onUpdate();
    if (isDead)
        return;
    SpellRing spellRing = getSpellRing();
    SpellData spellData = getSpellData();
    if (spellRing == null || spellData == null) {
        setDead();
        world.removeEntity(this);
        return;
    }
    if (world.isRemote && doesRender()) {
        ClientRunnable.run(new ClientRunnable() {

            @Override
            @SideOnly(Side.CLIENT)
            public void runIfClient() {
                IShapeOverrides overrides = spellRing.getOverrideHandler().getConsumerInterface(IShapeOverrides.class);
                if (overrides.onRenderProjectile(world, spellData, spellRing))
                    return;
                ParticleBuilder glitter = new ParticleBuilder(10);
                glitter.setRender(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
                glitter.enableMotionCalculation();
                glitter.setCollision(true);
                glitter.setCanBounce(true);
                glitter.setColorFunction(new InterpColorHSV(spellRing.getPrimaryColor(), spellRing.getSecondaryColor()));
                glitter.setAcceleration(new Vec3d(0, -0.015, 0));
                ParticleSpawner.spawn(glitter, world, new StaticInterp<>(getPositionVector().add(new Vec3d(motionX, motionY, motionZ))), 5, 0, (aFloat, particleBuilder) -> {
                    particleBuilder.setScaleFunction(new InterpScale((float) RandUtil.nextDouble(0.3, 0.8), 0));
                    particleBuilder.setLifetime(RandUtil.nextInt(40, 60));
                    particleBuilder.addMotion(new Vec3d(RandUtil.nextDouble(-0.03, 0.03), RandUtil.nextDouble(-0.01, 0.05), RandUtil.nextDouble(-0.03, 0.03)));
                });
                glitter.disableMotionCalculation();
                glitter.setMotion(Vec3d.ZERO);
                ParticleSpawner.spawn(glitter, world, new StaticInterp<>(getPositionVector()), 5, 0, (aFloat, particleBuilder) -> {
                    particleBuilder.setScaleFunction(new InterpScale(RandUtil.nextFloat(1f, 2), 0));
                    particleBuilder.setLifetime(RandUtil.nextInt(5, 10));
                });
            }
        });
        return;
    }
    Vec3d origin = spellData.getOrigin(world);
    rotationPitch = spellData.getPitch();
    rotationYaw = spellData.getYaw();
    Vec3d look = spellData.getData(LOOK);
    if (look == null) {
        setDead();
        world.removeEntity(this);
        return;
    }
    if (origin == null || getDistance() < getDistance(origin.x, origin.y, origin.z)) {
        spellData.processBlock(getPosition(), EnumFacing.getFacingFromVector((float) look.x, (float) look.y, (float) look.z), getPositionVector());
        goBoom(spellRing, spellData);
        return;
    }
    if (collided) {
        RayTraceResult result = new RayTrace(world, look, getPositionVector(), 5).setEntityFilter(input -> input != this && !input.isEntityEqual(spellData.getCaster(world))).trace();
        spellData.processTrace(result, getPositionVector());
        goBoom(spellRing, spellData);
        return;
    }
    float speed = getSpeed();
    // MOVE //
    motionX += ((look.x * speed) - motionX);
    motionY += ((look.y * speed) - motionY);
    motionZ += ((look.z * speed) - motionZ);
    // GRAVITY
    // if (getDistanceSq(origin.x, origin.y, origin.z) > 4)
    // motionY -= gravity;
    move(MoverType.SELF, motionX, motionY, motionZ);
    List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(this, getEntityBoundingBox());
    if (!entities.isEmpty()) {
        Entity caster = spellData.getCaster(world);
        // Don't collide with other spell projectiles
        for (Entity entity : entities) {
            if (entity == caster)
                return;
            if (entity instanceof EntitySpellProjectile)
                return;
            spellData.processEntity(entity, false);
        }
        RayTraceResult result = new RayTrace(world, look, getPositionVector(), 1).setEntityFilter(input -> input != this && !input.isEntityEqual(spellData.getCaster(world))).trace();
        spellData.processTrace(result, getPositionVector());
        goBoom(spellRing, spellData);
    }
}
Also used : EntityDataManager(net.minecraft.network.datasync.EntityDataManager) InterpScale(com.teamwizardry.wizardry.api.util.interp.InterpScale) StaticInterp(com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) PacketExplode(com.teamwizardry.wizardry.common.network.PacketExplode) ParticleSpawner(com.teamwizardry.librarianlib.features.particle.ParticleSpawner) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) SpellRing(com.teamwizardry.wizardry.api.spell.SpellRing) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) SpellData(com.teamwizardry.wizardry.api.spell.SpellData) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Entity(net.minecraft.entity.Entity) PacketHandler(com.teamwizardry.librarianlib.features.network.PacketHandler) ClientRunnable(com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable) World(net.minecraft.world.World) LOOK(com.teamwizardry.wizardry.api.spell.SpellData.DefaultKeys.LOOK) Wizardry(com.teamwizardry.wizardry.Wizardry) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) EnumFacing(net.minecraft.util.EnumFacing) DataParameter(net.minecraft.network.datasync.DataParameter) IShapeOverrides(com.teamwizardry.wizardry.common.module.shapes.IShapeOverrides) InterpColorHSV(com.teamwizardry.librarianlib.features.particle.functions.InterpColorHSV) List(java.util.List) DataSerializers(net.minecraft.network.datasync.DataSerializers) NetworkRegistry(net.minecraftforge.fml.common.network.NetworkRegistry) ResourceLocation(net.minecraft.util.ResourceLocation) EntityMod(com.teamwizardry.librarianlib.features.base.entity.EntityMod) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) MoverType(net.minecraft.entity.MoverType) NBTConstants(com.teamwizardry.wizardry.api.NBTConstants) Entity(net.minecraft.entity.Entity) IShapeOverrides(com.teamwizardry.wizardry.common.module.shapes.IShapeOverrides) StaticInterp(com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp) RayTraceResult(net.minecraft.util.math.RayTraceResult) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ClientRunnable(com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) Vec3d(net.minecraft.util.math.Vec3d) SpellData(com.teamwizardry.wizardry.api.spell.SpellData) InterpColorHSV(com.teamwizardry.librarianlib.features.particle.functions.InterpColorHSV) SpellRing(com.teamwizardry.wizardry.api.spell.SpellRing) InterpScale(com.teamwizardry.wizardry.api.util.interp.InterpScale) ResourceLocation(net.minecraft.util.ResourceLocation) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace)

Aggregations

EntityMod (com.teamwizardry.librarianlib.features.base.entity.EntityMod)1 StaticInterp (com.teamwizardry.librarianlib.features.math.interpolate.StaticInterp)1 PacketHandler (com.teamwizardry.librarianlib.features.network.PacketHandler)1 ParticleBuilder (com.teamwizardry.librarianlib.features.particle.ParticleBuilder)1 ParticleSpawner (com.teamwizardry.librarianlib.features.particle.ParticleSpawner)1 InterpColorHSV (com.teamwizardry.librarianlib.features.particle.functions.InterpColorHSV)1 ClientRunnable (com.teamwizardry.librarianlib.features.utilities.client.ClientRunnable)1 Wizardry (com.teamwizardry.wizardry.Wizardry)1 NBTConstants (com.teamwizardry.wizardry.api.NBTConstants)1 SpellData (com.teamwizardry.wizardry.api.spell.SpellData)1 LOOK (com.teamwizardry.wizardry.api.spell.SpellData.DefaultKeys.LOOK)1 SpellRing (com.teamwizardry.wizardry.api.spell.SpellRing)1 RandUtil (com.teamwizardry.wizardry.api.util.RandUtil)1 RayTrace (com.teamwizardry.wizardry.api.util.RayTrace)1 InterpScale (com.teamwizardry.wizardry.api.util.interp.InterpScale)1 IShapeOverrides (com.teamwizardry.wizardry.common.module.shapes.IShapeOverrides)1 PacketExplode (com.teamwizardry.wizardry.common.network.PacketExplode)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1