/**
   * checks that there is an item to be smelted in one of the input slots and that there is room for
   * the result in the output slots If desired, performs the smelt
   *
   * @param performSmelt if true, perform the smelt. if false, check whether smelting is possible,
   *     but don't change the inventory
   * @return false if no items can be smelted, true otherwise
   */
  private boolean smeltItem(boolean performSmelt) {
    Integer firstSuitableInputSlot = null;
    Integer firstSuitableOutputSlot = null;
    ItemStack result = null;

    // finds the first input slot which is smeltable and whose result fits into an output slot
    // (stacking if possible)
    for (int inputSlot = FIRST_INPUT_SLOT;
        inputSlot < FIRST_INPUT_SLOT + INPUT_SLOTS_COUNT;
        inputSlot++) {
      if (itemStacks[inputSlot] != null) {
        result = getSmeltingResultForItem(itemStacks[inputSlot]);
        if (result != null) {
          // find the first suitable output slot- either empty, or with identical item that has
          // enough space
          for (int outputSlot = FIRST_OUTPUT_SLOT;
              outputSlot < FIRST_OUTPUT_SLOT + OUTPUT_SLOTS_COUNT;
              outputSlot++) {
            ItemStack outputStack = itemStacks[outputSlot];
            if (outputStack == null) {
              firstSuitableInputSlot = inputSlot;
              firstSuitableOutputSlot = outputSlot;
              break;
            }

            if (outputStack.getItem() == result.getItem()
                && (!outputStack.getHasSubtypes()
                    || outputStack.getMetadata() == outputStack.getMetadata())
                && ItemStack.areItemStackTagsEqual(outputStack, result)) {
              int combinedSize = itemStacks[outputSlot].stackSize + result.stackSize;
              if (combinedSize <= getInventoryStackLimit()
                  && combinedSize <= itemStacks[outputSlot].getMaxStackSize()) {
                firstSuitableInputSlot = inputSlot;
                firstSuitableOutputSlot = outputSlot;
                break;
              }
            }
          }
          if (firstSuitableInputSlot != null) break;
        }
      }
    }

    if (firstSuitableInputSlot == null) return false;
    if (!performSmelt) return true;

    // alter input and output
    itemStacks[firstSuitableInputSlot].stackSize--;
    if (itemStacks[firstSuitableInputSlot].stackSize <= 0)
      itemStacks[firstSuitableInputSlot] = null;
    if (itemStacks[firstSuitableOutputSlot] == null) {
      itemStacks[firstSuitableOutputSlot] =
          result.copy(); // Use deep .copy() to avoid altering the recipe
    } else {
      itemStacks[firstSuitableOutputSlot].stackSize += result.stackSize;
    }
    markDirty();
    return true;
  }
示例#2
0
  private boolean checkMatch(InventoryCrafting craftinginventory, int x, int y, boolean reverse) {
    for (int k = 0; k < 3; ++k) {
      for (int l = 0; l < 3; ++l) {
        int i1 = k - x;
        int j1 = l - y;
        ItemStack itemstack = null;

        if (i1 >= 0 && j1 >= 0 && i1 < this.recipeWidth && j1 < this.recipeHeight) {
          if (reverse) {
            itemstack = this.recipeItems[this.recipeWidth - i1 - 1 + j1 * this.recipeWidth];
          } else {
            itemstack = this.recipeItems[i1 + j1 * this.recipeWidth];
          }
        }

        ItemStack itemstack1 = craftinginventory.getStackInRowAndColumn(k, l);

        if (itemstack1 != null || itemstack != null) {
          if (itemstack1 == null && itemstack != null || itemstack1 != null && itemstack == null) {
            return false;
          }

          if (itemstack.getItem() != itemstack1.getItem()) {
            return false;
          }

          if (itemstack.getMetadata() != 32767
              && itemstack.getMetadata() != itemstack1.getMetadata()) {
            return false;
          }

          // null and empty itemstacks are also ok
          boolean firstempty =
              itemstack.getTagCompound() == null || itemstack.getTagCompound().hasNoTags();
          boolean secondempty =
              itemstack1.getTagCompound() == null || itemstack1.getTagCompound().hasNoTags();

          //  System.out.println(firstempty + ": " + itemstack.getItem() + " / " +
          // itemstack.getTagCompound());
          //  System.out.println(secondempty + ": " + itemstack1.getItem() + " / " +
          // itemstack1.getTagCompound());

          if (firstempty != secondempty
              && !ItemStack.areItemStackTagsEqual(itemstack, itemstack1)) {
            return false;
          }
        }
      }
    }

    return true;
  }
