Пример #1
0
  @Override
  public void c() {
    if (this.world.v() && !this.world.isStatic) {
      float f = this.c(1.0F);

      if (f > 0.5F
          && this.random.nextFloat() * 30.0F < (f - 0.4F) * 2.0F
          && this.world.l(
              MathHelper.floor(this.locX),
              MathHelper.floor(this.locY),
              MathHelper.floor(this.locZ))) {
        ItemStack itemstack = this.getEquipment(4);

        if (itemstack != null) {
          if (itemstack.g()) {
            itemstack.setData(itemstack.j() + this.random.nextInt(2));
            if (itemstack.j() >= itemstack.l()) {
              this.a(itemstack);
              this.setEquipment(4, (ItemStack) null);
            }
          }
        }
      }
    }

    if (this.world.isStatic && this.getSkeletonType() == 1) {
      this.a(0.72F, 2.34F);
    }

    super.c();
  }
Пример #2
0
  @Override
  public void d(ItemStack itemstack, World world, EntityHuman entityhuman) {
    if (itemstack.hasTag() && itemstack.getTag().getBoolean("map_is_scaling")) {
      WorldMap worldmap = Items.MAP.getSavedMap(itemstack, world);

      world =
          world.getServer().getServer().worlds.get(0); // CraftBukkit - use primary world for maps

      itemstack.setData(world.b("map"));
      WorldMap worldmap1 = new WorldMap("map_" + itemstack.getData());

      worldmap1.scale = (byte) (worldmap.scale + 1);
      if (worldmap1.scale > 4) {
        worldmap1.scale = 4;
      }

      worldmap1.centerX = worldmap.centerX;
      worldmap1.centerZ = worldmap.centerZ;
      worldmap1.map = worldmap.map;
      worldmap1.c();
      world.a("map_" + itemstack.getData(), worldmap1);

      // CraftBukkit start
      MapInitializeEvent event = new MapInitializeEvent(worldmap1.mapView);
      Bukkit.getServer().getPluginManager().callEvent(event);
      // CraftBukkit end
    }
  }
Пример #3
0
  public WorldMap getSavedMap(ItemStack itemstack, World world) {
    World worldMain =
        world
            .getServer()
            .getServer()
            .worlds
            .get(0); // CraftBukkit - store reference to primary world
    String s = "map_" + itemstack.getData();
    WorldMap worldmap =
        (WorldMap) worldMain.a(WorldMap.class, s); // CraftBukkit - use primary world for maps

    if (worldmap == null && !world.isStatic) {
      itemstack.setData(worldMain.b("map")); // CraftBukkit - use primary world for maps
      s = "map_" + itemstack.getData();
      worldmap = new WorldMap(s);
      worldmap.scale = 3;
      int i = 128 * (1 << worldmap.scale);

      worldmap.centerX = Math.round((float) world.getWorldData().c() / (float) i) * i;
      worldmap.centerZ = Math.round(world.getWorldData().e() / i) * i;
      worldmap.map =
          (byte) ((WorldServer) world).dimension; // CraftBukkit - fixes Bukkit multiworld maps
      worldmap.c();
      worldMain.a(s, worldmap); // CraftBukkit - use primary world for maps

      // CraftBukkit start
      MapInitializeEvent event = new MapInitializeEvent(worldmap.mapView);
      Bukkit.getServer().getPluginManager().callEvent(event);
      // CraftBukkit end
    }

    return worldmap;
  }
  /**
   * Sets the electricity stored.
   *
   * @param itemstack the itemstack
   * @param f the f
   */
  protected void setElectricityStored(ItemStack itemstack, float f) {
    if (itemstack.tag == null) {
      itemstack.setTag(new NBTTagCompound());
    }

    float f1 = Math.max(Math.min(f, getElectricityCapacity()), 0.0F);
    itemstack.tag.setFloat("electricity", f1);
    itemstack.setData((int) (getElectricityCapacity() - f1));
  }
 /* (non-Javadoc)
  * @see net.minecraft.server.Item#addCreativeItems(java.util.ArrayList)
  */
 public void addCreativeItems(ArrayList arraylist) {
   ItemStack itemstack = new ItemStack(this, 1);
   itemstack.setData((int) getElectricityCapacity());
   arraylist.add(itemstack);
   ItemStack itemstack1 = new ItemStack(this, 1);
   setElectricityStored(
       itemstack1, ((ItemElectric) itemstack1.getItem()).getElectricityCapacity());
   arraylist.add(itemstack1);
 }
 /**
  * Gets the electricity stored.
  *
  * @param itemstack the itemstack
  * @return the electricity stored
  */
 protected float getElectricityStored(ItemStack itemstack) {
   if (itemstack.tag == null) {
     return 0.0F;
   } else {
     float f = itemstack.tag.getFloat("electricity");
     itemstack.setData((int) (getElectricityCapacity() - f));
     return f;
   }
 }
 /**
  * Called when item is crafted/smelted. Used only by maps so far.
  *
  * @param itemstack the itemstack
  * @param world the world
  * @param entityhuman the entityhuman
  */
 public void d(ItemStack itemstack, World world, EntityHuman entityhuman) {
   itemstack.setData((int) getElectricityCapacity());
 }
 /**
  * Gets the charged item stack.
  *
  * @return the charged item stack
  */
 public ItemStack getChargedItemStack() {
   ItemStack itemstack = new ItemStack(this);
   itemstack.setData((int) getElectricityCapacity());
   return itemstack;
 }
