예제 #1
0
 public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
   MovingObjectPosition movingobjectposition = func_40402_a(world, entityplayer, true);
   if (movingobjectposition == null) {
     return itemstack;
   }
   if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE) {
     int i = movingobjectposition.blockX;
     int j = movingobjectposition.blockY;
     int k = movingobjectposition.blockZ;
     if (!world.canMineBlock(entityplayer, i, j, k)) {
       return itemstack;
     }
     if (!entityplayer.canPlayerEdit(i, j, k)) {
       return itemstack;
     }
     if (world.getBlockMaterial(i, j, k) == Material.water) {
       itemstack.stackSize--;
       if (itemstack.stackSize <= 0) {
         return new ItemStack(Item.potion);
       }
       if (!entityplayer.inventory.addItemStackToInventory(new ItemStack(Item.potion))) {
         entityplayer.dropPlayerItem(new ItemStack(Item.potion.shiftedIndex, 1, 0));
       }
     }
   }
   return itemstack;
 }
예제 #2
0
  /** Handles the water game logic. */
  public void onUpdate(EntityPlayer par1EntityPlayer) {
    if (par1EntityPlayer.playerTemperature.getIsHot()) {
      baseWaterExhaustionValue = baseWaterExhaustionValueWhenIsHot;
    } else {
      baseWaterExhaustionValue = baseWaterExhaustionValueNormal;
    }

    int i = par1EntityPlayer.worldObj.difficultySetting;
    prevWaterLevel = waterLevel;

    if (waterExhaustionLevel > 4F) {
      waterExhaustionLevel -= 4F;

      if (i > 0) {
        waterLevel = Math.max(waterLevel - 1, 0);
      }
    }

    if (waterLevel <= 0) {
      waterTimer++;

      if (waterTimer >= 80) {
        if (par1EntityPlayer.getHealth() > 10
            || i >= 3
            || par1EntityPlayer.getHealth() > 1 && i >= 2) {
          par1EntityPlayer.attackEntityFrom(DamageSource.dehydrated, 1);
        }

        waterTimer = 0;
      }
    } else {
      waterTimer = 0;
    }
  }
예제 #3
0
 protected void onFoodEaten(
     ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
   if (par1ItemStack.getItemDamage() > 0) {
     if (!par2World.isRemote) {
       par3EntityPlayer.addPotionEffect(new PotionEffect(Potion.regeneration.id, 600, 3));
       par3EntityPlayer.addPotionEffect(new PotionEffect(Potion.resistance.id, 6000, 0));
       par3EntityPlayer.addPotionEffect(new PotionEffect(Potion.fireResistance.id, 6000, 0));
     }
   } else {
     super.onFoodEaten(par1ItemStack, par2World, par3EntityPlayer);
   }
 }
예제 #4
0
  /**
   * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack,
   * world, entityPlayer
   */
  public ItemStack onItemRightClick(
      ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    int var4 = EntityLiving.getArmorPosition(par1ItemStack) - 1;
    ItemStack var5 = par3EntityPlayer.getCurrentArmor(var4);

    if (var5 == null) {
      par3EntityPlayer.setCurrentItemOrArmor(var4, par1ItemStack.copy());
      par1ItemStack.stackSize = 0;
    }

    return par1ItemStack;
  }
