コード例 #1
0
ファイル: EntityMySheep.java プロジェクト: EALS634/MyPet
  public boolean handlePlayerInteraction(EntityHuman entityhuman) {
    if (super.handlePlayerInteraction(entityhuman)) {
      return true;
    }

    ItemStack itemStack = entityhuman.inventory.getItemInHand();

    if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
      if (itemStack.getItem() == Items.DYE
          && itemStack.getData() <= 15
          && itemStack.getData() != getMyPet().getColor().getDyeData()
          && !getMyPet().isSheared()) {
        getMyPet().setColor(DyeColor.getByDyeData((byte) itemStack.getData()));
        if (!entityhuman.abilities.canInstantlyBuild) {
          if (--itemStack.count <= 0) {
            entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
          }
        }
        return true;
      } else if (itemStack.getItem() == Items.SHEARS
          && MySheep.CAN_BE_SHEARED
          && !getMyPet().isSheared()) {
        getMyPet().setSheared(true);
        int woolDropCount = 1 + this.random.nextInt(3);

        for (int j = 0; j < woolDropCount; ++j) {
          EntityItem entityitem =
              this.a(new ItemStack(Blocks.WOOL, 1, getMyPet().getColor().getDyeData()), 1.0F);

          entityitem.motY += (double) this.random.nextFloat() * 0.05F;
          entityitem.motX += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
          entityitem.motZ += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
        }
        makeSound("mob.sheep.shear", 1.0F, 1.0F);
        if (!entityhuman.abilities.canInstantlyBuild) {
          itemStack.damage(1, entityhuman);
        }
        return true;
      } else if (MySheep.GROW_UP_ITEM.compare(itemStack)
          && getMyPet().isBaby()
          && getOwner().getPlayer().isSneaking()) {
        if (!entityhuman.abilities.canInstantlyBuild) {
          if (--itemStack.count <= 0) {
            entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
          }
        }
        getMyPet().setBaby(false);
        return true;
      }
    }
    return false;
  }
コード例 #2
0
ファイル: ItemWorldMap.java プロジェクト: Ajking11/mc-dev
  public Packet c(ItemStack itemstack, World world, EntityHuman entityhuman) {
    byte[] abyte = this.a(itemstack, world).a(itemstack, world, entityhuman);

    return abyte == null
        ? null
        : new Packet131((short) Item.MAP.id, (short) itemstack.getData(), abyte);
  }
コード例 #3
0
ファイル: ItemSandStone.java プロジェクト: JohnTitor/mc-dev
  public String c(ItemStack itemstack) {
    int i = itemstack.getData();

    if (i < 0 || i >= BlockSandStone.a.length) {
      i = 0;
    }

    return super.getName() + "." + BlockSandStone.a[i];
  }
コード例 #4
0
ファイル: NetUtil.java プロジェクト: yawkat/MCProtocolLib
 public static void writeItem(NetOutput out, ItemStack item) throws IOException {
   if (item == null) {
     out.writeShort(-1);
   } else {
     out.writeShort(item.getId());
     out.writeByte(item.getAmount());
     out.writeShort(item.getData());
     writeNBT(out, item.getNBT());
   }
 }
コード例 #5
0
ファイル: ItemWorldMap.java プロジェクト: Ajking11/mc-dev
  public WorldMap a(ItemStack itemstack, World world) {

    WorldMap worldmap = (WorldMap) world.a(WorldMap.class, "map_" + itemstack.getData());

    if (worldmap == null) {
      itemstack.b(world.b("map"));
      String s = "map_" + itemstack.getData();

      worldmap = new WorldMap(s);
      worldmap.b = world.r().c();
      worldmap.c = world.r().e();
      worldmap.e = 3;
      worldmap.map = (byte) world.worldProvider.dimension;
      worldmap.a();
      world.a(s, (WorldMapBase) worldmap);
    }

    return worldmap;
  }
