示例#1
0
 protected void entityInit() {
   super.entityInit();
   this.dataWatcher.addObject(18, new Integer(this.getHealth()));
   this.dataWatcher.addObject(19, new Byte((byte) 0));
   this.dataWatcher.addObject(20, new Byte((byte) BlockCloth.getBlockFromDye(1)));
   this.dataWatcher.addObject(23, "");
 }
 @SuppressWarnings({"rawtypes", "unchecked"})
 @Override
 public void addInformation(
     ItemStack safariNetStack, EntityPlayer player, List infoList, boolean advancedTooltips) {
   infoList.add(
       "Wool: "
           + ItemDye.dyeColorNames[
               BlockCloth.getBlockFromDye((safariNetStack.getTagCompound().getByte("Color")))]);
 }
  @Override
  public ItemStack getCraftingResult(InventoryCrafting inventoryCrafting) {

    ItemStack itemStack = null;
    ItemAlchemicalBag itemAlchemicalBag = null;
    int[] colorChannels = new int[3];
    int i = 0;
    int j = 0;
    int k, j1, k1, l1;
    int currentColor, newColor;
    float red, green, blue;

    for (k = 0; k < inventoryCrafting.getSizeInventory(); ++k) {

      ItemStack currentStack = inventoryCrafting.getStackInSlot(k);

      if (currentStack != null) {

        if (currentStack.getItem() instanceof ItemAlchemicalBag) {

          itemAlchemicalBag = (ItemAlchemicalBag) currentStack.getItem();

          if (itemStack != null) return null;

          itemStack = currentStack.copy();
          itemStack.stackSize = 1;

          if (itemAlchemicalBag.hasColor(currentStack)) {

            currentColor = itemAlchemicalBag.getColor(itemStack);
            red = (currentColor >> 16 & 255) / 255.0F;
            green = (currentColor >> 8 & 255) / 255.0F;
            blue = (currentColor & 255) / 255.0F;
            i = (int) (i + Math.max(red, Math.max(green, blue)) * 255.0F);
            colorChannels[0] = (int) (colorChannels[0] + red * 255.0F);
            colorChannels[1] = (int) (colorChannels[1] + green * 255.0F);
            colorChannels[2] = (int) (colorChannels[2] + blue * 255.0F);
            ++j;
          }
        } else {

          if (currentStack.itemID != Item.dyePowder.itemID) return null;

          float[] dyeColorChannels =
              EntitySheep.fleeceColorTable[
                  BlockCloth.getBlockFromDye(currentStack.getItemDamage())];
          j1 = (int) (dyeColorChannels[0] * 255.0F);
          k1 = (int) (dyeColorChannels[1] * 255.0F);
          newColor = (int) (dyeColorChannels[2] * 255.0F);
          i += Math.max(j1, Math.max(k1, newColor));
          colorChannels[0] += j1;
          colorChannels[1] += k1;
          colorChannels[2] += newColor;
          ++j;
        }
      }
    }

    if (itemAlchemicalBag == null) return null;
    else {

      k = colorChannels[0] / j;
      l1 = colorChannels[1] / j;
      currentColor = colorChannels[2] / j;
      red = (float) i / (float) j;
      green = Math.max(k, Math.max(l1, currentColor));
      k = (int) (k * red / green);
      l1 = (int) (l1 * red / green);
      currentColor = (int) (currentColor * red / green);
      newColor = (k << 8) + l1;
      newColor = (newColor << 8) + currentColor;
      itemAlchemicalBag.setColor(itemStack, newColor);
      return itemStack;
    }
  }
示例#4
0
  /**
   * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a
   * pig.
   */
  public boolean interact(EntityPlayer par1EntityPlayer) {
    ItemStack var2 = par1EntityPlayer.inventory.getCurrentItem();

    if (this.isTamed()) {
      if (var2 != null) {
        if (Item.itemsList[var2.itemID] instanceof ItemFood) {
          ItemFood var3 = (ItemFood) Item.itemsList[var2.itemID];

          if (var3.isWolfsFavoriteMeat() && this.dataWatcher.getWatchableObjectInt(18) < 20) {
            if (!par1EntityPlayer.capabilities.isCreativeMode) {
              --var2.stackSize;
            }

            this.heal(var3.getHealAmount());

            if (var2.stackSize <= 0) {
              par1EntityPlayer.inventory.setInventorySlotContents(
                  par1EntityPlayer.inventory.currentItem, (ItemStack) null);
            }

            return true;
          }
        } else if (var2.itemID == Item.dyePowder.itemID) {
          int var4 = BlockCloth.getBlockFromDye(var2.getItemDamage());

          if (var4 != this.getCollarColor()) {
            this.setCollarColor(var4);

            if (!par1EntityPlayer.capabilities.isCreativeMode && --var2.stackSize <= 0) {
              par1EntityPlayer.inventory.setInventorySlotContents(
                  par1EntityPlayer.inventory.currentItem, (ItemStack) null);
            }

            return true;
          }
        }
      }
      if (var2 != null
          && var2.itemID == ModBreeds.XmasSpecial.itemID
          && var2.getItemDamage() == 5
          && !worldObj.isRemote) {
        EntityWolf6 var21 = new EntityWolf6(this.worldObj);
        var21.setOwner(this.getOwnerName());
        var21.setTamed(true);
        var21.setLocationAndAngles(
            this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
        this.worldObj.spawnEntityInWorld(var21);
        this.setDead();

        if (--var2.stackSize <= 0) {
          par1EntityPlayer.inventory.setInventorySlotContents(
              par1EntityPlayer.inventory.currentItem, null);
        }

        return true;
      }
      if (var2 != null && var2.itemID == ModBreeds.Dogtag.itemID) {

        if (worldObj.isRemote) {
          ModBreeds.proxy.openGUI(par1EntityPlayer, 3, this.entityId);
        }

        return true;
      }
      if (par1EntityPlayer.username.equalsIgnoreCase(this.getOwnerName())
          && !this.worldObj.isRemote
          && !this.isBreedingItem(var2)) {
        this.aiSit.setSitting(!this.isSitting());
        this.isJumping = false;
        this.setPathToEntity((PathEntity) null);
      }
    } else if (var2 != null && var2.itemID == Item.bone.itemID && !this.isAngry()) {
      if (!par1EntityPlayer.capabilities.isCreativeMode) {
        --var2.stackSize;
      }

      if (var2.stackSize <= 0) {
        par1EntityPlayer.inventory.setInventorySlotContents(
            par1EntityPlayer.inventory.currentItem, (ItemStack) null);
      }

      if (!this.worldObj.isRemote) {
        if (this.rand.nextInt(3) == 0) {
          this.setTamed(true);
          this.setPathToEntity((PathEntity) null);
          this.setAttackTarget((EntityLiving) null);
          this.aiSit.setSitting(true);
          this.setEntityHealth(20);
          this.setOwner(par1EntityPlayer.username);
          this.playTameEffect(true);
          this.worldObj.setEntityState(this, (byte) 7);
        } else {
          this.playTameEffect(false);
          this.worldObj.setEntityState(this, (byte) 6);
        }
      }

      return true;
    }

    return super.interact(par1EntityPlayer);
  }