Beispiel #1
0
 public boolean onBlockStartBreak(
     ItemStack itemstack, int x, int y, int z, EntityPlayer entityplayer) {
   World world = entityplayer.worldObj;
   if (world.isRemote) {
     return false;
   }
   int bID = world.getBlockId(x, y, z);
   int md = world.getBlockMetadata(x, y, z);
   boolean flag = true;
   boolean flag1 = true;
   if (headType == handleType) {
     flag = powers(itemstack, bID, x, y, z, world, entityplayer, md, headType);
   } else {
     if (random.nextInt(100) + 1 <= 80) {
       flag = powers(itemstack, bID, x, y, z, world, entityplayer, md, headType);
     }
     if (random.nextInt(100) + 1 <= 20) {
       flag1 = powers(itemstack, bID, x, y, z, world, entityplayer, md, handleType);
     }
   }
   if (!ForgeHooks.canHarvestBlock(Block.blocksList[bID], entityplayer, md)) {
     flag = false;
   }
   if (!flag || !flag1) {
     world.playAuxSFX(2001, x, y, z, bID + (md << 12));
     world.setBlockWithNotify(x, y, z, 0);
     onBlockDestroyed(itemstack, bID, x, y, z, entityplayer);
     return true;
   } else {
     return false;
   }
 }