예제 #5
0
  public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack) {
    if (!par1EntityPlayer.capabilities.isCreativeMode) {
      par1EntityPlayer.addExperienceLevel(-this.anvil.maximumCost);
    }

    ContainerRepair.getRepairInputInventory(this.anvil)
        .setInventorySlotContents(0, (ItemStack) null);

    if (ContainerRepair.getStackSizeUsedInRepair(this.anvil) > 0) {
      ItemStack var3 = ContainerRepair.getRepairInputInventory(this.anvil).getStackInSlot(1);

      if (var3 != null && var3.stackSize > ContainerRepair.getStackSizeUsedInRepair(this.anvil)) {
        var3.stackSize -= ContainerRepair.getStackSizeUsedInRepair(this.anvil);
        ContainerRepair.getRepairInputInventory(this.anvil).setInventorySlotContents(1, var3);
      } else {
        ContainerRepair.getRepairInputInventory(this.anvil)
            .setInventorySlotContents(1, (ItemStack) null);
      }
    } else {
      ContainerRepair.getRepairInputInventory(this.anvil)
          .setInventorySlotContents(1, (ItemStack) null);
    }

    this.anvil.maximumCost = 0;

    if (!par1EntityPlayer.capabilities.isCreativeMode
        && !this.theWorld.isRemote
        && this.theWorld.getBlockId(this.field_82873_b, this.field_82874_c, this.field_82871_d)
            == Block.anvil.blockID
        && par1EntityPlayer.getRNG().nextFloat() < 0.12F) {
      int var6 =
          this.theWorld.getBlockMetadata(
              this.field_82873_b, this.field_82874_c, this.field_82871_d);
      int var4 = var6 & 3;
      int var5 = var6 >> 2;
      ++var5;

      if (var5 > 2) {
        this.theWorld.setBlockWithNotify(
            this.field_82873_b, this.field_82874_c, this.field_82871_d, 0);
        this.theWorld.playAuxSFX(
            1020, this.field_82873_b, this.field_82874_c, this.field_82871_d, 0);
      } else {
        this.theWorld.setBlockMetadataWithNotify(
            this.field_82873_b, this.field_82874_c, this.field_82871_d, var4 | var5 << 2);
        this.theWorld.playAuxSFX(
            1021, this.field_82873_b, this.field_82874_c, this.field_82871_d, 0);
      }
    } else if (!this.theWorld.isRemote) {
      this.theWorld.playAuxSFX(1021, this.field_82873_b, this.field_82874_c, this.field_82871_d, 0);
    }
  }
예제 #6
0
  public String getPlayerLanguage(Player player) {
    if (!(player instanceof CraftPlayer)) {
      return "en_US";
    }
    EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    try {
      Field field = entityPlayer.getClass().getDeclaredField("locale");
      field.setAccessible(true);

      return (String) field.get(entityPlayer);
    } catch (Exception e) {
      return "en_US";
    }
  }
예제 #7
0
  /** Called when the player picks up an item from an inventory slot */
  public void onPickupFromSlot(ItemStack par1ItemStack) {
    if (par1ItemStack.itemID == Item.potion.shiftedIndex && par1ItemStack.getItemDamage() > 0) {
      player.addStat(AchievementList.potion, 1);
    }

    super.onPickupFromSlot(par1ItemStack);
  }
예제 #8
0
 public void openGui(EntityPlayer player, int id, World world, int x, int y, int z) {
   if (debugGui)
     System.out.printf(
         "BaseMod.openGui: for %s with id %s in %s at (%s, %s, %s)\n",
         /*base*/ this, id, world, x, y, z);
   player.openGui(/*base*/ this, id, world, x, y, z);
 }
 public void drawScreen(int par1, int par2, float par3) {
   super.drawScreen(par1, par2, par3);
   boolean op = false; // TODO: Check if player is OP
   if (Keyboard.isKeyDown(Keyboard.KEY_O) && op) {
     player.openGui(ModUncrafting.instance, 1, worldObj, x, y, z);
   }
 }
  public boolean a_(EntityPlayer entityplayer) {
    if (!this.q.I) {
      entityplayer.a((IInventory) this);
    }

    return true;
  }
예제 #11
0
  /** Attempts to right-click use an item by the given EntityPlayer in the given World */
  public boolean tryUseItem(
      EntityPlayer par1EntityPlayer, World par2World, ItemStack par3ItemStack) {
    int var4 = par3ItemStack.stackSize;
    int var5 = par3ItemStack.getItemDamage();
    ItemStack var6 = par3ItemStack.useItemRightClick(par2World, par1EntityPlayer);

    if (var6 == par3ItemStack
        && (var6 == null
            || var6.stackSize == var4
                && var6.getMaxItemUseDuration() <= 0
                && var6.getItemDamage() == var5)) {
      return false;
    } else {
      par1EntityPlayer.inventory.mainInventory[par1EntityPlayer.inventory.currentItem] = var6;

      if (this.isCreative()) {
        var6.stackSize = var4;

        if (var6.isItemStackDamageable()) {
          var6.setItemDamage(var5);
        }
      }

      if (var6.stackSize == 0) {
        par1EntityPlayer.inventory.mainInventory[par1EntityPlayer.inventory.currentItem] = null;
      }

      if (!par1EntityPlayer.isUsingItem()) {
        ((EntityPlayerMP) par1EntityPlayer)
            .sendContainerToPlayer(par1EntityPlayer.inventoryContainer);
      }

      return true;
    }
  }
 /**
  * Copies the values from the given player into this player if boolean par2 is true. Always clones
  * Ender Chest Inventory.
  */
 public void clonePlayer(EntityPlayer p_71049_1_, boolean p_71049_2_) {
   super.clonePlayer(p_71049_1_, p_71049_2_);
   this.lastExperience = -1;
   this.lastHealth = -1.0F;
   this.lastFoodLevel = -1;
   this.destroyedItemsNetCache.addAll(((EntityPlayerMP) p_71049_1_).destroyedItemsNetCache);
 }
