use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class MathUtilities method calcNewVector.
private static AMVector3 calcNewVector(float scaler, AMVector3 base) {
AMVector3 retValue = new AMVector3(base.x, base.y, base.z);
retValue.scale(scaler);
return retValue;
}
use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class AffinityHelper method onEntityLivingBase.
@SubscribeEvent
public void onEntityLivingBase(LivingUpdateEvent event) {
EntityLivingBase ent = event.entityLiving;
if (ent instanceof EntityEnderman) {
if (ent.getLastAttacker() != ent.getAITarget() && ent.getAITarget() instanceof EntityPlayer) {
AffinityData affinityData = AffinityData.For(ent.getAITarget());
float enderDepth = affinityData.getAffinityDepth(Affinity.ENDER);
if (enderDepth == 1.0f) {
ent.setRevengeTarget(null);
}
}
}
if (!(ent instanceof EntityPlayer))
return;
AffinityData affinityData = AffinityData.For(ent);
affinityData.tickDiminishingReturns();
float waterDepth = affinityData.getAffinityDepth(Affinity.WATER);
float fireDepth = affinityData.getAffinityDepth(Affinity.FIRE);
float natureDepth = affinityData.getAffinityDepth(Affinity.NATURE);
float iceDepth = affinityData.getAffinityDepth(Affinity.ICE);
float lifeDepth = affinityData.getAffinityDepth(Affinity.LIFE);
float enderDepth = affinityData.getAffinityDepth(Affinity.ENDER);
float lightningDepth = affinityData.getAffinityDepth(Affinity.LIGHTNING);
AffinityModifiers.instance.applySpeedModifiersBasedOnDepth((EntityPlayer) ent, natureDepth, iceDepth, lightningDepth);
AffinityModifiers.instance.applyHealthModifiers((EntityPlayer) ent, enderDepth, waterDepth, fireDepth, lightningDepth);
applyFulmintion((EntityPlayer) ent, lightningDepth);
if (lightningDepth >= 0.5f) {
ent.stepHeight = 1.014f;
} else if (ent.stepHeight == 1.014f) {
ent.stepHeight = 0.5f;
}
affinityData.accumulatedLifeRegen += 0.025 * lifeDepth;
if (affinityData.accumulatedLifeRegen > 1.0f) {
affinityData.accumulatedLifeRegen -= 1.0f;
ent.heal(1);
}
if (natureDepth == 1.0f) {
if (ent.worldObj.canBlockSeeTheSky((int) ent.posX, (int) ent.posY, (int) ent.posZ) && ent.worldObj.isDaytime()) {
affinityData.accumulatedHungerRegen += 0.02f;
if (affinityData.accumulatedHungerRegen > 1.0f) {
((EntityPlayer) ent).getFoodStats().addStats(1, 0.025f);
affinityData.accumulatedHungerRegen -= 1;
}
} else {
((EntityPlayer) ent).addExhaustion(0.025f);
}
if (ent.isCollidedHorizontally) {
if (!ent.isSneaking()) {
float movement = ExtendedProperties.For(ent).getIsFlipped() ? -0.25f : 0.25f;
ent.moveEntity(0, movement, 0);
ent.motionY = 0;
} else {
ent.motionY *= 0.79999999;
}
ent.fallDistance = 0;
}
}
//Ender Affinity
if (enderDepth >= 0.75f && affinityData.hasActivatedNightVision()) {
if (!ent.worldObj.isRemote && (!ent.isPotionActive(Potion.nightVision.id) || ent.getActivePotionEffect(Potion.nightVision).getDuration() <= 220)) {
ent.addPotionEffect(new PotionEffect(Potion.nightVision.id, 300, 1));
}
}
if (ent.onGround)
affinityData.setLastGroundPosition(new AMVector3(ent));
affinityData.tickCooldown();
if (ent.isInWater()) {
float earthDepth = affinityData.getAffinityDepth(Affinity.EARTH);
if (earthDepth > 0.25f && ent.motionY > -0.3f) {
ent.addVelocity(0, -0.01f * earthDepth, 0);
}
if (waterDepth > 0.5f) {
if (!ent.isPotionActive(BuffList.swiftSwim.id) || ent.getActivePotionEffect(BuffList.swiftSwim).getDuration() < 10) {
ent.addPotionEffect(new BuffEffectSwiftSwim(100, waterDepth > 0.75f ? 2 : 1));
}
}
if (waterDepth > 0.4 && ent.worldObj.rand.nextInt(20) < 4)
ent.setAir(ent.getAir() + 1);
if (!ent.worldObj.isRemote && ent.worldObj.rand.nextInt(100) < 5) {
ent.setAir(ent.getAir() + 1);
byte[] data = new AMDataWriter().add(ent.getEntityId()).add(ent.getAir()).generate();
AMNetHandler.INSTANCE.sendPacketToClientPlayer((EntityPlayerMP) ent, AMPacketIDs.SYNC_AIR_CHANGE, data);
}
boolean waterMovementFlag = false;
if ((ent instanceof EntityPlayer && ((EntityPlayer) ent).inventory.armorInventory[1] != null && ((EntityPlayer) ent).inventory.armorInventory[1].getItem() == ItemsCommonProxy.waterGuardianOrbs)) {
waterMovementFlag = true;
if (!ent.worldObj.isRemote && (!ent.isPotionActive(BuffList.waterBreathing) || ent.getActivePotionEffect(BuffList.waterBreathing).getDuration() <= 200))
ent.addPotionEffect(new BuffEffectWaterBreathing(400, 2));
}
if (waterDepth > 0.5f || waterMovementFlag) {
applyReverseWaterMovement(ent);
}
}
if (ent.worldObj.isRaining() && !ent.worldObj.isRemote && ent.worldObj.getBiomeGenForCoords((int) Math.floor(ent.posX), (int) Math.floor(ent.posZ)).canSpawnLightningBolt()) {
float airDepth = affinityData.getAffinityDepth(Affinity.AIR);
if (airDepth > 0.5f && airDepth < 0.85f && !ent.worldObj.isRemote && ent.worldObj.rand.nextInt(100) < 10) {
if (!ent.isSneaking() && !ent.isPotionActive(BuffList.gravityWell) && !ent.isInsideOfMaterial(Material.water) && ent.isWet()) {
double velX = ent.worldObj.rand.nextDouble() - 0.5;
double velY = ent.worldObj.rand.nextDouble() - 0.5;
double velZ = ent.worldObj.rand.nextDouble() - 0.5;
ent.addVelocity(velX, velY, velZ);
AMNetHandler.INSTANCE.sendVelocityAddPacket(ent.worldObj, ent, velX, velY, velZ);
}
}
}
if (ent.isSneaking()) {
if (iceDepth >= 0.5f) {
makeIceBridge((EntityPlayer) ent, iceDepth);
}
}
}
use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class AffinityHelper method makeIceBridge.
private void makeIceBridge(EntityPlayer ent, float iceDepth) {
AMVector3[] blocks = MathUtilities.GetHorizontalBlocksInFrontOfCharacter(ent, 1, (int) Math.round(ent.posX), (int) Math.floor(ent.posY) - 1, (int) Math.round(ent.posZ));
for (int i = 0; i < blocks.length; ++i) {
AMVector3 current = blocks[i];
for (int n = -1; n <= 1; ++n) {
for (int p = -1; p <= 1; ++p) {
Block block = ent.worldObj.getBlock((int) current.x + n, (int) current.y, (int) current.z + p);
if (iceDepth == 1.0f && block == Blocks.lava)
ent.worldObj.setBlock((int) current.x + n, (int) current.y, (int) current.z + p, Blocks.obsidian);
else if (iceDepth == 1.0f && block == Blocks.flowing_lava)
ent.worldObj.setBlock((int) current.x + n, (int) current.y, (int) current.z + p, Blocks.cobblestone);
else if (block == Blocks.water)
ent.worldObj.setBlock((int) current.x + n, (int) current.y, (int) current.z + p, Blocks.ice);
else if (block == Blocks.flowing_water)
ent.worldObj.setBlock((int) current.x + n, (int) current.y, (int) current.z + p, Blocks.ice);
block = ent.worldObj.getBlock((int) current.x + n, (int) current.y + 1, (int) current.z + p);
if (block == Blocks.fire) {
ent.worldObj.setBlock((int) current.x + n, (int) current.y + 1, (int) current.z + p, Blocks.air);
}
}
}
}
}
use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class TileEntityFlickerHabitat method readOutList.
private void readOutList(NBTTagCompound compound) {
//valid compound?
if (!compound.hasKey("outList"))
return;
//get the tag list for the output data
NBTTagList outputList = compound.getTagList("outList", Constants.NBT.TAG_COMPOUND);
//spin through em
for (int i = 0; i < outputList.tagCount(); ++i) {
//get the current compound tag - this should contain a priority level and a list of vectors
NBTTagCompound priorityCompound = outputList.getCompoundTagAt(i);
//create the list to hold the output locations
ArrayList<AMVector3> locationsInPriority = new ArrayList<AMVector3>();
//does the current compound tag contain the values we're looking for?
if (!priorityCompound.hasKey("priority") || !priorityCompound.hasKey("vectors")) {
LogHelper.warn("Malformed save data for flicker item transport controller - cannot process records.");
continue;
}
//get the priority from the compound
int priority = priorityCompound.getInteger("priority");
//get the list of vectors from the compound
NBTTagList vectors = priorityCompound.getTagList("vectors", Constants.NBT.TAG_COMPOUND);
//spin through the vectors
for (int x = 0; x < vectors.tagCount(); ++x) {
//get the current vector tag
NBTTagCompound vectorItem = vectors.getCompoundTagAt(x);
//read the vector from the NBT compound
AMVector3 vec = AMVector3.readFromNBT(vectorItem);
//add the vector location if it read correctly
if (vec != null && vec != AMVector3.zero()) {
locationsInPriority.add(vec);
}
}
//insert the list into the output list at the specified priority
this.outList.put(priority, locationsInPriority);
}
}
use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class TileEntityFlickerHabitat method writeOutList.
private void writeOutList(NBTTagCompound compound) {
NBTTagList outputList = new NBTTagList();
for (int priority : outList.keySet()) {
//create a compound for the priority
NBTTagCompound priorityCompound = new NBTTagCompound();
//attach the priority to the compound
priorityCompound.setInteger("priority", priority);
//get the list of locations for this priority
ArrayList<AMVector3> priorityList = outList.get(priority);
if (priorityList == null)
continue;
//create a tag list to store the vectors in
NBTTagList vectors = new NBTTagList();
//spin through the list
for (AMVector3 vec : priorityList) {
//create a compound to hold the individual vector
NBTTagCompound vectorItem = new NBTTagCompound();
//write the vector to the newly created compound
vec.writeToNBT(vectorItem);
//attach the vector tag to the vectors list
vectors.appendTag(vectorItem);
}
//attach the vectors to the priority compound
priorityCompound.setTag("vectors", vectors);
//attach the priority compound to the final output list
outputList.appendTag(priorityCompound);
}
//store the final output list in the parent compound
compound.setTag("outList", outputList);
}
Aggregations