コード例 #1
0
  @Override
  public void readFromNBT(final NBTTagCompound tag) {
    super.readFromNBT(tag);

    this.age = tag.getLong("age");

    this.inventories.clear();

    final NBTTagCompound inventoriesTag = tag.getCompoundTag("inventories");

    for (final Object key : inventoriesTag.getKeySet()) {
      final String inventoryName = (String) key;
      final NBTTagList inventoryTag = inventoriesTag.getTagList(inventoryName, tag.getId());
      final Map<Integer, ItemStack> inventory = new HashMap<>();

      for (int i = 0; i < inventoryTag.tagCount(); i++) {
        final NBTTagCompound slotTag = inventoryTag.getCompoundTagAt(i);
        final ItemStack stack = ItemStack.loadItemStackFromNBT(slotTag);

        inventory.put((int) slotTag.getByte("slot"), stack);
      }

      this.inventories.put(inventoryName, inventory);
    }

    this.setOwner(NBTUtil.readGameProfileFromNBT(tag.getCompoundTag("owner")));
  }
コード例 #2
0
  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);
      }
    }
  }
コード例 #3
0
ファイル: ItemSkull.java プロジェクト: leijurv/MineBot
  /** 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;
      }
    }
  }