예제 #13
0
 public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
   MovingObjectPosition movingobjectposition = func_40402_a(world, entityplayer, true);
   if (movingobjectposition == null) {
     return itemstack;
   }
   if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE) {
     int i = movingobjectposition.blockX;
     int j = movingobjectposition.blockY;
     int k = movingobjectposition.blockZ;
     if (!world.canMineBlock(entityplayer, i, j, k)) {
       return itemstack;
     }
     if (!entityplayer.func_35190_e(i, j, k)) {
       return itemstack;
     }
     if (world.getBlockMaterial(i, j, k) == Material.water
         && world.getBlockMetadata(i, j, k) == 0
         && world.isAirBlock(i, j + 1, k)) {
       world.setBlockWithNotify(i, j + 1, k, Block.waterlily.blockID);
       if (!entityplayer.capabilities.depleteBuckets) {
         itemstack.stackSize--;
       }
     }
   }
   return itemstack;
 }
예제 #14
0
 /** Called by a player entity when they collide with an entity */
 public void onCollideWithPlayer(EntityPlayer par1EntityPlayer) {
   if (!this.m_bNotPlayerOwned) {
     if (!this.worldObj.isRemote) {
       if (this.field_70532_c == 0 && par1EntityPlayer.xpCooldown == 0) {
         par1EntityPlayer.xpCooldown = 2;
         this.worldObj.playSoundAtEntity(
             this,
             "random.orb",
             0.1F,
             0.5F * ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.8F));
         par1EntityPlayer.onItemPickup(this, 1);
         par1EntityPlayer.addExperience(this.xpValue);
         this.setDead();
       }
     }
   }
 }
 public boolean canInteractWith(EntityPlayer entityplayer) {
   if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this) {
     return false;
   }
   return entityplayer.getDistanceSq(
           (double) xCoord + 0.5D, (double) yCoord + 0.5D, (double) zCoord + 0.5D)
       <= 64D;
 }
예제 #16
0
 public boolean onItemUse(
     ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l) {
   if (l != 1) {
     return false;
   }
   if (!entityplayer.canPlayerEdit(i, j, k) || !entityplayer.canPlayerEdit(i, j + 1, k)) {
     return false;
   }
   int i1 = world.getBlockId(i, j, k);
   if (i1 == field_40438_b && world.isAirBlock(i, j + 1, k)) {
     world.setBlockWithNotify(i, j + 1, k, blockType);
     itemstack.stackSize--;
     return true;
   } else {
     return false;
   }
 }
예제 #17
0
 /** Do not make give this method the name canInteractWith because it clashes with Container */
 public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) {
   return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this
       ? false
       : par1EntityPlayer.getDistanceSq(
               (double) this.xCoord + 0.5D,
               (double) this.yCoord + 0.5D,
               (double) this.zCoord + 0.5D)
           <= 64.0D;
 }
예제 #18
0
  /**
   * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack,
   * world, entityPlayer
   */
  public ItemStack onItemRightClick(
      ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    if (par3EntityPlayer.capabilities.isCreativeMode
        || par3EntityPlayer.inventory.hasItem(Item.arrow.shiftedIndex)) {
      par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
    }

    return par1ItemStack;
  }