示例#3
0
 @Override
 public void addInformation(ItemStack item, EntityPlayer player, List infoList, boolean par4) {
   infoList.add(TooltipLocalizer.efficiency(toolMaterial.getEfficiencyOnProperMaterial()));
   if (item.getMaxDurability() != -1)
     infoList.add(TooltipLocalizer.usesRemaining(item.getMaxDurability() - item.getMetadata()));
   else infoList.add(TooltipLocalizer.infiniteUses());
 }
 private boolean onPlayerPlaceBlock(
     PlayerControllerMP controller,
     EntityPlayer player,
     ItemStack offhand,
     BlockPos pos,
     EnumFacing l,
     Vec3 hitVec) {
   final World worldObj = player.worldObj;
   if (!worldObj.getWorldBorder().contains(pos)) {
     return false;
   }
   float f = (float) hitVec.xCoord - (float) pos.getX();
   float f1 = (float) hitVec.yCoord - (float) pos.getY();
   float f2 = (float) hitVec.zCoord - (float) pos.getZ();
   boolean flag = false;
   if (!controller.isSpectatorMode()) {
     if (offhand.getItem().onItemUseFirst(offhand, player, worldObj, pos, l, f, f1, f2)) {
       return true;
     }
     if (!player.isSneaking()
         || player.getCurrentEquippedItem() == null
         || player.getCurrentEquippedItem().getItem().doesSneakBypassUse(worldObj, pos, player)) {
       IBlockState b = worldObj.getBlockState(pos);
       if (!b.getBlock().isAir(worldObj, pos)
           && b.getBlock().onBlockActivated(worldObj, pos, b, player, l, f, f1, f2)) {
         flag = true;
       }
     }
     if (!flag && offhand.getItem() instanceof ItemBlock) {
       ItemBlock itemblock = (ItemBlock) offhand.getItem();
       if (!itemblock.canPlaceBlockOnSide(worldObj, pos, l, player, offhand)) {
         return false;
       }
     }
   }
   Battlegear.packetHandler.sendPacketToServer(
       new OffhandPlaceBlockPacket(pos, l, offhand, f, f1, f2).generatePacket());
   if (flag || controller.isSpectatorMode()) {
     return true;
   } else if (offhand == null) {
     return false;
   } else {
     if (controller.isInCreativeMode()) {
       int i1 = offhand.getMetadata();
       int j1 = offhand.stackSize;
       boolean flag1 = offhand.onItemUse(player, worldObj, pos, l, f, f1, f2);
       offhand.setItemDamage(i1);
       offhand.stackSize = j1;
       return flag1;
     } else {
       if (!offhand.onItemUse(player, worldObj, pos, l, f, f1, f2)) {
         return false;
       }
       if (offhand.stackSize <= 0) {
         ForgeEventFactory.onPlayerDestroyItem(player, offhand);
       }
       return true;
     }
   }
 }
  @Override
  public ActionResult<ItemStack> onItemRightClick(
      ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    if (!playerIn.capabilities.isCreativeMode) {
      --itemStackIn.stackSize;
    }

    worldIn.playSound(
        null,
        playerIn.posX,
        playerIn.posY,
        playerIn.posZ,
        SoundEvents.ENTITY_SNOWBALL_THROW,
        SoundCategory.NEUTRAL,
        0.5F,
        0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

    if (!worldIn.isRemote) {
      ThrowballType type =
          ThrowballType.values()[itemStackIn.getMetadata() % ThrowballType.values().length];
      launchThrowball(worldIn, playerIn, type, hand);
    }

    playerIn.addStat(StatList.getObjectUseStats(this));
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn);
  }
