use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class Recall method handleRitualReagents.
private boolean handleRitualReagents(ItemStack[] ritualRunes, World world, int x, int y, int z, EntityLivingBase caster, Entity target) {
boolean hasVinteumDust = false;
for (ItemStack stack : ritualRunes) {
if (stack.getItem() == ItemsCommonProxy.itemOre && stack.getItemDamage() == ItemsCommonProxy.itemOre.META_VINTEUMDUST) {
hasVinteumDust = true;
break;
}
}
if (!hasVinteumDust && ritualRunes.length == 3) {
long key = KeystoneUtilities.instance.getKeyFromRunes(ritualRunes);
AMVector3 vector = AMCore.proxy.blocks.getNextKeystonePortalLocation(world, x, y, z, false, key);
if (vector == null || vector.equals(new AMVector3(x, y, z))) {
if (caster instanceof EntityPlayer && !world.isRemote)
((EntityPlayer) caster).addChatMessage(new ChatComponentText(StatCollector.translateToLocal("am2.tooltip.noMatchingGate")));
return false;
} else {
RitualShapeHelper.instance.consumeRitualReagents(this, world, x, y, z);
RitualShapeHelper.instance.consumeRitualShape(this, world, x, y, z);
((EntityLivingBase) target).setPositionAndUpdate(vector.x, vector.y - target.height, vector.z);
return true;
}
} else if (hasVinteumDust) {
ArrayList<ItemStack> copy = new ArrayList<ItemStack>();
for (ItemStack stack : ritualRunes) {
if (stack.getItem() == ItemsCommonProxy.rune && stack.getItemDamage() <= 16) {
copy.add(stack);
}
}
ItemStack[] newRunes = copy.toArray(new ItemStack[copy.size()]);
long key = KeystoneUtilities.instance.getKeyFromRunes(newRunes);
EntityPlayer player = EntityUtilities.getPlayerForCombo(world, (int) key);
if (player == null) {
if (caster instanceof EntityPlayer && !world.isRemote)
((EntityPlayer) caster).addChatMessage(new ChatComponentText("am2.tooltip.noMatchingPlayer"));
return false;
} else if (player == caster) {
if (caster instanceof EntityPlayer && !world.isRemote)
((EntityPlayer) caster).addChatMessage(new ChatComponentText("am2.tooltip.cantSummonSelf"));
return false;
} else {
RitualShapeHelper.instance.consumeRitualReagents(this, world, x, y, z);
if (target.worldObj.provider.dimensionId != caster.worldObj.provider.dimensionId) {
DimensionUtilities.doDimensionTransfer(player, caster.worldObj.provider.dimensionId);
}
((EntityLivingBase) target).setPositionAndUpdate(x, y, z);
return true;
}
}
return false;
}
use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class TileEntitySlipstreamGenerator method updateEntity.
@Override
public void updateEntity() {
super.updateEntity();
if (updateTicks++ > 10) {
refreshPlayerList();
updateTicks = 0;
if (worldObj.isRemote && levitatingEntities.size() > 0)
AMNetHandler.INSTANCE.sendPowerRequestToServer(new AMVector3(this));
}
Iterator<EntityPlayer> it = levitatingEntities.iterator();
while (it.hasNext()) {
EntityPlayer player = it.next();
if (!playerIsValid(player)) {
it.remove();
continue;
}
if (PowerNodeRegistry.For(this.worldObj).getHighestPower(this) >= 0.25f) {
player.motionY *= 0.5999999;
if (Math.abs(player.motionY) < 0.2) {
player.addVelocity(0, -player.motionY, 0);
player.fallDistance = 0f;
} else {
player.fallDistance--;
}
if (!player.isSneaking()) {
float pitch = player.rotationPitch;
float factor = (pitch > 0 ? (pitch - 10) : (pitch + 10)) / -180.0f;
if (Math.abs(pitch) > 10f) {
player.moveEntity(0, factor, 0);
}
}
if (worldObj.isRemote)
spawnParticles(player);
PowerNodeRegistry.For(this.worldObj).consumePower(this, PowerNodeRegistry.For(this.worldObj).getHighestPowerType(this), 0.25f);
}
}
}
use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class TileEntityKeystoneRecepticle method doTeleport.
private void doTeleport(Entity entity) {
deactivate();
AMVector3 newLocation = AMCore.instance.proxy.blocks.getNextKeystonePortalLocation(this.worldObj, xCoord, yCoord, zCoord, false, this.key);
AMVector3 myLocation = new AMVector3(xCoord, yCoord, zCoord);
double distance = myLocation.distanceTo(newLocation);
float essenceCost = (float) (Math.pow(distance, 2) * 0.00175f);
int meta = worldObj.getBlockMetadata((int) newLocation.x, (int) newLocation.y, (int) newLocation.z);
if (AMCore.config.getHazardousGateways()) {
//uh-oh! Not enough power! The teleporter will still send you though, but I wonder where...
float charge = PowerNodeRegistry.For(this.worldObj).getHighestPower(this);
if (charge < essenceCost) {
essenceCost = charge;
//get the distance that our charge *will* take us towards the next point
double distanceWeCanGo = MathHelper.sqrt_double(charge / 0.00175);
//get the angle between the 2 vectors
double deltaZ = newLocation.z - myLocation.z;
double deltaX = newLocation.x - myLocation.x;
double angleH = Math.atan2(deltaZ, deltaX);
//interpolate the distance at that angle - this is the new position
double newX = myLocation.x + (Math.cos(angleH) * distanceWeCanGo);
double newZ = myLocation.z + (Math.sin(angleH) * distanceWeCanGo);
double newY = myLocation.y;
while (worldObj.isAirBlock((int) newX, (int) newY, (int) newZ)) {
newY++;
}
newLocation = new AMVector3(newX, newY, newZ);
}
} else {
this.worldObj.playSoundEffect(newLocation.x, newLocation.y, newLocation.z, "mob.endermen.portal", 1.0F, 1.0F);
return;
}
float newRotation = 0;
switch(meta) {
case 0:
newRotation = 270;
break;
case 1:
newRotation = 180;
break;
case 2:
newRotation = 90;
break;
case 3:
newRotation = 0;
break;
}
entity.setPositionAndRotation(newLocation.x + 0.5, newLocation.y - entity.height, newLocation.z + 0.5, newRotation, entity.rotationPitch);
PowerNodeRegistry.For(this.worldObj).consumePower(this, PowerNodeRegistry.For(this.worldObj).getHighestPowerType(this), essenceCost);
this.worldObj.playSoundEffect(myLocation.x, myLocation.y, myLocation.z, "mob.endermen.portal", 1.0F, 1.0F);
this.worldObj.playSoundEffect(newLocation.x, newLocation.y, newLocation.z, "mob.endermen.portal", 1.0F, 1.0F);
}
use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class TileEntityKeystoneRecepticle method setActive.
public void setActive(long key) {
this.isActive = true;
this.key = key;
int myMeta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
if (PowerNodeRegistry.For(worldObj).getHighestPowerType(this) == PowerTypes.DARK) {
myMeta |= 8;
} else if (PowerNodeRegistry.For(worldObj).getHighestPowerType(this) == PowerTypes.LIGHT) {
myMeta |= 4;
}
if (!this.worldObj.isRemote) {
for (Object player : this.worldObj.playerEntities) {
if (player instanceof EntityPlayerMP && new AMVector3((EntityPlayerMP) player).distanceSqTo(new AMVector3(this)) <= 4096) {
((EntityPlayerMP) player).playerNetServerHandler.sendPacket(getDescriptionPacket());
}
}
} else {
worldObj.playSound(xCoord, yCoord, zCoord, "arsmagica2:misc.gateway.open", 1.0f, 1.0f, true);
}
}
use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.
the class TileEntityOtherworldAura method spawnHelper.
private void spawnHelper() {
if (helper != null || worldObj.isRemote)
return;
this.helper = new EntityShadowHelper(worldObj);
this.helper.setPosition(xCoord, yCoord + 1, zCoord);
if (this.watchTarget != null)
this.helper.setAltarTarget(watchTarget);
this.worldObj.spawnEntityInWorld(helper);
if (this.watchTarget != null) {
this.helper.setDropoffLocation(new AMVector3(watchTarget.xCoord, watchTarget.yCoord - 2, watchTarget.zCoord));
if (placedByUsername != null && !placedByUsername.isEmpty())
this.helper.setMimicUser(placedByUsername);
}
}
Aggregations