예제 #19
0
 public boolean onItemUse(
     ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l) {
   int i1 = world.getBlockId(i, j, k);
   if (i1 == Block.snow.blockID) {
     l = 0;
   } else if (i1 != Block.vine.blockID) {
     if (l == 0) {
       j--;
     }
     if (l == 1) {
       j++;
     }
     if (l == 2) {
       k--;
     }
     if (l == 3) {
       k++;
     }
     if (l == 4) {
       i--;
     }
     if (l == 5) {
       i++;
     }
   }
   if (itemstack.stackSize == 0) {
     return false;
   }
   if (!entityplayer.canPlayerEdit(i, j, k)) {
     return false;
   }
   if (j == world.worldYMax - 1 && Block.blocksList[blockID].blockMaterial.isSolid()) {
     return false;
   }
   if (world.canBlockBePlacedAt(blockID, i, j, k, false, l)) {
     Block block = Block.blocksList[blockID];
     if (world.setBlockAndMetadataWithNotify(
         i, j, k, blockID, getMetadata(itemstack.getItemDamage()))) {
       if (world.getBlockId(i, j, k) == blockID) {
         Block.blocksList[blockID].onBlockPlaced(world, i, j, k, l);
         Block.blocksList[blockID].onBlockPlacedBy(world, i, j, k, entityplayer);
       }
       world.playSoundEffect(
           (float) i + 0.5F,
           (float) j + 0.5F,
           (float) k + 0.5F,
           block.stepSound.stepSoundDir(),
           (block.stepSound.getVolume() + 1.0F) / 2.0F,
           block.stepSound.getPitch() * 0.8F);
       itemstack.stackSize--;
     }
     return true;
   } else {
     return false;
   }
 }
 public void onCraftGuiClosed(EntityPlayer entityplayer) {
   super.onCraftGuiClosed(entityplayer);
   for (int i = 0; i < 4; i++) {
     ItemStack itemstack = craftMatrix.getStackInSlot(i);
     if (itemstack != null) {
       entityplayer.dropPlayerItem(itemstack);
       craftMatrix.setInventorySlotContents(i, null);
     }
   }
 }
  /** Callback for when the crafting gui is closed. */
  public void onCraftGuiClosed(EntityPlayer par1EntityPlayer) {
    super.onCraftGuiClosed(par1EntityPlayer);
    this.theMerchant.setCustomer((EntityPlayer) null);
    super.onCraftGuiClosed(par1EntityPlayer);

    if (!this.theWorld.isRemote) {
      ItemStack var2 = this.merchantInventory.getStackInSlotOnClosing(0);

      if (var2 != null) {
        par1EntityPlayer.dropPlayerItem(var2);
      }

      var2 = this.merchantInventory.getStackInSlotOnClosing(1);

      if (var2 != null) {
        par1EntityPlayer.dropPlayerItem(var2);
      }
    }
  }
예제 #22
0
  public void a(EntityHuman entityhuman) {
    EnumDifficulty enumdifficulty = entityhuman.world.difficulty;

    this.e = this.foodLevel;
    if (this.exhaustionLevel > 4.0F) {
      this.exhaustionLevel -= 4.0F;
      if (this.saturationLevel > 0.0F) {
        // Alkazia - food
        this.saturationLevel = Math.max(this.saturationLevel - 0.8F, 0.0F);
      } else if (enumdifficulty != EnumDifficulty.PEACEFUL) {
        // CraftBukkit start
        org.bukkit.event.entity.FoodLevelChangeEvent event =
            org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(
                entityhuman, (int) Math.max(this.foodLevel - 0.5D, 0));

        if (!event.isCancelled()) {
          this.foodLevel = event.getFoodLevel();
        }

        ((EntityPlayer) entityhuman)
            .playerConnection.sendPacket(
                new PacketPlayOutUpdateHealth(
                    ((EntityPlayer) entityhuman).getBukkitEntity().getScaledHealth(),
                    this.foodLevel,
                    this.saturationLevel));
        // CraftBukkit end
      }
    }

    if (entityhuman.world.getGameRules().getBoolean("naturalRegeneration")
        && this.foodLevel >= 18
        && entityhuman.bP()) {
      ++this.foodTickTimer;
      if (this.foodTickTimer >= 80) {
        // CraftBukkit - added RegainReason
        entityhuman.heal(
            1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED);
        this.a(3.0F);
        this.foodTickTimer = 0;
      }
    } else if (this.foodLevel <= 0) {
      ++this.foodTickTimer;
      if (this.foodTickTimer >= 80) {
        if (entityhuman.getHealth() > 10.0F
            || enumdifficulty == EnumDifficulty.HARD
            || entityhuman.getHealth() > 1.0F && enumdifficulty == EnumDifficulty.NORMAL) {
          entityhuman.damageEntity(DamageSource.STARVE, 1.0F);
        }

        this.foodTickTimer = 0;
      }
    } else {
      this.foodTickTimer = 0;
    }
  }
  /**
   * sets the itemInUse when the use item button is clicked. Args: itemstack, int maxItemUseDuration
   */
  public void setItemInUse(ItemStack p_71008_1_, int p_71008_2_) {
    super.setItemInUse(p_71008_1_, p_71008_2_);

    if (p_71008_1_ != null
        && p_71008_1_.getItem() != null
        && p_71008_1_.getItem().getItemUseAction(p_71008_1_) == EnumAction.eat) {
      this.getServerForPlayer()
          .getEntityTracker()
          .func_151248_b(this, new S0BPacketAnimation(this, 3));
    }
  }