示例#6
0
  /* Straight from InventoryHelper in vanilla code */
  public static void spawnInWorld(World world, BlockPos pos, ItemStack itemStack) {

    float f = RANDOM.nextFloat() * 0.8F + 0.1F;
    float f1 = RANDOM.nextFloat() * 0.8F + 0.1F;
    float f2 = RANDOM.nextFloat() * 0.8F + 0.1F;

    while (itemStack.stackSize > 0) {
      int i = RANDOM.nextInt(21) + 10;

      if (i > itemStack.stackSize) i = itemStack.stackSize;

      itemStack.stackSize -= i;
      EntityItem entityitem =
          new EntityItem(
              world,
              pos.getX() + (double) f,
              pos.getY() + (double) f1,
              pos.getZ() + (double) f2,
              new ItemStack(itemStack.getItem(), i, itemStack.getMetadata()));

      if (itemStack.hasTagCompound())
        entityitem
            .getEntityItem()
            .setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());

      float f3 = 0.05F;
      entityitem.motionX = RANDOM.nextGaussian() * (double) f3;
      entityitem.motionY = RANDOM.nextGaussian() * (double) f3 + 0.20000000298023224D;
      entityitem.motionZ = RANDOM.nextGaussian() * (double) f3;
      world.spawnEntityInWorld(entityitem);
    }
  }
 public Comparable<?> getTypeForItem(ItemStack stack) {
   return EABlockSlabDraconium.EnumType.byMetadata(
       stack.getMetadata()
           &
           // 7
           0);
 }
示例#8
0
 @Override
 public boolean equals(Object obj) {
   if (!(obj instanceof ItemStackHolder)) return false;
   ItemStackHolder ish = (ItemStackHolder) obj;
   return is.getItem() == ish.is.getItem()
       && is.getMetadata() == ish.is.getMetadata()
       && ItemStack.areItemStackTagsEqual(is, ish.is);
 }
示例#9
0
  /**
   * Returns the unlocalized name of this item. This version accepts an ItemStack so different
   * stacks can have different names based on their damage or NBT.
   */
  public String getUnlocalizedName(ItemStack stack) {
    int i = stack.getMetadata();

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

    return super.getUnlocalizedName() + "." + skullTypes[i];
  }
 @Override
 @SideOnly(Side.CLIENT)
 public int getColorFromItemStack(ItemStack stack, int renderPass) {
   if (stack.getItemDamage() == MWoodType.FROZEN.getMetadata()) {
     return 10420217;
   }
   return MBlocks.ministrapp_leaves.getRenderColor(
       MBlocks.ministrapp_leaves.getStateFromMeta(stack.getMetadata()));
 }
示例#11
0
 /**
  * Returns the unlocalized name of this item. This version accepts an ItemStack so different
  * stacks can have different names based on their damage or NBT.
  */
 public String getUnlocalizedName(ItemStack stack) {
   if (this.subtypeNames == null) {
     return super.getUnlocalizedName(stack);
   } else {
     int i = stack.getMetadata();
     return i >= 0 && i < this.subtypeNames.length
         ? super.getUnlocalizedName(stack) + "." + this.subtypeNames[i]
         : super.getUnlocalizedName(stack);
   }
 }
 @Override
 public String getUnlocalizedName(ItemStack stack) {
   int meta = stack.getMetadata(); // should call getMetadata below
   if (meta < ThrowballType.values().length) {
     return super.getUnlocalizedName(stack)
         + "."
         + LocUtils.makeLocString(ThrowballType.values()[meta].name());
   } else {
     return super.getUnlocalizedName(stack);
   }
 }
 public static void addRecipe(
     ItemFoodAppleMagic apple, ItemStack ingredient, boolean isExpensive) {
   int refund = 8;
   if (isExpensive) {
     GameRegistry.addRecipe(
         new ItemStack(apple), "lll", "lal", "lll", 'l', ingredient, 'a', Items.APPLE);
   } else {
     GameRegistry.addShapelessRecipe(new ItemStack(apple), ingredient, Items.APPLE);
     refund = 1;
   }
   GameRegistry.addSmelting(
       apple, new ItemStack(ingredient.getItem(), refund, ingredient.getMetadata()), smeltexp);
 }
