use of net.minecraft.util.EntityDamageSource in project SimplyJetpacks by Tonius.
the class Jetpack method flyUser.
public void flyUser(EntityLivingBase user, ItemStack stack, ItemPack item, boolean force) {
if (this.isOn(stack)) {
boolean hoverMode = this.isHoverModeOn(stack);
double hoverSpeed = Config.invertHoverSneakingBehavior == SyncHandler.isDescendKeyDown(user) ? this.speedVerticalHoverSlow : this.speedVerticalHover;
boolean flyKeyDown = force || SyncHandler.isFlyKeyDown(user);
boolean descendKeyDown = SyncHandler.isDescendKeyDown(user);
double currentAccel = this.accelVertical * (user.motionY < 0.3D ? 2.5D : 1.0D);
double currentSpeedVertical = this.speedVertical * (user.isInWater() ? 0.4D : 1.0D);
if (flyKeyDown || hoverMode && !user.onGround) {
if (this.usesFuel) {
item.useFuel(stack, (int) (user.isSprinting() ? Math.round(this.getFuelUsage(stack) * this.sprintFuelModifier) : this.getFuelUsage(stack)), false);
}
if (item.getFuelStored(stack) > 0) {
if (flyKeyDown) {
if (!hoverMode) {
user.motionY = Math.min(user.motionY + currentAccel, currentSpeedVertical);
} else {
if (descendKeyDown) {
user.motionY = Math.min(user.motionY + currentAccel, -this.speedVerticalHoverSlow);
} else {
user.motionY = Math.min(user.motionY + currentAccel, this.speedVerticalHover);
}
}
} else {
user.motionY = Math.min(user.motionY + currentAccel, -hoverSpeed);
}
float speedSideways = (float) (user.isSneaking() ? this.speedSideways * 0.5F : this.speedSideways);
float speedForward = (float) (user.isSprinting() ? speedSideways * this.sprintSpeedModifier : speedSideways);
if (SyncHandler.isForwardKeyDown(user)) {
user.moveFlying(0, speedForward, speedForward);
}
if (SyncHandler.isBackwardKeyDown(user)) {
user.moveFlying(0, -speedSideways, speedSideways * 0.8F);
}
if (SyncHandler.isLeftKeyDown(user)) {
user.moveFlying(speedSideways, 0, speedSideways);
}
if (SyncHandler.isRightKeyDown(user)) {
user.moveFlying(-speedSideways, 0, speedSideways);
}
if (!user.worldObj.isRemote) {
user.fallDistance = 0.0F;
if (user instanceof EntityPlayerMP) {
((EntityPlayerMP) user).playerNetServerHandler.floatingTickCount = 0;
}
if (Config.flammableFluidsExplode) {
if (!(user instanceof EntityPlayer) || !((EntityPlayer) user).capabilities.isCreativeMode) {
int x = Math.round((float) user.posX - 0.5F);
int y = Math.round((float) user.posY);
int z = Math.round((float) user.posZ - 0.5F);
Block fluidBlock = user.worldObj.getBlock(x, y, z);
if (fluidBlock instanceof IFluidBlock && fluidBlock.isFlammable(user.worldObj, x, y, z, ForgeDirection.UNKNOWN)) {
user.worldObj.playSoundAtEntity(user, "mob.ghast.fireball", 2.0F, 1.0F);
user.worldObj.createExplosion(user, user.posX, user.posY, user.posZ, 3.5F, false);
user.attackEntityFrom(new EntityDamageSource("jetpackexplode", user), 100.0F);
}
}
}
}
}
}
}
if (!user.worldObj.isRemote && this.emergencyHoverMode && this.isEHoverOn(stack)) {
if (item.getEnergyStored(stack) > 0 && (!this.isHoverModeOn(stack) || !this.isOn(stack))) {
if (user.posY < -5) {
this.doEHover(stack, user);
} else if (user instanceof EntityPlayer) {
if (!((EntityPlayer) user).capabilities.isCreativeMode && user.fallDistance - 1.2F >= user.getHealth()) {
for (int i = 0; i <= 16; i++) {
int x = Math.round((float) user.posX - 0.5F);
int y = Math.round((float) user.posY) - i;
int z = Math.round((float) user.posZ - 0.5F);
if (!user.worldObj.isAirBlock(x, y, z)) {
this.doEHover(stack, user);
break;
}
}
}
}
}
}
}
use of net.minecraft.util.EntityDamageSource in project SimplyJetpacks by Tonius.
the class JetpackPotato method flyUser.
@Override
public void flyUser(EntityLivingBase user, ItemStack stack, ItemPack item, boolean force) {
if (this.isFired(stack)) {
super.flyUser(user, stack, item, true);
user.rotationYawHead += 37.5F;
if (item.getFuelStored(stack) <= 0) {
user.setCurrentItemOrArmor(3, null);
if (!user.worldObj.isRemote) {
user.worldObj.createExplosion(user, user.posX, user.posY, user.posZ, 4.0F, false);
for (int i = 0; i <= MathHelper.RANDOM.nextInt(3) + 4; i++) {
ItemStack firework = FireworksHelper.getRandomFireworks(0, 1, MathHelper.RANDOM.nextInt(6) + 1, 1);
user.worldObj.spawnEntityInWorld(new EntityFireworkRocket(user.worldObj, user.posX + MathHelper.RANDOM.nextDouble() * 6.0D - 3.0D, user.posY, user.posZ + MathHelper.RANDOM.nextDouble() * 6.0D - 3.0D, firework));
}
user.attackEntityFrom(new EntityDamageSource("jetpackpotato", user), 100.0F);
if (user instanceof EntityPlayer) {
user.dropItem(Items.baked_potato, 1);
}
}
}
} else {
if (force || SyncHandler.isFlyKeyDown(user)) {
if (this.isTimerSet(stack)) {
this.decrementTimer(stack, user);
} else {
this.setTimer(stack, 50);
}
}
}
}
use of net.minecraft.util.EntityDamageSource in project Trains-In-Motion-1.7.10 by EternalBlueFlame.
the class HitboxHandler method getCollision.
/**
* <h3>Process Entity Collision for train</h3>
* this checks an area for blocks and other entities and returns true if there is something in that area besides what is supposed to be, (mounted players and bogies).
*/
public boolean getCollision(GenericRailTransport transport) {
//Be sure the transport has hitboxes
for (int iteration = 0; iteration < transport.getHitboxPositions().length; iteration++) {
double[] position = RailUtility.rotatePoint(new double[] { transport.getHitboxPositions()[iteration], 0, 0 }, transport.rotationPitch, transport.rotationYaw, 0);
if (hitboxList.size() <= iteration || transport.ticksExisted == 0) {
hitboxList.add(new MultipartHitbox(transport, transport, position[0] + transport.posX, position[1] + transport.posY, position[2] + transport.posZ));
transport.worldObj.spawnEntityInWorld(hitboxList.get(iteration));
} else {
hitboxList.get(iteration).setLocationAndAngles(position[0] + transport.posX, position[1] + transport.posY, position[2] + transport.posZ, transport.rotationYaw, transport.rotationPitch);
}
}
//initialize the variables before the loop to save some CPU
int k1;
int l1;
int i2;
int l;
int i1;
int j1;
List list;
Entity entity;
double[][] vectorCache = new double[2][3];
//detect collisions with blocks on X, Y, and Z.
for (MultipartHitbox box : hitboxList) {
//define the values as temporary variables first since it will be faster than flooring the variable every loop check
k1 = MathHelper.floor_double(box.boundingBox.minX);
l1 = MathHelper.floor_double(box.boundingBox.minY);
i2 = MathHelper.floor_double(box.boundingBox.minZ);
l = MathHelper.floor_double(box.boundingBox.maxX);
i1 = MathHelper.floor_double(box.boundingBox.maxY);
j1 = MathHelper.floor_double(box.boundingBox.maxZ);
/*
* check if the chunk exists, then loop for X, Y, and Z to check for a rail or an air block.
* if one isnt found return true to stop the movement.
* @see GenericRailTransport#onUpdate()
*/
if (transport.worldObj.checkChunksExist(k1, l1, i2, l, i1, j1)) {
for (; k1 <= l; ++k1) {
for (; l1 <= i1; ++l1) {
for (; i2 <= j1; ++i2) {
if (!(transport.worldObj.getBlock(k1, l1, i2) instanceof BlockAir) && !RailUtility.isRailBlockAt(transport.worldObj, k1, l1, i2)) {
return true;
}
}
}
}
}
/*
* detect collision with entities.
* we have to create a temporary bounding box that's larger than the current so we can check just a bit past the current box, this gives collision events a bit more time to react.
* from there we create a list of entities in the new hitbox, and then loop through them to figure out what happens, we can't use the list directly due to concurrent modifications.
*/
list = transport.worldObj.getEntitiesWithinAABBExcludingEntity(transport, box.boundingBox.copy().expand(0.35, 0, 0.35));
if (list != null && list.size() > 0) {
for (Object obj : list) {
/*cast the entity ahead of time, so we don't need to cast it over and over later.*/
if (obj instanceof Entity) {
entity = (Entity) obj;
} else {
continue;
}
/*if it's something we don't collide with, skip to next iteration.*/
if (entity instanceof EntityBogie || entity instanceof GenericRailTransport || entity.ridingEntity instanceof EntitySeat || entity.ridingEntity instanceof GenericRailTransport || hitboxList.contains(entity)) {
continue;
}
/*if it's an item, check if we should add it to the inventory, maybe do it, and continue to the next iteration*/
if (entity instanceof EntityItem) {
if (transport.getType().isHopper() && transport.isItemValidForSlot(0, ((EntityItem) entity).getEntityItem()) && ((EntityItem) entity).posY > transport.posY + 1) {
transport.addItem(((EntityItem) entity).getEntityItem());
((EntityItem) entity).worldObj.removeEntity((EntityItem) entity);
}
continue;
}
/*if the parent is an Entity Rollingstock, and the other checks were false, we now need to check if we roadkill the entity, or get pushed by it.*/
if (transport instanceof EntityRollingStockCore) {
if (transport.frontBogie.motionX > 0.5 || transport.frontBogie.motionX < -0.5 || transport.frontBogie.motionZ > 0.5 || transport.frontBogie.motionZ < -0.5) {
//in the case of roadkill
entity.attackEntityFrom(new EntityDamageSource("rollingstock", transport), (float) (transport.frontBogie.motionX + transport.frontBogie.motionZ) * 1000);
if (transport.worldObj.isRemote) {
entity.applyEntityCollision(transport);
}
} else {
vectorCache[0][0] = entity.posX - transport.posX;
vectorCache[0][2] = entity.posZ - transport.posZ;
vectorCache[0][1] = MathHelper.sqrt_double(vectorCache[0][0] * vectorCache[0][0] + vectorCache[0][2] * vectorCache[0][2]);
if (vectorCache[0][1] >= 0.00999999987D) {
vectorCache[0][0] /= vectorCache[0][1];
vectorCache[0][2] /= vectorCache[0][1];
vectorCache[0][0] *= 1.0D / vectorCache[0][1];
vectorCache[0][2] *= 1.0D / vectorCache[0][1];
vectorCache[0][0] *= 0.05000000074444445D;
vectorCache[0][2] *= 0.05000000074444445D;
transport.frontBogie.addVelocity(-vectorCache[0][0], 0.0D, -vectorCache[0][2]);
transport.backBogie.addVelocity(-vectorCache[0][0], 0.0D, -vectorCache[0][2]);
}
entity.applyEntityCollision(transport);
}
/*however if this was n entity Train Core, we just have to figure out if we should roadkill it.*/
} else if (transport.frontVelocityX > 0.5 || transport.frontVelocityX < -0.5 || transport.frontVelocityZ > 0.5 || transport.frontVelocityZ < -0.5) {
entity.attackEntityFrom(new EntityDamageSource("train", transport), (float) (transport.frontVelocityX + transport.frontVelocityZ) * 1000);
if (transport.worldObj.isRemote) {
entity.applyEntityCollision(transport);
}
} else {
boolean bool = rand.nextBoolean();
vectorCache[0][0] = bool ? 0.05 : 0;
vectorCache[0][2] = bool ? 0 : 0.05;
vectorCache[1] = RailUtility.rotatePoint(vectorCache[0], 0, transport.rotationYaw, 0);
entity.addVelocity(vectorCache[0][0], -0.5, vectorCache[0][2]);
entity.applyEntityCollision(transport);
}
}
}
}
//returning true stops the transport, false lets it move.
return false;
}
use of net.minecraft.util.EntityDamageSource in project ArsMagica2 by Mithion.
the class DamageSources method causeEntityMagicDamage.
public static DamageSource causeEntityMagicDamage(EntityLivingBase source) {
DamageSource ds = new EntityDamageSource("magic", source);
ds.setMagicDamage();
setDamageSourceUnblockable(ds);
return ds;
}
use of net.minecraft.util.EntityDamageSource in project BluePower by Qmunity.
the class BPEventHandler method onEntityAttack.
@SubscribeEvent
public void onEntityAttack(LivingAttackEvent event) {
if (!isAttacking && event.source instanceof EntityDamageSource) {
// this event will be trigger recursively by EntityLiving#attackEntityFrom,
// so we need to stop the loop.
EntityDamageSource entitySource = (EntityDamageSource) event.source;
if (entitySource.getEntity() instanceof EntityPlayer) {
EntityPlayer killer = (EntityPlayer) entitySource.getEntity();
if (killer.inventory.getCurrentItem() != null) {
if (EnchantmentHelper.getEnchantments(killer.inventory.getCurrentItem()).containsKey(BPEnchantments.disjunction.effectId)) {
if (event.entityLiving instanceof EntityEnderman || event.entityLiving instanceof EntityDragon) {
int level = EnchantmentHelper.getEnchantmentLevel(BPEnchantments.disjunction.effectId, killer.inventory.getCurrentItem());
isAttacking = true;
event.entityLiving.attackEntityFrom(event.source, event.ammount * (level * 0.5F + 1));
isAttacking = false;
event.setCanceled(true);
}
}
}
}
}
}
Aggregations