Ejemplo n.º 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")));
  }
Ejemplo n.º 2
0
  @Override
  public void writeToNBT(final NBTTagCompound tag) {
    super.writeToNBT(tag);

    final NBTTagCompound inventoriesTag = new NBTTagCompound();
    final NBTTagCompound ownerTag = new NBTTagCompound();

    for (final Entry<String, Map<Integer, ItemStack>> inventoryEntry :
        this.inventories.entrySet()) {
      final NBTTagList inventoryTag = new NBTTagList();

      for (final Entry<Integer, ItemStack> slotEntry : inventoryEntry.getValue().entrySet()) {
        final NBTTagCompound slotTag = new NBTTagCompound();

        slotEntry.getValue().writeToNBT(slotTag);
        slotTag.setByte("slot", slotEntry.getKey().byteValue());

        inventoryTag.appendTag(slotTag);
      }

      inventoriesTag.setTag(inventoryEntry.getKey(), inventoryTag);
    }

    NBTUtil.writeGameProfile(ownerTag, this.owner);

    tag.setLong("age", this.age);
    tag.setTag("inventories", inventoriesTag);
    tag.setTag("owner", ownerTag);
  }
  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);
      }
    }
  }
Ejemplo n.º 4
0
  @Override
  public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);

    if (nbttagcompound.hasKey("moniker")) {
      moniker = NBTUtil.func_152459_a(nbttagcompound.getCompoundTag("moniker"));
    }
  }
Ejemplo n.º 5
0
  /* SAVING & LOADING */
  @Override
  public void writeToNBT(NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);

    if (this.moniker != null) {
      NBTTagCompound nbt = new NBTTagCompound();
      NBTUtil.func_152460_a(nbt, moniker);
      nbttagcompound.setTag("moniker", nbt);
    }
  }
Ejemplo n.º 6
0
  /** Called when an ItemStack with NBT data is read to potentially that ItemStack's NBT data */
  public boolean updateItemStackNBT(NBTTagCompound nbt) {
    super.updateItemStackNBT(nbt);

    if (nbt.hasKey("SkullOwner", 8) && nbt.getString("SkullOwner").length() > 0) {
      GameProfile gameprofile = new GameProfile((UUID) null, nbt.getString("SkullOwner"));
      gameprofile = TileEntitySkull.updateGameprofile(gameprofile);
      nbt.setTag("SkullOwner", NBTUtil.writeGameProfile(new NBTTagCompound(), gameprofile));
      return true;
    } else {
      return false;
    }
  }
Ejemplo n.º 7
0
  public void onBlockPlacedBy(
      World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
    TileEntity te = world.getTileEntity(x, y, z);
    if (te != null && te instanceof TileEntityMannequin) {
      int l = MathHelper.floor_double((double) (player.rotationYaw * 16.0F / 360.0F) + 0.5D) & 15;
      ((TileEntityMannequin) te).setRotation(l);

      if (stack.hasTagCompound()) {
        NBTTagCompound compound = stack.getTagCompound();
        GameProfile gameProfile = null;
        if (compound.hasKey(TAG_OWNER, 10)) {
          gameProfile = NBTUtil.func_152459_a(compound.getCompoundTag(TAG_OWNER));
          ((TileEntityMannequin) te).setGameProfile(gameProfile);
        }
      }
    }
  }
Ejemplo n.º 8
0
 @Override
 public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
   ItemStack stack = new ItemStack(ModBlocks.doll, 1);
   int meta = world.getBlockMetadata(x, y, z);
   int yOffset = 0;
   if (meta == 1) {
     yOffset = -1;
   }
   TileEntity te = world.getTileEntity(x, y + yOffset, z);
   ;
   if (te != null && te instanceof TileEntityMannequin) {
     TileEntityMannequin teMan = (TileEntityMannequin) te;
     if (teMan.getGameProfile() != null) {
       NBTTagCompound profileTag = new NBTTagCompound();
       NBTUtil.func_152460_a(profileTag, teMan.getGameProfile());
       stack.setTagCompound(new NBTTagCompound());
       stack.getTagCompound().setTag(TAG_OWNER, profileTag);
     }
   }
   return stack;
 }