Пример #9
0
  public void e() {
    ItemStack itemstack = this.g.getItem(0);

    this.a = 0;
    int i = 0;
    byte b0 = 0;
    int j = 0;

    if (itemstack == null) {
      this.f.setItem(0, (ItemStack) null);
      this.a = 0;
    } else {
      ItemStack itemstack1 = itemstack.cloneItemStack();
      ItemStack itemstack2 = this.g.getItem(1);
      Map map = EnchantmentManager.a(itemstack1);
      boolean flag = false;
      int k =
          b0 + itemstack.getRepairCost() + (itemstack2 == null ? 0 : itemstack2.getRepairCost());

      this.l = 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.g(itemstack2).size() > 0;
        if (itemstack1.g() && Item.byId[itemstack1.id].a(itemstack, itemstack2)) {
          l = Math.min(itemstack1.j(), itemstack1.l() / 4);
          if (l <= 0) {
            this.f.setItem(0, (ItemStack) null);
            this.a = 0;
            return;
          }

          for (i1 = 0; l > 0 && i1 < itemstack2.count; ++i1) {
            j1 = itemstack1.j() - l;
            itemstack1.setData(j1);
            i += Math.max(1, l / 100) + map.size();
            l = Math.min(itemstack1.j(), itemstack1.l() / 4);
          }

          this.l = i1;
        } else {
          if (!flag && (itemstack1.id != itemstack2.id || !itemstack1.g())) {
            this.f.setItem(0, (ItemStack) null);
            this.a = 0;
            return;
          }

          if (itemstack1.g() && !flag) {
            l = itemstack.l() - itemstack.j();
            i1 = itemstack2.l() - itemstack2.j();
            j1 = i1 + itemstack1.l() * 12 / 100;
            int i2 = l + j1;

            k1 = itemstack1.l() - i2;
            if (k1 < 0) {
              k1 = 0;
            }

            if (k1 < itemstack1.getData()) {
              itemstack1.setData(k1);
              i += Math.max(1, j1 / 100);
            }
          }

          Map map1 = EnchantmentManager.a(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 (this.n.abilities.canInstantlyBuild
                || itemstack.id == ItemEnchantedBook.ENCHANTED_BOOK.id) {
              flag1 = true;
            }

            Iterator iterator1 = map.keySet().iterator();

            while (iterator1.hasNext()) {
              int l2 = ((Integer) iterator1.next()).intValue();

              if (l2 != j1 && !enchantment.a(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;
              }

              if (flag) {
                i3 = Math.max(1, i3 / 2);
              }

              i += i3 * k2;
            }
          }
        }
      }

      if (this.m != null
          && this.m.length() > 0
          && !this.m.equalsIgnoreCase(this.n.getLocale().c(itemstack.a()))
          && !this.m.equals(itemstack.getName())) {
        j = itemstack.g() ? 7 : itemstack.count * 5;
        i += j;
        if (itemstack.hasName()) {
          k += j / 2;
        }

        itemstack1.c(this.m);
      }

      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);
      }

      this.a = k + i;
      if (i <= 0) {
        itemstack1 = null;
      }

      if (j == i && j > 0 && this.a >= 40) {
        this.h
            .getLogger()
            .info("Naming an item only, cost too high; giving discount to cap cost to 39 levels");
        this.a = 39;
      }

      if (this.a >= 40 && !this.n.abilities.canInstantlyBuild) {
        itemstack1 = null;
      }

      if (itemstack1 != null) {
        i1 = itemstack1.getRepairCost();
        if (itemstack2 != null && i1 < itemstack2.getRepairCost()) {
          i1 = itemstack2.getRepairCost();
        }

        if (itemstack1.hasName()) {
          i1 -= 9;
        }

        if (i1 < 0) {
          i1 = 0;
        }

        i1 += 2;
        itemstack1.setRepairCost(i1);
        EnchantmentManager.a(map, itemstack1);
      }

      this.f.setItem(0, itemstack1);
      this.b();
    }
  }