コード例 #6
0
ファイル: ItemWorldMap.java プロジェクト: Ajking11/mc-dev
  public void d(ItemStack itemstack, World world, EntityHuman entityhuman) {
    itemstack.b(world.b("map"));
    String s = "map_" + itemstack.getData();
    WorldMap worldmap = new WorldMap(s);

    world.a(s, (WorldMapBase) worldmap);
    worldmap.b = MathHelper.floor(entityhuman.locX);
    worldmap.c = MathHelper.floor(entityhuman.locZ);
    worldmap.e = 3;
    worldmap.map = (byte) world.worldProvider.dimension;
    worldmap.a();
  }
コード例 #7
0
ファイル: ItemBlock.java プロジェクト: CasperGrey/MineCraft
  public boolean interactWith(
      ItemStack itemstack,
      EntityHuman entityhuman,
      World world,
      BlockPosition blockposition,
      EnumDirection enumdirection,
      float f,
      float f1,
      float f2) {
    IBlockData iblockdata = world.getType(blockposition);
    Block block = iblockdata.getBlock();

    if (!block.a(world, blockposition)) {
      blockposition = blockposition.shift(enumdirection);
    }

    if (itemstack.count == 0) {
      return false;
    } else if (!entityhuman.a(blockposition, enumdirection, itemstack)) {
      return false;
    } else if (world.a(this.a, blockposition, false, enumdirection, (Entity) null, itemstack)) {
      int i = this.filterData(itemstack.getData());
      IBlockData iblockdata1 =
          this.a.getPlacedState(world, blockposition, enumdirection, f, f1, f2, i, entityhuman);

      if (world.setTypeAndData(blockposition, iblockdata1, 3)) {
        iblockdata1 = world.getType(blockposition);
        if (iblockdata1.getBlock() == this.a) {
          a(world, entityhuman, blockposition, itemstack);
          this.a.postPlace(world, blockposition, iblockdata1, entityhuman, itemstack);
        }

        world.makeSound(
            (double) ((float) blockposition.getX() + 0.5F),
            (double) ((float) blockposition.getY() + 0.5F),
            (double) ((float) blockposition.getZ() + 0.5F),
            this.a.stepSound.getPlaceSound(),
            (this.a.stepSound.getVolume1() + 1.0F) / 2.0F,
            this.a.stepSound.getVolume2() * 0.8F);
        --itemstack.count;
      }

      return true;
    } else {
      return false;
    }
  }
コード例 #8
0
ファイル: ItemBlock.java プロジェクト: DaMarine/Alkazia
  public boolean interactWith(
      ItemStack itemstack,
      EntityHuman entityhuman,
      World world,
      int i,
      int j,
      int k,
      int l,
      float f,
      float f1,
      float f2) {
    final int clickedX = i, clickedY = j, clickedZ = k; // CraftBukkit
    Block block = world.getType(i, j, k);

    if (block == Blocks.SNOW && (world.getData(i, j, k) & 7) < 1) {
      l = 1;
    } else if (block != Blocks.VINE && block != Blocks.LONG_GRASS && block != Blocks.DEAD_BUSH) {
      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.count == 0) {
      return false;
    } else if (!entityhuman.a(i, j, k, l, itemstack)) {
      return false;
    } else if (j == 255 && this.block.getMaterial().isBuildable()) {
      return false;
    } else if (world.mayPlace(this.block, i, j, k, false, l, entityhuman, itemstack)) {
      int i1 = this.filterData(itemstack.getData());
      int j1 = this.block.getPlacedData(world, i, j, k, l, f, f1, f2, i1);

      // CraftBukkit start - Redirect to common function handler
      /*
      if (world.setTypeAndData(i, j, k, this.block, j1, 3)) {
          if (world.getType(i, j, k) == this.block) {
              this.block.postPlace(world, i, j, k, entityhuman, itemstack);
              this.block.postPlace(world, i, j, k, j1);
          }

          world.makeSound((double) ((float) i + 0.5F), (double) ((float) j + 0.5F), (double) ((float) k + 0.5F), this.block.stepSound.getPlaceSound(), (this.block.stepSound.getVolume1() + 1.0F) / 2.0F, this.block.stepSound.getVolume2() * 0.8F);
          --itemstack.count;
      }

      return true;
      */
      return processBlockPlace(
          world, entityhuman, itemstack, i, j, k, this.block, j1, clickedX, clickedY, clickedZ);
      // CraftBukkit end
    } else {
      return false;
    }
  }