Ejemplo n.º 9
0
  // 独自の手に持ったアイテムの描画(ModelBiped)
  private void renderEquippedItems(EntityLiving par1Entity, float par2) {
    GL11.glColor3f(1.0F, 1.0F, 1.0F);
    super.renderEquippedItems(par1Entity, par2);
    ItemStack itemstack = par1Entity.getHeldItem();
    ItemStack itemstack1 = par1Entity.func_130225_q(3);
    Item item;
    float f1;

    if (itemstack1 != null) {
      GL11.glPushMatrix();
      // this.modelBipedMain.bipedHead.postRender( 0.0625F );
      item = itemstack1.getItem();

      IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(itemstack1, EQUIPPED);
      boolean is3D =
          (customRenderer != null
              && customRenderer.shouldUseRenderHelper(EQUIPPED, itemstack1, BLOCK_3D));

      if (item instanceof ItemBlock) {
        if (is3D || RenderBlocks.renderItemIn3d(Block.getBlockFromItem(item).getRenderType())) {
          f1 = 0.625F;
          GL11.glTranslatef(0.0F, -0.25F, 0.0F);
          GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
          GL11.glScalef(f1, -f1, -f1);
        }

        this.renderManager.itemRenderer.renderItem(par1Entity, itemstack1, 0);
      } else if (item == Items.skull) {
        f1 = 1.0625F;
        GL11.glScalef(f1, -f1, -f1);
        GameProfile gameprofile = null;

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

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

        TileEntitySkullRenderer.field_147536_b.func_152674_a(
            -0.5F, 0.0F, -0.5F, 1, 180.0F, itemstack1.getItemDamage(), gameprofile);
      }

      GL11.glPopMatrix();
    }

    if (itemstack != null && itemstack.getItem() != null) {
      item = itemstack.getItem();
      GL11.glPushMatrix();

      if (this.mainModel.isChild) {
        f1 = 0.5F;
        GL11.glTranslatef(0.0F, 0.625F, 0.0F);
        GL11.glRotatef(-20.0F, -1.0F, 0.0F, 0.0F);
        GL11.glScalef(f1, f1, f1);
      }

      this.modelLivingChestMain.rightArm.postRender(0.0625F);
      GL11.glTranslatef(-0.0625F, 0.4375F, 0.0625F);

      IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(itemstack, EQUIPPED);
      boolean is3D =
          (customRenderer != null
              && customRenderer.shouldUseRenderHelper(EQUIPPED, itemstack, BLOCK_3D));

      if (item instanceof ItemBlock
          && (is3D || RenderBlocks.renderItemIn3d(Block.getBlockFromItem(item).getRenderType()))) {
        f1 = 0.5F;
        GL11.glTranslatef(0.0F, 0.1875F, -0.3125F);
        f1 *= 0.75F;
        GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F);
        GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
        GL11.glScalef(-f1, -f1, f1);
      } else if (item == Items.bow) {
        f1 = 0.625F;
        GL11.glTranslatef(0.0F, 0.125F, 0.3125F);
        GL11.glRotatef(-20.0F, 0.0F, 1.0F, 0.0F);
        GL11.glScalef(f1, -f1, f1);
        GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);
        GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
      } else if (item.isFull3D()) {
        f1 = 0.625F;

        if (item.shouldRotateAroundWhenRendering()) {
          GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
          GL11.glTranslatef(0.0F, -0.125F, 0.0F);
        }

        this.func_82422_c();
        GL11.glScalef(f1, -f1, f1);
        GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);
        GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
      } else {
        f1 = 0.375F;
        GL11.glTranslatef(0.25F, 0.1875F, -0.1875F);
        GL11.glScalef(f1, f1, f1);
        GL11.glRotatef(60.0F, 0.0F, 0.0F, 1.0F);
        GL11.glRotatef(-90.0F, 1.0F, 0.0F, 0.0F);
        GL11.glRotatef(20.0F, 0.0F, 0.0F, 1.0F);
      }

      float f2;
      float f3;
      int i;

      if (itemstack.getItem().requiresMultipleRenderPasses()) {
        for (i = 0; i < itemstack.getItem().getRenderPasses(itemstack.getItemDamage()); ++i) {
          int j = itemstack.getItem().getColorFromItemStack(itemstack, i);
          f2 = (j >> 16 & 255) / 255.0F;
          f3 = (j >> 8 & 255) / 255.0F;
          float f4 = (j & 255) / 255.0F;
          GL11.glColor4f(f2, f3, f4, 1.0F);
          this.renderManager.itemRenderer.renderItem(par1Entity, itemstack, i);
        }
      } else {
        i = itemstack.getItem().getColorFromItemStack(itemstack, 0);
        float f5 = (i >> 16 & 255) / 255.0F;
        f2 = (i >> 8 & 255) / 255.0F;
        f3 = (i & 255) / 255.0F;
        GL11.glColor4f(f5, f2, f3, 1.0F);
        this.renderManager.itemRenderer.renderItem(par1Entity, itemstack, 0);
      }

      GL11.glPopMatrix();
    }
  }
Ejemplo n.º 10
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;
      }
    }
  }