Beispiel #2
0
  /** Called by a player entity when they collide with an entity */
  public void onCollideWithPlayer(EntityPlayer par1EntityPlayer) {
    if (!this.worldObj.isRemote) {
      int var2 = this.item.stackSize;

      if (delayBeforeCanPickup == 0 && !ForgeHooks.onItemPickup(par1EntityPlayer, this)) {
        FMLServerHandler.instance().notifyItemPickup(this, par1EntityPlayer);
        this.worldObj.playSoundAtEntity(
            this, "random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
        par1EntityPlayer.onItemPickup(this, var2);
        if (item.stackSize <= 0) {
          setDead();
        }
        return;
      }

      var2 = item.stackSize;

      if (this.delayBeforeCanPickup == 0
          && par1EntityPlayer.inventory.addItemStackToInventory(this.item)) {
        FMLServerHandler.instance().notifyItemPickup(this, par1EntityPlayer);
        if (this.item.itemID == Block.wood.blockID) {
          par1EntityPlayer.triggerAchievement(AchievementList.mineWood);
        }

        if (this.item.itemID == Item.leather.shiftedIndex) {
          par1EntityPlayer.triggerAchievement(AchievementList.killCow);
        }

        if (this.item.itemID == Item.diamond.shiftedIndex) {
          par1EntityPlayer.triggerAchievement(AchievementList.diamonds);
        }

        if (this.item.itemID == Item.blazeRod.shiftedIndex) {
          par1EntityPlayer.triggerAchievement(AchievementList.blazeRod);
        }

        this.worldObj.playSoundAtEntity(
            this,
            "random.pop",
            0.2F,
            ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
        par1EntityPlayer.onItemPickup(this, var2);

        if (this.item.stackSize <= 0) {
          this.setDead();
        }
      }
    }
  }
  /** Uses the currently equipped item on the specified entity. Args: entity */
  public void useCurrentItemOnEntity(Entity par1Entity) {
    if (!ForgeHooks.onEntityInteract(this, par1Entity, false)) {
      return;
    }
    if (!par1Entity.interact(this)) {
      ItemStack var2 = this.getCurrentEquippedItem();

      if (var2 != null && par1Entity instanceof EntityLiving) {
        var2.useItemOnEntity((EntityLiving) par1Entity);

        if (var2.stackSize <= 0) {
          var2.onItemDestroyedByUse(this);
          this.destroyCurrentEquippedItem();
        }
      }
    }
  }
  /** Handles a players right click */
  public boolean onPlayerRightClick(
      EntityPlayer par1EntityPlayer,
      World par2World,
      ItemStack par3ItemStack,
      int par4,
      int par5,
      int par6,
      int par7) {
    this.syncCurrentPlayItem();
    this.netClientHandler.addToSendQueue(
        new Packet15Place(par4, par5, par6, par7, par1EntityPlayer.inventory.getCurrentItem()));

    if (par3ItemStack != null
        && par3ItemStack.getItem() != null
        && par3ItemStack
            .getItem()
            .onItemUseFirst(par3ItemStack, par1EntityPlayer, par2World, par4, par5, par6, par7)) {
      return true;
    }

    int var8 = par2World.getBlockId(par4, par5, par6);

    if (var8 > 0
        && Block.blocksList[var8].blockActivated(par2World, par4, par5, par6, par1EntityPlayer)) {
      return true;
    } else if (par3ItemStack == null) {
      return false;
    } else if (this.creativeMode) {
      int var9 = par3ItemStack.getItemDamage();
      int var10 = par3ItemStack.stackSize;
      boolean var11 = par3ItemStack.useItem(par1EntityPlayer, par2World, par4, par5, par6, par7);
      par3ItemStack.setItemDamage(var9);
      par3ItemStack.stackSize = var10;
      return var11;
    } else {
      if (!par3ItemStack.useItem(par1EntityPlayer, par2World, par4, par5, par6, par7)) {
        return false;
      }
      if (par3ItemStack.stackSize <= 0) {
        ForgeHooks.onDestroyCurrentItem(par1EntityPlayer, par3ItemStack);
      }
      return true;
    }
  }
  /**
   * Attacks for the player the targeted entity with the currently equipped item. The equipped item
   * has hitEntity called on it. Args: targetEntity
   */
  public void attackTargetEntityWithCurrentItem(Entity par1Entity) {
    if (!ForgeHooks.onEntityInteract(this, par1Entity, true)) {
      return;
    }
    ItemStack stack = getCurrentEquippedItem();
    if (stack != null && stack.getItem().onLeftClickEntity(stack, this, par1Entity)) {
      return;
    }

    if (par1Entity.canAttackWithItem()) {
      int var2 = this.inventory.getDamageVsEntity(par1Entity);

      if (this.isPotionActive(Potion.damageBoost)) {
        var2 += 3 << this.getActivePotionEffect(Potion.damageBoost).getAmplifier();
      }

      if (this.isPotionActive(Potion.weakness)) {
        var2 -= 2 << this.getActivePotionEffect(Potion.weakness).getAmplifier();
      }

      int var3 = 0;
      int var4 = 0;

      if (par1Entity instanceof EntityLiving) {
        var4 =
            EnchantmentHelper.getEnchantmentModifierLiving(
                this.inventory, (EntityLiving) par1Entity);
        var3 += EnchantmentHelper.getKnockbackModifier(this.inventory, (EntityLiving) par1Entity);
      }

      if (this.isSprinting()) {
        ++var3;
      }

      if (var2 > 0 || var4 > 0) {
        boolean var5 =
            this.fallDistance > 0.0F
                && !this.onGround
                && !this.isOnLadder()
                && !this.isInWater()
                && !this.isPotionActive(Potion.blindness)
                && this.ridingEntity == null
                && par1Entity instanceof EntityLiving;

        if (var5) {
          var2 += this.rand.nextInt(var2 / 2 + 2);
        }

        var2 += var4;
        boolean var6 = par1Entity.attackEntityFrom(DamageSource.causePlayerDamage(this), var2);

        if (var6) {
          if (var3 > 0) {
            par1Entity.addVelocity(
                (double)
                    (-MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F)
                        * (float) var3
                        * 0.5F),
                0.1D,
                (double)
                    (MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F)
                        * (float) var3
                        * 0.5F));
            this.motionX *= 0.6D;
            this.motionZ *= 0.6D;
            this.setSprinting(false);
          }

          if (var5) {
            this.onCriticalHit(par1Entity);
          }

          if (var4 > 0) {
            this.onEnchantmentCritical(par1Entity);
          }

          if (var2 >= 18) {
            this.triggerAchievement(AchievementList.overkill);
          }

          this.setLastAttackingEntity(par1Entity);
        }

        ItemStack var7 = this.getCurrentEquippedItem();

        if (var7 != null && par1Entity instanceof EntityLiving) {
          var7.hitEntity((EntityLiving) par1Entity, this);

          if (var7.stackSize <= 0) {
            var7.onItemDestroyedByUse(this);
            this.destroyCurrentEquippedItem();
          }
        }

        if (par1Entity instanceof EntityLiving) {
          if (par1Entity.isEntityAlive()) {
            this.alertWolves((EntityLiving) par1Entity, true);
          }

          this.addStat(StatList.damageDealtStat, var2);
          int var8 =
              EnchantmentHelper.getFireAspectModifier(this.inventory, (EntityLiving) par1Entity);

          if (var8 > 0) {
            par1Entity.setFire(var8 * 4);
          }
        }

        this.addExhaustion(0.3F);
      }
    }
  }
 /** Destroys the currently equipped item from the player's inventory. */
 public void destroyCurrentEquippedItem() {
   ItemStack orig = inventory.getCurrentItem();
   this.inventory.setInventorySlotContents(this.inventory.currentItem, (ItemStack) null);
   ForgeHooks.onDestroyCurrentItem(this, orig);
 }
  /** puts player to sleep on specified bed if possible */
  public EnumStatus sleepInBedAt(int par1, int par2, int par3) {
    EnumStatus customSleep = ForgeHooks.sleepInBedAt(this, par1, par2, par3);
    if (customSleep != null) {
      return customSleep;
    }

    if (!this.worldObj.isRemote) {
      if (this.isPlayerSleeping() || !this.isEntityAlive()) {
        return EnumStatus.OTHER_PROBLEM;
      }

      if (!this.worldObj.worldProvider.func_48567_d()) {
        return EnumStatus.NOT_POSSIBLE_HERE;
      }

      if (this.worldObj.isDaytime()) {
        return EnumStatus.NOT_POSSIBLE_NOW;
      }

      if (Math.abs(this.posX - (double) par1) > 3.0D
          || Math.abs(this.posY - (double) par2) > 2.0D
          || Math.abs(this.posZ - (double) par3) > 3.0D) {
        return EnumStatus.TOO_FAR_AWAY;
      }

      double var4 = 8.0D;
      double var6 = 5.0D;
      List var8 =
          this.worldObj.getEntitiesWithinAABB(
              EntityMob.class,
              AxisAlignedBB.getBoundingBoxFromPool(
                  (double) par1 - var4,
                  (double) par2 - var6,
                  (double) par3 - var4,
                  (double) par1 + var4,
                  (double) par2 + var6,
                  (double) par3 + var4));

      if (!var8.isEmpty()) {
        return EnumStatus.NOT_SAFE;
      }
    }

    this.setSize(0.2F, 0.2F);
    this.yOffset = 0.2F;

    if (this.worldObj.blockExists(par1, par2, par3)) {
      int var9 = this.worldObj.getBlockMetadata(par1, par2, par3);
      int var5 = BlockBed.getDirection(var9);
      Block block = Block.blocksList[worldObj.getBlockId(par1, par2, par3)];
      if (block != null) {
        var5 = block.getBedDirection(worldObj, par1, par2, par3);
      }
      float var10 = 0.5F;
      float var7 = 0.5F;

      switch (var5) {
        case 0:
          var7 = 0.9F;
          break;
        case 1:
          var10 = 0.1F;
          break;
        case 2:
          var7 = 0.1F;
          break;
        case 3:
          var10 = 0.9F;
      }

      this.func_22059_e(var5);
      this.setPosition(
          (double) ((float) par1 + var10),
          (double) ((float) par2 + 0.9375F),
          (double) ((float) par3 + var7));
    } else {
      this.setPosition(
          (double) ((float) par1 + 0.5F),
          (double) ((float) par2 + 0.9375F),
          (double) ((float) par3 + 0.5F));
    }

    this.sleeping = true;
    this.sleepTimer = 0;
    this.playerLocation = new ChunkCoordinates(par1, par2, par3);
    this.motionX = this.motionZ = this.motionY = 0.0D;

    if (!this.worldObj.isRemote) {
      this.worldObj.updateAllPlayersSleepingFlag();
    }

    return EnumStatus.OK;
  }