Search in sources :

Example 1 with EntityBombCart

use of icbm.classic.content.entity.EntityBombCart in project ICBM-Classic by BuiltBrokenModding.

the class ItemDefuser method onLeftClickEntity.

/**
     * Called when the player Left Clicks (attacks) an entity. Processed before damage is done, if
     * return value is true further processing is canceled and the entity is not attacked.
     *
     * @param itemStack The Item being used
     * @param player    The player that is attacking
     * @param entity    The entity being attacked
     * @return True to cancel the rest of the interaction.
     */
@Override
public boolean onLeftClickEntity(ItemStack itemStack, EntityPlayer player, Entity entity) {
    if (this.getEnergy(itemStack) >= ENERGY_COST) {
        if (entity instanceof EntityExplosive) {
            if (!entity.worldObj.isRemote) {
                EntityExplosive entityTNT = (EntityExplosive) entity;
                EntityItem entityItem = new EntityItem(entity.worldObj, entity.posX, entity.posY, entity.posZ, new ItemStack(ICBMClassic.blockExplosive, 1, entityTNT.explosiveID.ordinal()));
                float var13 = 0.05F;
                Random random = new Random();
                entityItem.motionX = ((float) random.nextGaussian() * var13);
                entityItem.motionY = ((float) random.nextGaussian() * var13 + 0.2F);
                entityItem.motionZ = ((float) random.nextGaussian() * var13);
                entity.worldObj.spawnEntityInWorld(entityItem);
            }
            entity.setDead();
        } else if (entity instanceof EntityTNTPrimed) {
            if (!entity.worldObj.isRemote) {
                EntityItem entityItem = new EntityItem(entity.worldObj, entity.posX, entity.posY, entity.posZ, new ItemStack(Blocks.tnt));
                float var13 = 0.05F;
                Random random = new Random();
                entityItem.motionX = ((float) random.nextGaussian() * var13);
                entityItem.motionY = ((float) random.nextGaussian() * var13 + 0.2F);
                entityItem.motionZ = ((float) random.nextGaussian() * var13);
                entity.worldObj.spawnEntityInWorld(entityItem);
            }
            entity.setDead();
        } else if (entity instanceof EntityBombCart) {
            ((EntityBombCart) entity).killMinecart(DamageSource.generic);
        }
        this.discharge(itemStack, ENERGY_COST, true);
        return true;
    } else {
        player.addChatMessage(new ChatComponentText(LanguageUtility.getLocal("message.defuser.nopower")));
    }
    return false;
}
Also used : EntityBombCart(icbm.classic.content.entity.EntityBombCart) Random(java.util.Random) EntityTNTPrimed(net.minecraft.entity.item.EntityTNTPrimed) EntityExplosive(icbm.classic.content.entity.EntityExplosive) ItemStack(net.minecraft.item.ItemStack) ChatComponentText(net.minecraft.util.ChatComponentText) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

EntityBombCart (icbm.classic.content.entity.EntityBombCart)1 EntityExplosive (icbm.classic.content.entity.EntityExplosive)1 Random (java.util.Random)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityTNTPrimed (net.minecraft.entity.item.EntityTNTPrimed)1 ItemStack (net.minecraft.item.ItemStack)1 ChatComponentText (net.minecraft.util.ChatComponentText)1