@Override
 public void onEnable() {
   if (mc.thePlayer.inventory.getStackInSlot(0) != null) {
     wurst.chat.error("Please clear the first slot in your hotbar.");
     setEnabled(false);
     return;
   } else if (!mc.thePlayer.capabilities.isCreativeMode) {
     wurst.chat.error("Creative mode only.");
     setEnabled(false);
     return;
   }
   ItemStack stack = new ItemStack(Items.potionitem);
   stack.setItemDamage(16384);
   NBTTagList effects = new NBTTagList();
   for (int i = 1; i <= 23; i++) {
     NBTTagCompound effect = new NBTTagCompound();
     effect.setInteger("Amplifier", Integer.MAX_VALUE);
     effect.setInteger("Duration", Integer.MAX_VALUE);
     effect.setInteger("Id", i);
     effects.appendTag(effect);
   }
   stack.setTagInfo("CustomPotionEffects", effects);
   stack.setStackDisplayName("§c§lTroll§6§lPotion");
   mc.thePlayer.sendQueue.addToSendQueue(new C10PacketCreativeInventoryAction(36, stack));
   wurst.chat.message("Potion created. Trololo!");
   setEnabled(false);
 }
 @Override
 public void onContainerClosed(EntityPlayer par1EntityPlayer) {
   super.onContainerClosed(par1EntityPlayer);
   if (par1EntityPlayer.worldObj.isRemote) {
     NBTTagCompound tag = new NBTTagCompound();
     tag.setString("EntityId", mobID);
     tag.setShort("MinSpawnDelay", (short) minSpawnDelay);
     tag.setShort("MaxSpawnDelay", (short) maxSpawnDelay);
     tag.setShort("SpawnCount", (short) spawnCount);
     tag.setShort("MaxNearbyEntities", (short) maxNearbyEntities);
     tag.setShort("RequiredPlayerRange", (short) activatingRangeFromPlayer);
     tag.setShort("SpawnRange", (short) spawnRange);
     sendDataToServer(tag);
     return;
   }
   ItemStack builderItem = player.inventory.getCurrentItem();
   if (builderItem == null
       || builderItem.getItem() == null
       || builderItem.getItem() != AWStructuresItemLoader.spawnerPlacer) {
     return;
   }
   if (!builderItem.hasTagCompound() || !builderItem.getTagCompound().hasKey("spawnData")) {
     builderItem.setTagInfo("spawnData", new NBTTagCompound());
   }
   NBTTagCompound tag = new NBTTagCompound();
   tag.setString("EntityId", mobID);
   tag.setShort("MinSpawnDelay", (short) minSpawnDelay);
   tag.setShort("MaxSpawnDelay", (short) maxSpawnDelay);
   tag.setShort("SpawnCount", (short) spawnCount);
   tag.setShort("MaxNearbyEntities", (short) maxNearbyEntities);
   tag.setShort("RequiredPlayerRange", (short) activatingRangeFromPlayer);
   tag.setShort("SpawnRange", (short) spawnRange);
   builderItem.getTagCompound().setTag("spawnData", tag);
 }
  /** Set the enchantments for the specified stack. */
  public static void setEnchantments(Map p_82782_0_, ItemStack p_82782_1_) {
    NBTTagList nbttaglist = new NBTTagList();
    Iterator iterator = p_82782_0_.keySet().iterator();

    while (iterator.hasNext()) {
      int i = ((Integer) iterator.next()).intValue();
      NBTTagCompound nbttagcompound = new NBTTagCompound();
      nbttagcompound.setShort("id", (short) i);
      nbttagcompound.setShort(
          "lvl", (short) ((Integer) p_82782_0_.get(Integer.valueOf(i))).intValue());
      nbttaglist.appendTag(nbttagcompound);

      if (p_82782_1_.getItem() == Items.enchanted_book) {
        Items.enchanted_book.addEnchantment(
            p_82782_1_,
            new EnchantmentData(i, ((Integer) p_82782_0_.get(Integer.valueOf(i))).intValue()));
      }
    }

    if (nbttaglist.tagCount() > 0) {
      if (p_82782_1_.getItem() != Items.enchanted_book) {
        p_82782_1_.setTagInfo("ench", nbttaglist);
      }
    } else if (p_82782_1_.hasTagCompound()) {
      p_82782_1_.getTagCompound().removeTag("ench");
    }
  }
  /** Set the enchantments for the specified stack. */
  public static void setEnchantments(Map par0Map, ItemStack par1ItemStack) {
    NBTTagList nbttaglist = new NBTTagList();
    Iterator iterator = par0Map.keySet().iterator();

    while (iterator.hasNext()) {
      int i = ((Integer) iterator.next()).intValue();
      NBTTagCompound nbttagcompound = new NBTTagCompound();
      nbttagcompound.setShort("id", (short) i);
      nbttagcompound.setShort(
          "lvl", (short) ((Integer) par0Map.get(Integer.valueOf(i))).intValue());
      nbttaglist.appendTag(nbttagcompound);

      if (par1ItemStack.itemID == Item.enchantedBook.itemID) {
        Item.enchantedBook.addEnchantment(
            par1ItemStack,
            new EnchantmentData(i, ((Integer) par0Map.get(Integer.valueOf(i))).intValue()));
      }
    }

    if (nbttaglist.tagCount() > 0) {
      if (par1ItemStack.itemID != Item.enchantedBook.itemID) {
        par1ItemStack.setTagInfo("ench", nbttaglist);
      }
    } else if (par1ItemStack.hasTagCompound()) {
      par1ItemStack.getTagCompound().removeTag("ench");
    }
  }