示例#14
0
  public boolean onItemUse(
      ItemStack stack,
      EntityPlayer playerIn,
      World worldIn,
      BlockPos pos,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    IBlockState var9 = worldIn.getBlockState(pos);
    Block var10 = var9.getBlock();
    if (var10 == Blocks.snow_layer
        && ((Integer) var9.getValue(BlockSnow.LAYERS_PROP)).intValue() < 1) {
      side = EnumFacing.UP;
    } else if (!var10.isReplaceable(worldIn, pos)) {
      pos = pos.offset(side);
    }

    if (stack.stackSize == 0) {
      return false;
    } else if (!playerIn.func_175151_a(pos, side, stack)) {
      return false;
    } else if (pos.getY() == 255 && this.block.getMaterial().isSolid()) {
      return false;
    } else if (worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity) null, stack)) {
      int var11 = this.getMetadata(stack.getMetadata());
      IBlockState var12 =
          this.block.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, var11, playerIn);
      if (worldIn.setBlockState(pos, var12, 3)) {
        var12 = worldIn.getBlockState(pos);
        if (var12.getBlock() == this.block) {
          setTileEntityNBT(worldIn, pos, stack);
          this.block.onBlockPlacedBy(worldIn, pos, var12, playerIn, stack);
        }

        worldIn.playSoundEffect(
            (double) ((float) pos.getX() + 0.5F),
            (double) ((float) pos.getY() + 0.5F),
            (double) ((float) pos.getZ() + 0.5F),
            this.block.stepSound.getPlaceSound(),
            (this.block.stepSound.getVolume() + 1.0F) / 2.0F,
            this.block.stepSound.getFrequency() * 0.8F);
        --stack.stackSize;
      }

      return true;
    } else {
      return false;
    }
  }
示例#15
0
  /**
   * Returns true if the item can be used on the given entity, e.g. shears on sheep.
   *
   * @param stack the item stack of the item being used
   * @param player the player who used the item
   * @param target the target we hit with the item in hand
   */
  public boolean itemInteractionForEntity(
      ItemStack stack, EntityPlayer player, EntityLivingBase target) {
    if (target instanceof EntitySheep) {
      EntitySheep entitysheep = (EntitySheep) target;
      int i = BlockColored.func_150032_b(stack.getMetadata());

      if (!entitysheep.getSheared() && entitysheep.getFleeceColor() != i) {
        entitysheep.setFleeceColor(i);
        --stack.stackSize;
      }

      return true;
    } else {
      return false;
    }
  }
  public void renderByItem(ItemStack p_179022_1_) {
    if (p_179022_1_.getItem() == Items.banner) {
      this.banner.setItemValues(p_179022_1_);
      TileEntityRendererDispatcher.instance.renderTileEntityAt(this.banner, 0.0D, 0.0D, 0.0D, 0.0F);
    } else if (p_179022_1_.getItem() == Items.skull) {
      GameProfile gameprofile = null;

      if (p_179022_1_.hasTagCompound()) {
        NBTTagCompound nbttagcompound = p_179022_1_.getTagCompound();

        if (nbttagcompound.hasKey("SkullOwner", 10)) {
          gameprofile = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner"));
        } else if (nbttagcompound.hasKey("SkullOwner", 8)
            && nbttagcompound.getString("SkullOwner").length() > 0) {
          gameprofile = new GameProfile((UUID) null, nbttagcompound.getString("SkullOwner"));
          gameprofile = TileEntitySkull.updateGameprofile(gameprofile);
          nbttagcompound.removeTag("SkullOwner");
          nbttagcompound.setTag(
              "SkullOwner", NBTUtil.writeGameProfile(new NBTTagCompound(), gameprofile));
        }
      }

      if (TileEntitySkullRenderer.instance != null) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(-0.5F, 0.0F, -0.5F);
        GlStateManager.scale(2.0F, 2.0F, 2.0F);
        GlStateManager.disableCull();
        TileEntitySkullRenderer.instance.renderSkull(
            0.0F, 0.0F, 0.0F, EnumFacing.UP, 0.0F, p_179022_1_.getMetadata(), gameprofile, -1);
        GlStateManager.enableCull();
        GlStateManager.popMatrix();
      }
    } else {
      Block block = Block.getBlockFromItem(p_179022_1_.getItem());

      if (block == Blocks.ender_chest) {
        TileEntityRendererDispatcher.instance.renderTileEntityAt(
            this.field_147716_d, 0.0D, 0.0D, 0.0D, 0.0F);
      } else if (block == Blocks.trapped_chest) {
        TileEntityRendererDispatcher.instance.renderTileEntityAt(
            this.field_147718_c, 0.0D, 0.0D, 0.0D, 0.0F);
      } else {
        TileEntityRendererDispatcher.instance.renderTileEntityAt(
            this.field_147717_b, 0.0D, 0.0D, 0.0D, 0.0F);
      }
    }
  }