コード例 #9
0
ファイル: VAnvil.java プロジェクト: vanZeben/VirtualPack
 public void #FIELD_CONTAINERANVIL_4#()
 {
     ItemStack itemstack = VAnvil.#FIELD_CONTAINERANVIL_1#(this).getItem(0);
     #FIELD_CONTAINERANVIL_5# = 0;
     int i = 0;
     byte b0 = 0;
     int j = 0;
     if(itemstack == null)
     {
         getInv("#FIELD_CONTAINERANVIL_2#").setItem(0, null);
         #FIELD_CONTAINERANVIL_5# = 0;
     }
     else
     {
         ItemStack itemstack1 = itemstack.cloneItemStack();
         ItemStack itemstack2 = VAnvil.#FIELD_CONTAINERANVIL_1#(this).getItem(1);
         Map map = EnchantmentManager.#FIELD_ENCHANTMENTMANAGER_3#(itemstack1);
         boolean flag = false;
         int k = b0 + itemstack.getRepairCost() + (itemstack2 == null ? 0 : itemstack2.getRepairCost());
         _exp = 0;
         int l;
         int i1;
         int j1;
         int k1;
         int l1;
         Iterator iterator;
         Enchantment enchantment;
         if(itemstack2 != null)
         {
             flag = itemstack2.id == Item.ENCHANTED_BOOK.id && Item.ENCHANTED_BOOK.#FIELD_ITEMENCHANTEDBOOK_2#(itemstack2).size() > 0;
             if(itemstack1.#FIELD_ITEM_6#() && Item.byId[itemstack1.id].a(itemstack, itemstack2))
             {
                 l = Math.min(itemstack1.#FIELD_ITEMSTACK_5#(), itemstack1.#FIELD_ITEMSTACK_6#() / 4);
                 if(l <= 0)
                 {
                     getInv("#FIELD_CONTAINERANVIL_2#").setItem(0, null);
                     #FIELD_CONTAINERANVIL_5# = 0;
                     return;
                 }
                 for(i1 = 0; l > 0 && i1 < itemstack2.count; ++i1)
                 {
                     j1 = itemstack1.#FIELD_ITEMSTACK_5#() - l;
                     itemstack1.setData(j1);
                     i += Math.max(1, l / 100) + map.size();
                     l = Math.min(itemstack1.#FIELD_ITEMSTACK_5#(), itemstack1.#FIELD_ITEMSTACK_6#() / 4);
                 }
                 _exp = i1;
             }
             else
             {
                 if(!flag && (itemstack1.id != itemstack2.id || !itemstack1.#FIELD_ITEM_6#()))
                 {
                     getInv("#FIELD_CONTAINERANVIL_2#").setItem(0, null);
                     #FIELD_CONTAINERANVIL_5# = 0;
                     return;
                 }
                 if(itemstack1.#FIELD_ITEM_6#() && !flag)
                 {
                     l = itemstack.#FIELD_ITEMSTACK_6#() - itemstack.#FIELD_ITEMSTACK_5#();
                     i1 = itemstack2.#FIELD_ITEMSTACK_6#() - itemstack2.#FIELD_ITEMSTACK_5#();
                     j1 = i1 + itemstack1.#FIELD_ITEMSTACK_6#() * 12 / 100;
                     int i2 = l + j1;
                     k1 = itemstack1.#FIELD_ITEMSTACK_6#() - i2;
                     if(k1 < 0)
                     {
                         k1 = 0;
                     }
                     if(k1 < itemstack1.getData())
                     {
                         itemstack1.setData(k1);
                         i += Math.max(1, j1 / 100);
                     }
                 }
                 Map map1 = EnchantmentManager.#FIELD_ENCHANTMENTMANAGER_3#(itemstack2);
                 iterator = map1.keySet().iterator();
                 while(iterator.hasNext())
                 {
                     j1 = ((Integer)iterator.next()).intValue();
                     enchantment = Enchantment.byId[j1];
                     k1 = map.containsKey(Integer.valueOf(j1)) ? ((Integer)map.get(Integer.valueOf(j1))).intValue() : 0;
                     l1 = ((Integer)map1.get(Integer.valueOf(j1))).intValue();
                     int j2;
                     if(k1 == l1)
                     {
                         ++l1;
                         j2 = l1;
                     }
                     else
                     {
                         j2 = Math.max(l1, k1);
                     }
                     l1 = j2;
                     int k2 = l1 - k1;
                     boolean flag1 = enchantment.canEnchant(itemstack);
                     if(playerFree(_player))
                     {
                         flag1 = true;
                     }
                     Iterator iterator1 = map.keySet().iterator();
                     while(iterator1.hasNext())
                     {
                         int l2 = ((Integer)iterator1.next()).intValue();
                         if(l2 != j1 && !enchantment.#FIELD_ENCHANTMENT_1#(Enchantment.byId[l2]))
                         {
                             flag1 = false;
                             i += k2;
                         }
                     }
                     if(flag1)
                     {
                         if(l1 > enchantment.getMaxLevel())
                         {
                             l1 = enchantment.getMaxLevel();
                         }
                         map.put(Integer.valueOf(j1), Integer.valueOf(l1));
                         int i3 = 0;
                         switch(enchantment.getRandomWeight())
                         {
                             case 1:
                                 i3 = 8;
                                 break;
                             case 2:
                                 i3 = 4;
                             case 3:
                             case 4:
                             case 6:
                             case 7:
                             case 8:
                             case 9:
                             default:
                                 break;
                             case 5:
                                 i3 = 2;
                                 break;
                             case 10:
                                 i3 = 1;
                         }
                         i += i3 * k2;
                     }
                 }
             }
         }
         if(_itemName != null && !_itemName.equalsIgnoreCase(itemstack.#FIELD_ITEMSTACK_7#()) && _itemName.length() > 0)
         {
             j = itemstack.#FIELD_ITEM_6#() ? 7 : itemstack.count * 5;
             i += j;
             if(itemstack.#FIELD_ITEMSTACK_8#())
             {
                 k += j / 2;
             }
             itemstack1.#FIELD_ITEMSTACK_9#(_itemName);
         }
         l = 0;
         for(iterator = map.keySet().iterator(); iterator.hasNext(); k += l + k1 * l1)
         {
             j1 = ((Integer)iterator.next()).intValue();
             enchantment = Enchantment.byId[j1];
             k1 = ((Integer)map.get(Integer.valueOf(j1))).intValue();
             l1 = 0;
             ++l;
             switch(enchantment.getRandomWeight())
             {
                 case 1:
                     l1 = 8;
                     break;
                 case 2:
                     l1 = 4;
                 case 3:
                 case 4:
                 case 6:
                 case 7:
                 case 8:
                 case 9:
                 default:
                     break;
                 case 5:
                     l1 = 2;
                     break;
                 case 10:
                     l1 = 1;
             }
             if(flag)
             {
                 l1 = Math.max(1, l1 / 2);
             }
         }
         if(flag)
         {
             k = Math.max(1, k / 2);
         }
         #FIELD_CONTAINERANVIL_5# = k + i;
         if(i <= 0)
         {
             itemstack1 = null;
         }
         if(j == i && j > 0 && #FIELD_CONTAINERANVIL_5# >= 40)
         {
             #FIELD_CONTAINERANVIL_5# = 39;
         }
         if(#FIELD_CONTAINERANVIL_5# >= 40 && !playerFree(_player))
         {
             itemstack1 = null;
         }
         if(itemstack1 != null)
         {
             i1 = itemstack1.getRepairCost();
             if(itemstack2 != null && i1 < itemstack2.getRepairCost())
             {
                 i1 = itemstack2.getRepairCost();
             }
             if(itemstack1.#FIELD_ITEMSTACK_8#())
             {
                 i1 -= 9;
             }
             if(i1 < 0)
             {
                 i1 = 0;
             }
             i1 += 2;
             itemstack1.setRepairCost(i1);
             EnchantmentManager.#FIELD_ENCHANTMENTMANAGER_4#(map, itemstack1);
         }
         getInv("#FIELD_CONTAINERANVIL_2#").setItem(0, itemstack1);
         #FIELD_CONTAINER_9#();
     }
 }