예제 #24
0
  public boolean func_77648_a(
      ItemStack par1ItemStack,
      EntityPlayer par2EntityPlayer,
      World par3World,
      int par4,
      int par5,
      int par6,
      int par7,
      float par8,
      float par9,
      float par10) {
    if (par7 != 1) {
      return false;
    }

    par5++;
    Block block;

    if (doorMaterial == Material.wood) {
      block = Block.doorWood;
    } else {
      block = Block.doorSteel;
    }

    if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6)
        || !par2EntityPlayer.canPlayerEdit(par4, par5 + 1, par6)) {
      return false;
    }

    if (!block.canPlaceBlockAt(par3World, par4, par5, par6)) {
      return false;
    } else {
      int i =
          MathHelper.floor_double(
                  (double) (((par2EntityPlayer.rotationYaw + 180F) * 4F) / 360F) - 0.5D)
              & 3;
      placeDoorBlock(par3World, par4, par5, par6, i, block);
      par1ItemStack.stackSize--;
      return true;
    }
  }
  /** (abstract) Protected helper method to read subclass entity data from NBT. */
  public void readEntityFromNBT(NBTTagCompound tagCompund) {
    super.readEntityFromNBT(tagCompund);

    if (tagCompund.hasKey("playerGameType", 99)) {
      if (MinecraftServer.getServer().getForceGamemode()) {
        this.theItemInWorldManager.setGameType(MinecraftServer.getServer().getGameType());
      } else {
        this.theItemInWorldManager.setGameType(
            WorldSettings.GameType.getByID(tagCompund.getInteger("playerGameType")));
      }
    }
  }
예제 #26
0
  /**
   * Activate the clicked on block, otherwise use the held item. Args: player, world, itemStack, x,
   * y, z, side, xOffset, yOffset, zOffset
   */
  public boolean activateBlockOrUseItem(
      EntityPlayer par1EntityPlayer,
      World par2World,
      ItemStack par3ItemStack,
      int par4,
      int par5,
      int par6,
      int par7,
      float par8,
      float par9,
      float par10) {
    int var11;

    if (!par1EntityPlayer.isSneaking() || par1EntityPlayer.getHeldItem() == null) {
      var11 = par2World.getBlockId(par4, par5, par6);

      if (var11 > 0
          && Block.blocksList[var11].onBlockActivated(
              par2World, par4, par5, par6, par1EntityPlayer, par7, par8, par9, par10)) {
        return true;
      }
    }

    if (par3ItemStack == null) {
      return false;
    } else if (this.isCreative()) {
      var11 = par3ItemStack.getItemDamage();
      int var12 = par3ItemStack.stackSize;
      boolean var13 =
          par3ItemStack.tryPlaceItemIntoWorld(
              par1EntityPlayer, par2World, par4, par5, par6, par7, par8, par9, par10);
      par3ItemStack.setItemDamage(var11);
      par3ItemStack.stackSize = var12;
      return var13;
    } else {
      return par3ItemStack.tryPlaceItemIntoWorld(
          par1EntityPlayer, par2World, par4, par5, par6, par7, par8, par9, par10);
    }
  }