示例#17
0
  private DyeColor func_175511_a(EntityAnimal p_175511_1_, EntityAnimal p_175511_2_) {
    int var3 = ((EntitySheep) p_175511_1_).func_175509_cj().getDyeColorValue();
    int var4 = ((EntitySheep) p_175511_2_).func_175509_cj().getDyeColorValue();
    this.inventoryCrafting.get(0).setItemDamage(var3);
    this.inventoryCrafting.get(1).setItemDamage(var4);
    ItemStack var5 =
        CraftingManager.getInstance()
            .findMatchingRecipe(this.inventoryCrafting, ((EntitySheep) p_175511_1_).world);
    int var6;

    if (var5 != null && var5.getItem() == Items.dye) {
      var6 = var5.getMetadata();
    } else {
      var6 = this.world.rand.nextBoolean() ? var3 : var4;
    }

    return DyeColor.getDyeColorForValue(var6);
  }
示例#18
0
  public String getItemStackDisplayName(ItemStack stack) {
    if (stack.getMetadata() == 3 && stack.hasTagCompound()) {
      if (stack.getTagCompound().hasKey("SkullOwner", 8)) {
        return StatCollector.translateToLocalFormatted(
            "item.skull.player.name",
            new Object[] {stack.getTagCompound().getString("SkullOwner")});
      }

      if (stack.getTagCompound().hasKey("SkullOwner", 10)) {
        NBTTagCompound nbttagcompound = stack.getTagCompound().getCompoundTag("SkullOwner");

        if (nbttagcompound.hasKey("Name", 8)) {
          return StatCollector.translateToLocalFormatted(
              "item.skull.player.name", new Object[] {nbttagcompound.getString("Name")});
        }
      }
    }

    return super.getItemStackDisplayName(stack);
  }
示例#19
0
  /** The update tick for the ingame UI */
  public void updateTick() {
    if (this.recordPlayingUpFor > 0) {
      --this.recordPlayingUpFor;
    }

    if (this.field_175195_w > 0) {
      --this.field_175195_w;

      if (this.field_175195_w <= 0) {
        this.field_175201_x = "";
        this.field_175200_y = "";
      }
    }

    ++this.updateCounter;
    this.streamIndicator.func_152439_a();

    if (this.mc.thePlayer != null) {
      ItemStack var1 = this.mc.thePlayer.inventory.getCurrentItem();

      if (var1 == null) {
        this.remainingHighlightTicks = 0;
      } else if (this.highlightingItemStack != null
          && var1.getItem() == this.highlightingItemStack.getItem()
          && ItemStack.areItemStackTagsEqual(var1, this.highlightingItemStack)
          && (var1.isItemStackDamageable()
              || var1.getMetadata() == this.highlightingItemStack.getMetadata())) {
        if (this.remainingHighlightTicks > 0) {
          --this.remainingHighlightTicks;
        }
      } else {
        this.remainingHighlightTicks = 40;
      }

      this.highlightingItemStack = var1;
    }
  }
示例#20
0
  @Override
  public void breakBlock(World w, int x, int y, int z, Block b, int i) {
    TileEntityFrostedChest items = (TileEntityFrostedChest) w.getTileEntity(x, y, z);
    if (items != null) {
      ItemStack itemstack = null;
      for (int i1 = 0; i1 < items.getSizeInventory(); i1++) {
        itemstack = items.getStackInSlot(i1);
        if (itemstack != null) {
          float f = rand.nextFloat() * 0.8F + 0.1F;
          float f1 = rand.nextFloat() * 0.8F + 0.1F;
          float f3 = 0.05F;
          EntityItem entityitem;

          for (float f2 = rand.nextFloat() * 0.8F + 0.1F;
              itemstack.stackSize > 0;
              w.spawnEntityInWorld(entityitem)) {
            int j1 = rand.nextInt(21) + 10;
            if (j1 > itemstack.stackSize) j1 = itemstack.stackSize;

            itemstack.stackSize -= j1;
            entityitem =
                new EntityItem(
                    w,
                    (double) ((float) x + f),
                    (double) ((float) y + f1),
                    (double) ((float) z + f2),
                    new ItemStack(itemstack.getItem(), j1, itemstack.getMetadata()));
            entityitem.motionX = (double) ((float) rand.nextGaussian() * f3);
            entityitem.motionY = (double) ((float) rand.nextGaussian() * f3 + 0.2F);
            entityitem.motionZ = (double) ((float) rand.nextGaussian() * f3);
          }
        }
      }
      w.updateNeighborsAboutBlockChange(x, y, z, b);
    }
    super.breakBlock(w, x, y, z, b, i);
  }
