Search in sources :

Example 71 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class WaterWalking method applyEffect.

@Override
public boolean applyEffect(EntityPlayer player, World world, ItemStack stack, ImbuementApplicationTypes matchedType, Object... params) {
    Block[] blocks = new Block[4];
    AMVector3[] vectors = new AMVector3[4];
    int posY = (int) Math.floor(player.posY - player.yOffset);
    vectors[0] = new AMVector3((int) Math.floor(player.posX), posY, (int) Math.floor(player.posZ));
    vectors[1] = new AMVector3((int) Math.ceil(player.posX), posY, (int) Math.floor(player.posZ));
    vectors[2] = new AMVector3((int) Math.floor(player.posX), posY, (int) Math.ceil(player.posZ));
    vectors[3] = new AMVector3((int) Math.ceil(player.posX), posY, (int) Math.ceil(player.posZ));
    blocks[0] = world.getBlock((int) vectors[0].x, (int) vectors[0].y, (int) vectors[0].z);
    blocks[1] = world.getBlock((int) vectors[1].x, (int) vectors[1].y, (int) vectors[1].z);
    blocks[2] = world.getBlock((int) vectors[2].x, (int) vectors[2].y, (int) vectors[2].z);
    blocks[3] = world.getBlock((int) vectors[3].x, (int) vectors[3].y, (int) vectors[3].z);
    boolean onWater = false;
    int index = 0;
    for (int i = 0; i < 4 && !onWater; ++i) {
        onWater |= (blocks[i] == Blocks.flowing_water || blocks[i] == Blocks.water);
        index = i;
    }
    if (!player.isInsideOfMaterial(Material.water) && onWater && !player.isSneaking()) {
        player.fallDistance = 0;
        player.onGround = true;
        player.isAirBorne = false;
        player.isCollidedVertically = true;
        player.isCollided = true;
        if (player.motionY < 0) {
            player.motionY = 0;
        }
        if (player.worldObj.isRemote && player.ticksExisted % 5 == 0 && (Math.abs(player.motionX) > 0.1f || Math.abs(player.motionZ) > 0.1f)) {
            player.playSound("liquid.swim", 0.02f, 1.0F + (player.getRNG().nextFloat() - player.getRNG().nextFloat()) * 0.4F);
            for (float l = 0; l < 5; ++l) {
                float f5 = (player.getRNG().nextFloat() * 2.0F - 1.0F) * player.width;
                float f4 = (player.getRNG().nextFloat() * 2.0F - 1.0F) * player.width;
                player.worldObj.spawnParticle("splash", player.posX + f5, player.posY - player.yOffset, player.posZ + f4, (player.getRNG().nextFloat() - 0.5f) * 0.2f, player.getRNG().nextFloat() * 0.1f, (player.getRNG().nextFloat() - 0.5f) * 0.2f);
            }
        }
    }
    return false;
}
Also used : AMVector3(am2.api.math.AMVector3) Block(net.minecraft.block.Block)

Example 72 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class BlockInlay method onMinecartPass.

@Override
public void onMinecartPass(World world, EntityMinecart cart, int x, int y, int z) {
    if (cart == null)
        return;
    long millisSinceLastTeleport = cart.getEntityData().getLong(minecartGoldInlayKey);
    int meta = world.getBlockMetadata(x, y, z);
    if (this.material == TYPE_REDSTONE) {
        float limit = 2f;
        if (meta == 1) {
            if (cart.motionX > 0 && cart.motionX < limit)
                cart.motionX *= 1.1f;
            else if (cart.motionX < 0 && cart.motionX > -limit)
                cart.motionX *= 1.1f;
        } else if (meta == 0) {
            if (cart.motionZ > 0 && cart.motionZ < limit)
                cart.motionZ *= 1.1f;
            else if (cart.motionZ < 0 && cart.motionZ > -limit)
                cart.motionZ *= 1.1f;
        }
    } else if (this.material == TYPE_IRON) {
        if (meta == 1) {
            cart.motionX = -cart.motionX * 0.5f;
            if (cart.motionX < 0)
                cart.setPosition(x - 0.02, cart.posY, cart.posZ);
            else if (cart.motionX > 0)
                cart.setPosition(x + 1.02, cart.posY, cart.posZ);
        } else if (meta == 0) {
            cart.motionZ = -cart.motionZ * 0.5f;
            if (cart.motionZ < 0)
                cart.setPosition(cart.posX, cart.posY, z - 0.02);
            else if (cart.motionZ > 0)
                cart.setPosition(cart.posX, cart.posY, z + 1.02);
        }
    } else if (this.material == TYPE_GOLD) {
        AMVector3 teleportLocation = null;
        if (meta == 1) {
            if (cart.motionX > 0) {
                for (int i = 1; i <= 8; ++i) {
                    if (world.getBlock(x + i, y, z) == BlocksCommonProxy.goldInlay) {
                        teleportLocation = new AMVector3(x + i, y, z);
                        break;
                    }
                }
            } else if (cart.motionX < 0) {
                for (int i = 1; i <= 8; ++i) {
                    if (world.getBlock(x - i, y, z) == BlocksCommonProxy.goldInlay) {
                        teleportLocation = new AMVector3(x - i, y, z);
                        break;
                    }
                }
            }
        } else if (meta == 0) {
            if (cart.motionZ > 0) {
                for (int i = 1; i <= 8; ++i) {
                    if (world.getBlock(x, y, z + i) == BlocksCommonProxy.goldInlay) {
                        teleportLocation = new AMVector3(x, y, z + i);
                        break;
                    }
                }
            } else if (cart.motionZ < 0) {
                for (int i = 1; i <= 8; ++i) {
                    if (world.getBlock(x, y, z - i) == BlocksCommonProxy.goldInlay) {
                        teleportLocation = new AMVector3(x, y, z - i);
                        break;
                    }
                }
            }
        }
        int teleportMeta = teleportLocation != null ? world.getBlockMetadata((int) teleportLocation.x, (int) teleportLocation.x, (int) teleportLocation.z) : -1;
        long time = System.currentTimeMillis();
        boolean cooldownPassed = (time - millisSinceLastTeleport) > 5000;
        if (teleportLocation != null && (teleportMeta == 1 || teleportMeta == 0) && cooldownPassed) {
            world.playSoundEffect(teleportLocation.x, teleportLocation.y, teleportLocation.z, "mob.endermen.portal", 1.0F, 1.0F);
            world.playSoundEffect(cart.posX, cart.posY, cart.posZ, "mob.endermen.portal", 1.0F, 1.0F);
            cart.setPosition(teleportLocation.x, teleportLocation.y, teleportLocation.z);
            cart.getEntityData().setLong(minecartGoldInlayKey, time);
        }
    }
}
Also used : AMVector3(am2.api.math.AMVector3)