예제 #27
0
 public boolean onItemUse(
     ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l) {
   if (l != 1) {
     return false;
   }
   j++;
   BlockBed blockbed = (BlockBed) Block.bed;
   int i1 = MathHelper.floor_double((double) ((entityplayer.rotationYaw * 4F) / 360F) + 0.5D) & 3;
   byte byte0 = 0;
   byte byte1 = 0;
   if (i1 == 0) {
     byte1 = 1;
   }
   if (i1 == 1) {
     byte0 = -1;
   }
   if (i1 == 2) {
     byte1 = -1;
   }
   if (i1 == 3) {
     byte0 = 1;
   }
   if (!entityplayer.func_35190_e(i, j, k)
       || !entityplayer.func_35190_e(i + byte0, j, k + byte1)) {
     return false;
   }
   if (world.isAirBlock(i, j, k)
       && world.isAirBlock(i + byte0, j, k + byte1)
       && world.isBlockNormalCube(i, j - 1, k)
       && world.isBlockNormalCube(i + byte0, j - 1, k + byte1)) {
     world.setBlockAndMetadataWithNotify(i, j, k, blockbed.blockID, i1);
     world.setBlockAndMetadataWithNotify(i + byte0, j, k + byte1, blockbed.blockID, i1 + 8);
     itemstack.stackSize--;
     return true;
   } else {
     return false;
   }
 }
  /**
   * Wake up the player if they're sleeping.
   *
   * @param updateWorldFlag Updates World.allPlayersSleeping on the server
   * @param setSpawn Set the (re)spawn point for the player
   */
  public void wakeUpPlayer(boolean p_70999_1_, boolean updateWorldFlag, boolean setSpawn) {
    if (this.isPlayerSleeping()) {
      this.getServerForPlayer()
          .getEntityTracker()
          .func_151248_b(this, new S0BPacketAnimation(this, 2));
    }

    super.wakeUpPlayer(p_70999_1_, updateWorldFlag, setSpawn);

    if (this.playerNetServerHandler != null) {
      this.playerNetServerHandler.setPlayerLocation(
          this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
    }
  }
예제 #29
0
  /**
   * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack,
   * world, entityPlayer
   */
  public ItemStack onItemRightClick(
      ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    MovingObjectPosition var4 =
        this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true);

    if (var4 == null) {
      return par1ItemStack;
    } else {
      if (var4.typeOfHit == EnumMovingObjectType.TILE) {
        int var5 = var4.blockX;
        int var6 = var4.blockY;
        int var7 = var4.blockZ;

        if (!par2World.canMineBlock(par3EntityPlayer, var5, var6, var7)) {
          return par1ItemStack;
        }

        if (!par3EntityPlayer.canPlayerEdit(var5, var6, var7)) {
          return par1ItemStack;
        }

        if (par2World.getBlockMaterial(var5, var6, var7) == Material.water) {
          --par1ItemStack.stackSize;

          if (par1ItemStack.stackSize <= 0) {
            return new ItemStack(Item.potion);
          }

          if (!par3EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.potion))) {
            par3EntityPlayer.dropPlayerItem(new ItemStack(Item.potion.shiftedIndex, 1, 0));
          }
        }
      }

      return par1ItemStack;
    }
  }
예제 #30
0
  /**
   * Callback for item usage. If the item does something special on right clicking, he will have one
   * of those. Return True if something happen and false if it don't. This is for ITEMS, not BLOCKS
   */
  public boolean onItemUse(
      ItemStack par1ItemStack,
      EntityPlayer par2EntityPlayer,
      World par3World,
      int par4,
      int par5,
      int par6,
      int par7,
      float par8,
      float par9,
      float par10) {
    if (par7 == 0) {
      return false;
    } else if (par7 == 1) {
      return false;
    } else {
      byte var11 = 0;

      if (par7 == 4) {
        var11 = 1;
      }

      if (par7 == 3) {
        var11 = 2;
      }

      if (par7 == 5) {
        var11 = 3;
      }

      if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6)) {
        return false;
      } else {
        EntityPainting var12 = new EntityPainting(par3World, par4, par5, par6, var11);

        if (var12.onValidSurface()) {
          if (!par3World.isRemote) {
            par3World.spawnEntityInWorld(var12);
          }

          --par1ItemStack.stackSize;
        }

        return true;
      }
    }
  }