示例#21
0
 @Override
 public boolean matchesExact(IItemStack item) {
   ItemStack internal = getItemStack(item);
   if (internal.getTagCompound() != null && stack.getTagCompound() == null) {
     return false;
   }
   if (internal.getTagCompound() == null && stack.getTagCompound() != null) {
     return false;
   }
   if (internal.getTagCompound() == null && stack.getTagCompound() == null) {
     return stack.getItem() == internal.getItem()
         && (internal.getMetadata() == 32767 || stack.getMetadata() == internal.getMetadata());
   }
   if (internal.getTagCompound().getKeySet().equals(stack.getTagCompound().getKeySet())) {
     for (String s : internal.getTagCompound().getKeySet()) {
       if (!internal.getTagCompound().getTag(s).equals(stack.getTagCompound().getTag(s))) {
         return false;
       }
     }
   }
   return stack.getItem() == internal.getItem()
       && (internal.getMetadata() == 32767 || stack.getMetadata() == internal.getMetadata());
 }
示例#22
0
 @Override
 public String getUnlocalizedName(ItemStack stack) {
   return super.getUnlocalizedName(stack) + (stack.getMetadata() > 0 ? "_empty" : "");
 }
示例#23
0
 @Override
 public boolean hasContainerItem(ItemStack stack) {
   return stack.getMetadata() == 0 ? true : false;
 }
示例#24
0
 /**
  * Returns the unlocalized name of this item. This version accepts an ItemStack so different
  * stacks can have different names based on their damage or NBT.
  */
 public String getUnlocalizedName(ItemStack stack) {
   int i = MathHelper.clamp_int(stack.getMetadata(), 0, 15);
   return super.getUnlocalizedName() + "." + dyeColorNames[i];
 }
示例#25
0
  // Copied from vanila skull itemBlock. Relevant edits are indicated.
  @Nonnull
  @Override
  public EnumActionResult onItemUse(
      ItemStack stack,
      EntityPlayer playerIn,
      World worldIn,
      BlockPos pos,
      EnumHand hand,
      EnumFacing facing,
      float hitX,
      float hitY,
      float hitZ) {
    if (facing == EnumFacing.DOWN) {
      return EnumActionResult.FAIL;
    } else {
      if (worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos)) {
        facing = EnumFacing.UP;
        pos = pos.down();
      }
      IBlockState iblockstate = worldIn.getBlockState(pos);
      Block block = iblockstate.getBlock();
      boolean flag = block.isReplaceable(worldIn, pos);

      if (!flag) {
        if (!worldIn.getBlockState(pos).getMaterial().isSolid()
            && !worldIn.isSideSolid(pos, facing, true)) {
          return EnumActionResult.FAIL;
        }

        pos = pos.offset(facing);
      }

      if (playerIn.canPlayerEdit(pos, facing, stack)
          && Blocks.SKULL.canPlaceBlockAt(worldIn, pos)) {
        if (worldIn.isRemote) {
          return EnumActionResult.SUCCESS;
        } else {
          worldIn.setBlockState(
              pos,
              ModBlocks.gaiaHead.getDefaultState().withProperty(BlockSkull.FACING, facing),
              11); // Botania - skull -> gaia head
          int i = 0;

          if (facing == EnumFacing.UP) {
            i = MathHelper.floor_double(playerIn.rotationYaw * 16.0F / 360.0F + 0.5D) & 15;
          }

          TileEntity tileentity = worldIn.getTileEntity(pos);

          if (tileentity instanceof TileEntitySkull) {
            TileEntitySkull tileentityskull = (TileEntitySkull) tileentity;

            if (stack.getMetadata() == 3) // Botania - do not retrieve skins
            {
              /*GameProfile gameprofile = null;

              if (stack.hasTagCompound())
              {
              	NBTTagCompound nbttagcompound = stack.getTagCompound();

              	if (nbttagcompound.hasKey("SkullOwner", 10))
              	{
              		gameprofile = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner"));
              	}
              	else if (nbttagcompound.hasKey("SkullOwner", 8) && !nbttagcompound.getString("SkullOwner").isEmpty())
              	{
              		gameprofile = new GameProfile((UUID)null, nbttagcompound.getString("SkullOwner"));
              	}
              }

              tileentityskull.setPlayerProfile(gameprofile);*/
            } else {
              tileentityskull.setType(3); // Botania - Force type to 3 (humanoid)
            }

            tileentityskull.setSkullRotation(i);
            Blocks.SKULL.checkWitherSpawn(worldIn, pos, tileentityskull);
          }

          --stack.stackSize;
          return EnumActionResult.SUCCESS;
        }
      } else {
        return EnumActionResult.FAIL;
      }
    }
  }