Example 73 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class MathUtilities method GetMovementVectorBetweenPoints.

public static AMVector3 GetMovementVectorBetweenPoints(AMVector3 from, AMVector3 to) {
    AMVector3 delta = from.sub(to);
    delta.normalize();
    return delta;
}
Also used : AMVector3(am2.api.math.AMVector3)

Example 74 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class MathUtilities method GetBlocksInFrontOfCharacter.

public static AMVector3[] GetBlocksInFrontOfCharacter(EntityLivingBase entity, int numBlocks, int x, int y, int z) {
    float speed = 0.1F;
    float factor = (float) (Math.PI / 180.0f);
    float sinYawRadians = MathHelper.sin(entity.rotationYaw * factor);
    float cosYawRadians = MathHelper.cos(entity.rotationYaw * factor);
    float sinPitchRadians = MathHelper.sin(entity.rotationPitch * factor);
    float cosPitchRadians = MathHelper.cos(entity.rotationPitch * factor);
    double motionZ = cosYawRadians * cosPitchRadians * speed;
    double motionX = -sinYawRadians * cosPitchRadians * speed;
    double motionY = -sinPitchRadians * speed;
    double curX = x;
    double curY = y;
    double curZ = z;
    float minimum = 0.01f;
    if (Math.abs(motionX) < minimum) {
        motionX = 0;
    }
    if (Math.abs(motionY) < minimum) {
        motionY = 0;
    }
    if (Math.abs(motionZ) < minimum) {
        motionZ = 0;
    }
    int lastX = x;
    int lastY = y;
    int lastZ = z;
    AMVector3[] list = new AMVector3[numBlocks];
    list[0] = new AMVector3(x, y, z);
    int count = 1;
    while (count < numBlocks) {
        curX += motionX;
        curY += motionY;
        curZ += motionZ;
        //check for deltas
        if ((int) Math.round(curX) != lastX || (int) Math.round(curY) != lastY || (int) Math.round(curZ) != lastZ) {
            lastX = (int) Math.round(curX);
            lastY = (int) Math.round(curY);
            lastZ = (int) Math.round(curZ);
            list[count++] = new AMVector3(lastX, lastY, lastZ);
        }
    }
    return list;
}
Also used : AMVector3(am2.api.math.AMVector3)

Example 75 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class MathUtilities method GetMovementVectorBetweenEntities.

public static AMVector3 GetMovementVectorBetweenEntities(Entity from, Entity to) {
    AMVector3 fromPosition = new AMVector3(from.posX, from.posY, from.posZ);
    AMVector3 toPosition = new AMVector3(to.posX, to.posY, to.posZ);
    AMVector3 delta = fromPosition.sub(toPosition);
    delta.normalize();
    return delta;
}
Also used : AMVector3(am2.api.math.AMVector3)

Aggregations

AMVector3 (am2.api.math.AMVector3)113 TileEntity (net.minecraft.tileentity.TileEntity)21 EntityPlayer (net.minecraft.entity.player.EntityPlayer)16 EntityLivingBase (net.minecraft.entity.EntityLivingBase)15 ArrayList (java.util.ArrayList)11 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)11 IPowerNode (am2.api.power.IPowerNode)10 Block (net.minecraft.block.Block)9 Entity (net.minecraft.entity.Entity)9 ItemStack (net.minecraft.item.ItemStack)9 NBTTagList (net.minecraft.nbt.NBTTagList)9 IInventory (net.minecraft.inventory.IInventory)8 PowerTypes (am2.api.power.PowerTypes)6 AMParticle (am2.particles.AMParticle)5 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)5 TileEntityCrystalMarker (am2.blocks.tileentities.TileEntityCrystalMarker)4 EntityDragonPart (net.minecraft.entity.boss.EntityDragonPart)4 TileEntityFlickerHabitat (am2.blocks.tileentities.TileEntityFlickerHabitat)3 AMDataWriter (am2.network.AMDataWriter)3 ParticleFloatUpward (am2.particles.ParticleFloatUpward)3