Search in sources :

Example 26 with AMVector3

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

the class TileEntityOtherworldAura method refreshNearbyInventories.

private void refreshNearbyInventories() {
    nearbyInventories = new ArrayList<AMVector3>();
    int radius = 6;
    for (int i = -radius; i <= radius; ++i) {
        for (int j = -radius; j <= radius; ++j) {
            for (int k = -radius; k <= radius; ++k) {
                if (i == 0 && j == 0 && k == 0)
                    continue;
                TileEntity te = worldObj.getTileEntity(xCoord + i, yCoord + j, zCoord + k);
                if (te == null)
                    continue;
                if (!(te instanceof IInventory))
                    continue;
                nearbyInventories.add(new AMVector3(te));
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3)

Example 27 with AMVector3

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

the class TileEntityOtherworldAura method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    // sanity check
    if (nearbyInventories == null)
        return;
    if (watchTarget == null || !watchTarget.isCrafting()) {
        setActive(false, null);
        return;
    }
    if (helper != null && helper.isDead) {
        return;
    }
    if (!worldObj.isRemote) {
        if (PowerNodeRegistry.For(worldObj).checkPower(this, 1.25f)) {
            if (delayCounter-- <= 0) {
                if (helper == null) {
                    spawnHelper();
                }
                ItemStack next = watchTarget.getNextPlannedItem();
                if (next == null) {
                    setActive(false, null);
                    return;
                }
                if (next.getItem() == ItemsCommonProxy.essence && next.getItemDamage() > ItemsCommonProxy.essence.META_MAX) {
                    if (!this.helper.hasSearchLocation())
                        this.helper.setSearchLocationAndItem(new AMVector3(1, 1, 1), next);
                    delayCounter = 100;
                } else {
                    AMVector3 location = findInNearbyInventories(next);
                    if (location == null) {
                        // can't find it nearby - don't search again for 5 seconds (gives player time to add)
                        delayCounter = 20;
                        cantFindItem = true;
                        return;
                    } else {
                        cantFindItem = false;
                        if (!this.helper.hasSearchLocation())
                            this.helper.setSearchLocationAndItem(location, next);
                        // delay for 5s (give the helper time to get the item and toss it in)
                        delayCounter = 20;
                    }
                }
            }
            PowerNodeRegistry.For(worldObj).consumePower(this, PowerNodeRegistry.For(worldObj).getHighestPowerType(this), 1.25f);
        } else {
            if (this.helper != null)
                this.helper.unSummon();
        }
    }
}
Also used : AMVector3(am2.api.math.AMVector3) ItemStack(net.minecraft.item.ItemStack)

Example 28 with AMVector3

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

the class TileEntityParticleEmitter method setShow.

public void setShow(boolean show) {
    this.show = show;
    if (worldObj.isRemote && show) {
        forceShow = false;
        showTicks = 0;
        EntityPlayer localPlayer = AMCore.proxy.getLocalPlayer();
        if (localPlayer != null && localPlayer.inventory.getCurrentItem() != null && localPlayer.inventory.getCurrentItem().getItem() == ItemsCommonProxy.crystalWrench) {
            AMVector3 myLoc = new AMVector3(xCoord, yCoord, zCoord);
            AMVector3 playerLoc = new AMVector3(localPlayer);
            if (myLoc.distanceSqTo(playerLoc) < 64D) {
                forceShow = true;
            }
        }
    }
    int oldMeta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
    worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, show ? oldMeta & ~0x8 : oldMeta | 0x8, 2);
}
Also used : AMVector3(am2.api.math.AMVector3) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 29 with AMVector3

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

the class TileEntityParticleEmitter method updateEntity.

@Override
public void updateEntity() {
    if (worldObj.isRemote && spawnTicks++ >= spawnRate) {
        for (int i = 0; i < particleQuantity; ++i) doSpawn();
        spawnTicks = 0;
    }
    if (!show && worldObj.isRemote && ((forceShow && showTicks++ > 100) || !forceShow)) {
        showTicks = 0;
        forceShow = false;
        EntityPlayer localPlayer = AMCore.proxy.getLocalPlayer();
        if (localPlayer != null && localPlayer.inventory.getCurrentItem() != null && localPlayer.inventory.getCurrentItem().getItem() == ItemsCommonProxy.crystalWrench) {
            AMVector3 myLoc = new AMVector3(xCoord, yCoord, zCoord);
            AMVector3 playerLoc = new AMVector3(localPlayer);
            if (myLoc.distanceSqTo(playerLoc) < 64D) {
                forceShow = true;
            }
        }
        int oldMeta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
        if (forceShow) {
            this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, oldMeta & ~0x8, 2);
        } else {
            this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, oldMeta | 0x8, 2);
        }
    }
}
Also used : AMVector3(am2.api.math.AMVector3) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 30 with AMVector3

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

the class TileEntityParticleEmitter method doSpawn.

private void doSpawn() {
    if (!hasReceivedFullUpdate)
        return;
    double x = randomizeCoord(xCoord + 0.5);
    double y = randomizeCoord(yCoord + 0.5);
    double z = randomizeCoord(zCoord + 0.5);
    AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, AMParticle.particleTypes[particleType], x, y, z);
    if (particle != null) {
        particle.AddParticleController(AMCore.proxy.particleManager.createDefaultParticleController(particleBehaviour, particle, new AMVector3(x, y, z), speed, worldObj.getBlockMetadata(xCoord, yCoord, zCoord)));
        particle.setParticleAge(Math.min(Math.max(spawnRate, 10), 40));
        particle.setIgnoreMaxAge(false);
        particle.setParticleScale(particleScale);
        particle.SetParticleAlpha(particleAlpha);
        if (!defaultColor) {
            if (!randomColor)
                particle.setRGBColorF(((particleColor >> 16) & 0xFF) / 255f, ((particleColor >> 8) & 0xFF) / 255f, (particleColor & 0xFF) / 255f);
            else
                particle.setRGBColorF(worldObj.rand.nextFloat(), worldObj.rand.nextFloat(), worldObj.rand.nextFloat());
        }
    }
}
Also used : AMVector3(am2.api.math.AMVector3) AMParticle(am2.particles.AMParticle)

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