示例#26
0
 @SideOnly(Side.CLIENT)
 public int getColorFromItemStack(ItemStack stack, int renderPass) {
   return this.coloredBlock.getRenderColor(
       this.coloredBlock.getStateFromMeta(stack.getMetadata()));
 }
示例#27
0
 @Override
 public int hashCode() {
   return is.getItem().hashCode() * 31
       + (is.getMetadata() * 31 * 31)
       + (is.hasTagCompound() ? is.getTagCompound().hashCode() : 0);
 }
 @Override
 public String getSubtypeUnlocalizedName(ItemStack stack) {
   return ChiselProperties.PAPERWALL_VARIANTS.fromMeta(stack.getMetadata()).getName();
 }
示例#29
0
  /** Called when a Block is right-clicked with this Item */
  public boolean onItemUse(
      ItemStack stack,
      EntityPlayer playerIn,
      World worldIn,
      BlockPos pos,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (side == EnumFacing.DOWN) {
      return false;
    } else {
      IBlockState iblockstate = worldIn.getBlockState(pos);
      Block block = iblockstate.getBlock();
      boolean flag = block.isReplaceable(worldIn, pos);

      if (!flag) {
        if (!worldIn.getBlockState(pos).getBlock().getMaterial().isSolid()) {
          return false;
        }

        pos = pos.offset(side);
      }

      if (!playerIn.canPlayerEdit(pos, side, stack)) {
        return false;
      } else if (!Blocks.skull.canPlaceBlockAt(worldIn, pos)) {
        return false;
      } else {
        if (!worldIn.isRemote) {
          worldIn.setBlockState(
              pos, Blocks.skull.getDefaultState().withProperty(BlockSkull.FACING, side), 3);
          int i = 0;

          if (side == EnumFacing.UP) {
            i =
                MathHelper.floor_double((double) (playerIn.rotationYaw * 16.0F / 360.0F) + 0.5D)
                    & 15;
          }

          TileEntity tileentity = worldIn.getTileEntity(pos);

          if (tileentity instanceof TileEntitySkull) {
            TileEntitySkull tileentityskull = (TileEntitySkull) tileentity;

            if (stack.getMetadata() == 3) {
              GameProfile gameprofile = null;

              if (stack.hasTagCompound()) {
                NBTTagCompound nbttagcompound = stack.getTagCompound();

                if (nbttagcompound.hasKey("SkullOwner", 10)) {
                  gameprofile =
                      NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner"));
                } else if (nbttagcompound.hasKey("SkullOwner", 8)
                    && nbttagcompound.getString("SkullOwner").length() > 0) {
                  gameprofile =
                      new GameProfile((UUID) null, nbttagcompound.getString("SkullOwner"));
                }
              }

              tileentityskull.setPlayerProfile(gameprofile);
            } else {
              tileentityskull.setType(stack.getMetadata());
            }

            tileentityskull.setSkullRotation(i);
            Blocks.skull.checkWitherSpawn(worldIn, pos, tileentityskull);
          }

          --stack.stackSize;
        }

        return true;
      }
    }
  }
 private boolean areItemStacksEqual(ItemStack parItemStack1, ItemStack parItemStack2) {
   return parItemStack2.getItem() == parItemStack1.getItem()
       && (parItemStack2.getMetadata() == 32767
           || parItemStack2.getMetadata() == parItemStack1.getMetadata());
 }