Beispiel #5
0
 public ItemStack setDecay(ItemStack is, int decay) {
   NBTTagCompound nbtTagCompound = new NBTTagCompound();
   NBTTagList nbtlist = new NBTTagList();
   nbtTagCompound.setInteger("decay", decay);
   nbtlist.appendTag(nbtTagCompound);
   if (nbtlist.tagCount() > 0) {
     is.setTagInfo("Decay", nbtlist);
   }
   return is;
 }
 public static void setSettingsFor(ItemStack item, ItemStructureSettings settings) {
   NBTTagCompound tag = new NBTTagCompound();
   if (settings.setKeys[0]) {
     NBTTagCompound tag1 = new NBTTagCompound();
     settings.pos1.writeToNBT(tag1);
     tag.setTag("pos1", tag1);
   }
   if (settings.setKeys[1]) {
     NBTTagCompound tag1 = new NBTTagCompound();
     settings.pos2.writeToNBT(tag1);
     tag.setTag("pos2", tag1);
   }
   if (settings.setKeys[2]) {
     NBTTagCompound tag1 = new NBTTagCompound();
     settings.key.writeToNBT(tag1);
     tag1.setInteger("face", settings.buildFace);
     tag.setTag("buildKey", tag1);
   }
   if (settings.setKeys[3]) {
     tag.setString("name", settings.name);
   }
   item.setTagInfo("structData", tag);
 }
  // patch method
  @Overwrite
  public void processVanilla250Packet(C17PacketCustomPayload p_147349_1_) {
    PacketBuffer packetbuffer;
    ItemStack itemstack;
    ItemStack itemstack1;

    if ("MC|BEdit".equals(p_147349_1_.func_149559_c())) {
      packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e()));

      try {
        itemstack = packetbuffer.readItemStackFromBuffer();

        if (itemstack == null) {
          return;
        }

        if (!ItemWritableBook.func_150930_a(itemstack.getTagCompound())) {
          throw new IOException("Invalid book tag!");
        }

        itemstack1 = playerEntity.inventory.getCurrentItem();

        if (itemstack1 != null) {
          if (itemstack.getItem() == Items.writable_book
              && itemstack.getItem() == itemstack1.getItem()) {
            itemstack1.setTagInfo("pages", itemstack.getTagCompound().getTagList("pages", 8));
          }

          return;
        }
      } catch (Exception exception4) {
        logger.error("Couldn\'t handle book info", exception4);
        return;
      } finally {
        packetbuffer.release();
      }

      return;
    } else if ("MC|BSign".equals(p_147349_1_.func_149559_c())) {
      packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e()));

      try {
        itemstack = packetbuffer.readItemStackFromBuffer();

        if (itemstack != null) {
          if (!ItemEditableBook.validBookTagContents(itemstack.getTagCompound())) {
            throw new IOException("Invalid book tag!");
          }

          itemstack1 = playerEntity.inventory.getCurrentItem();

          if (itemstack1 == null) {
            return;
          }

          if (itemstack.getItem() == Items.written_book
              && itemstack1.getItem() == Items.writable_book) {
            itemstack1.setTagInfo("author", new NBTTagString(playerEntity.getCommandSenderName()));
            itemstack1.setTagInfo(
                "title", new NBTTagString(itemstack.getTagCompound().getString("title")));
            itemstack1.setTagInfo("pages", itemstack.getTagCompound().getTagList("pages", 8));
            itemstack1.func_150996_a(Items.written_book);
          }

          return;
        }
      } catch (Exception exception3) {
        logger.error("Couldn\'t sign book", exception3);
        return;
      } finally {
        packetbuffer.release();
      }

      return;
    } else {
      DataInputStream datainputstream;
      int i;

      if ("MC|TrSel".equals(p_147349_1_.func_149559_c())) {
        try {
          datainputstream =
              new DataInputStream(new ByteArrayInputStream(p_147349_1_.func_149558_e()));
          i = datainputstream.readInt();
          Container container = playerEntity.openContainer;

          if (container instanceof ContainerMerchant) {
            ((ContainerMerchant) container).setCurrentRecipeIndex(i);
          }
        } catch (Exception exception2) {
          logger.error("Couldn\'t select trade", exception2);
        }
      } else if ("MC|AdvCdm".equals(p_147349_1_.func_149559_c())) {
        if (!serverController.isCommandBlockEnabled()) {
          playerEntity.addChatMessage(
              new ChatComponentTranslation("advMode.notEnabled", new Object[0]));
        } else if (PermissionManager.checkPermission(playerEntity, "mc.cmdblocks")
            && playerEntity.capabilities.isCreativeMode) {
          packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e()));

          try {
            byte b0 = packetbuffer.readByte();
            CommandBlockLogic commandblocklogic = null;

            if (b0 == 0) {
              TileEntity tileentity =
                  playerEntity.worldObj.getTileEntity(
                      packetbuffer.readInt(), packetbuffer.readInt(), packetbuffer.readInt());

              if (tileentity instanceof TileEntityCommandBlock) {
                commandblocklogic = ((TileEntityCommandBlock) tileentity).func_145993_a();
              }
            } else if (b0 == 1) {
              Entity entity = playerEntity.worldObj.getEntityByID(packetbuffer.readInt());

              if (entity instanceof EntityMinecartCommandBlock) {
                commandblocklogic = ((EntityMinecartCommandBlock) entity).func_145822_e();
              }
            }

            String s1 = packetbuffer.readStringFromBuffer(packetbuffer.readableBytes());

            if (commandblocklogic != null) {
              commandblocklogic.func_145752_a(s1);
              commandblocklogic.func_145756_e();
              playerEntity.addChatMessage(
                  new ChatComponentTranslation("advMode.setCommand.success", new Object[] {s1}));
            }
          } catch (Exception exception1) {
            logger.error("Couldn\'t set command block", exception1);
          } finally {
            packetbuffer.release();
          }
        } else {
          playerEntity.addChatMessage(
              new ChatComponentTranslation("advMode.notAllowed", new Object[0]));
        }
      } else if ("MC|Beacon".equals(p_147349_1_.func_149559_c())) {
        if (playerEntity.openContainer instanceof ContainerBeacon) {
          try {
            datainputstream =
                new DataInputStream(new ByteArrayInputStream(p_147349_1_.func_149558_e()));
            i = datainputstream.readInt();
            int j = datainputstream.readInt();
            ContainerBeacon containerbeacon = (ContainerBeacon) playerEntity.openContainer;
            Slot slot = containerbeacon.getSlot(0);

            if (slot.getHasStack()) {
              slot.decrStackSize(1);
              TileEntityBeacon tileentitybeacon = containerbeacon.func_148327_e();
              tileentitybeacon.setPrimaryEffect(i);
              tileentitybeacon.setSecondaryEffect(j);
              tileentitybeacon.markDirty();
            }
          } catch (Exception exception) {
            logger.error("Couldn\'t set beacon", exception);
          }
        }
      } else if ("MC|ItemName".equals(p_147349_1_.func_149559_c())
          && playerEntity.openContainer instanceof ContainerRepair) {
        ContainerRepair containerrepair = (ContainerRepair) playerEntity.openContainer;

        if (p_147349_1_.func_149558_e() != null && p_147349_1_.func_149558_e().length >= 1) {
          String s =
              ChatAllowedCharacters.filerAllowedCharacters(
                  new String(p_147349_1_.func_149558_e(), Charsets.UTF_8));

          if (s.length() <= 30) {
            containerrepair.updateItemName(s);
          }
        } else {
          containerrepair.updateItemName("");
        }
      }
    }
  }
  /** Process the contents of this packet */
  public void handle(NetHandlerPlayServer handler) {
    PacketThreadUtil.processPacket(this, handler, handler.playerEntity.getWorldForPlayer());
    PacketBuffer var2;
    ItemStack var3;
    ItemStack var4;

    if ("MC|BEdit".equals(this.channel)) {
      var2 = new PacketBuffer(Unpooled.wrappedBuffer(this.data));

      try {
        var3 = var2.readItemStackFromBuffer();

        if (var3 == null) return;

        if (!ItemWritableBook.validBookPageTagContents(var3.getTagCompound())) {
          throw new IOException("Invalid book tag!");
        }

        var4 = handler.playerEntity.inventory.getCurrentItem();

        if (var4 != null) {
          if (var3.getItem() == Items.writable_book && var3.getItem() == var4.getItem()) {
            var4.setTagInfo("pages", var3.getTagCompound().getTagList("pages", 8));
          }
        }
      } catch (Exception ignored) {
      } finally {
        var2.release();
      }

    } else if ("MC|BSign".equals(this.channel)) {
      var2 = new PacketBuffer(Unpooled.wrappedBuffer(this.data));

      try {
        var3 = var2.readItemStackFromBuffer();

        if (var3 == null) {
          return;
        }

        if (!ItemEditableBook.validBookTagContents(var3.getTagCompound())) {
          throw new IOException("Invalid book tag!");
        }

        var4 = handler.playerEntity.inventory.getCurrentItem();

        if (var4 != null) {
          if (var3.getItem() == Items.written_book && var4.getItem() == Items.writable_book) {
            var4.setTagInfo("author", new NBTTagString(handler.playerEntity.getName()));
            var4.setTagInfo("title", new NBTTagString(var3.getTagCompound().getString("title")));
            var4.setTagInfo("pages", var3.getTagCompound().getTagList("pages", 8));
            var4.setItem(Items.written_book);
          }
        }
      } catch (Exception ignored) {
      } finally {
        var2.release();
      }
    } else if ("MC|TrSel".equals(this.channel)) {
      try {
        int var40 = this.data.readInt();
        Container container = handler.playerEntity.openContainer;

        if (container instanceof ContainerMerchant) {
          ((ContainerMerchant) container).setCurrentRecipeIndex(var40);
        }
      } catch (Exception ignored) {
      }
    } else if ("MC|AdvCdm".equals(this.channel)) {
      if (!handler.serverController.isCommandBlockEnabled()) {
        handler.playerEntity.addChatMessage(new FormattedTextTranslation("advMode.notEnabled"));
      } else if (handler.playerEntity.canCommandSenderUseCommand(2, "")
          && handler.playerEntity.capabilities.isCreativeMode) {
        var2 = this.data;

        try {
          byte var43 = var2.readByte();
          CommandBlockLogic var46 = null;

          if (var43 == 0) {
            var46 =
                $.bind(
                    handler.playerEntity.world.getTileEntity(
                        new BlockPos(var2.readInt(), var2.readInt(), var2.readInt()),
                        TileEntityCommandBlock.class),
                    TileEntityCommandBlock::getCommandBlockLogic);
          } else if (var43 == 1) {
            var46 =
                $.bind(
                    handler.playerEntity.world.getEntityByID(
                        var2.readInt(), EntityMinecartCommandBlock.class),
                    EntityMinecartCommandBlock::getCommandBlockLogic);
          }

          String var49 = var2.readString(var2.readableBytes());
          boolean var6 = var2.readBoolean();

          if (var46 != null) {
            var46.setCommand(var49);
            var46.setCommandFeedback(var6);

            if (!var6) {
              var46.func_145750_b(null);
            }

            var46.markForUpdate();
            handler.playerEntity.addChatMessage(
                new FormattedTextTranslation("advMode.setCommand.success", var49));
          }
        } catch (Exception ignored) {
        } finally {
          var2.release();
        }
      } else {
        handler.playerEntity.addChatMessage(new FormattedTextTranslation("advMode.notAllowed"));
      }
    } else if ("MC|Beacon".equals(this.channel)) {
      if (handler.playerEntity.openContainer instanceof ContainerBeacon) {
        try {
          var2 = this.data;
          int var44 = var2.readInt();
          int var47 = var2.readInt();
          ContainerBeacon var50 = (ContainerBeacon) handler.playerEntity.openContainer;
          Slot var51 = var50.getSlot(0);

          if (var51.hasStack()) {
            var51.decreaseStackSize(1);
            IInventory var7 = var50.getTileEntity();
            var7.setField(1, var44);
            var7.setField(2, var47);
            var7.markDirty();
          }
        } catch (Exception ignored) {
        }
      }
    } else if ("MC|ItemName".equals(this.channel)
        && handler.playerEntity.openContainer instanceof ContainerAnvil) {
      ContainerAnvil container = (ContainerAnvil) handler.playerEntity.openContainer;

      if (this.data != null && this.data.readableBytes() >= 1) {
        String data = ChatAllowedCharacters.filterAllowedCharacters(this.data.readString(32767));

        if (data.length() <= 30) {
          container.updateItemName(data);
        }
      } else {
        container.updateItemName("");
      }
    }
  }