Search in sources :

Example 1 with EntityDamageSource

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;
                        }
                    }
                }
            }
        }
    }
}
Also used : IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EntityDamageSource(net.minecraft.util.EntityDamageSource)

Example 2 with EntityDamageSource

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);
            }
        }
    }
}
Also used : EntityFireworkRocket(net.minecraft.entity.item.EntityFireworkRocket) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityDamageSource(net.minecraft.util.EntityDamageSource)

Example 3 with EntityDamageSource

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;
}
Also used : BlockAir(net.minecraft.block.BlockAir) Entity(net.minecraft.entity.Entity) EntityDamageSource(net.minecraft.util.EntityDamageSource) ArrayList(java.util.ArrayList) List(java.util.List) EntityItem(net.minecraft.entity.item.EntityItem)

Example 4 with EntityDamageSource

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;
}
Also used : EntityDamageSource(net.minecraft.util.EntityDamageSource) DamageSource(net.minecraft.util.DamageSource) EntityDamageSource(net.minecraft.util.EntityDamageSource)

Example 5 with EntityDamageSource

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);
                    }
                }
            }
        }
    }
}
Also used : EntityDragon(net.minecraft.entity.boss.EntityDragon) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityEnderman(net.minecraft.entity.monster.EntityEnderman) EntityDamageSource(net.minecraft.util.EntityDamageSource) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

EntityDamageSource (net.minecraft.util.EntityDamageSource)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ItemStack (net.minecraft.item.ItemStack)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Block (net.minecraft.block.Block)1 BlockAir (net.minecraft.block.BlockAir)1 Entity (net.minecraft.entity.Entity)1 EntityDragon (net.minecraft.entity.boss.EntityDragon)1 EntityFireworkRocket (net.minecraft.entity.item.EntityFireworkRocket)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityEnderman (net.minecraft.entity.monster.EntityEnderman)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 DamageSource (net.minecraft.util.DamageSource)1 IFluidBlock (net.minecraftforge.fluids.IFluidBlock)1