Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Ben_

Members
  • Joined

  • Last visited

  1. I'm trying to write a questing mod, and I'm trying to write the completion. What I need to do, is give some items to the player and then remove some of them. The relevant code is near the bottom: public static Boolean finishQuest(Quest quest, EntityPlayer player) { if(player.worldObj.isRemote == true) { //On the client side System.out.println("Sending quest completion request"); EngineerCraft.channel.sendToServer(new QuestCompleteMessage(player, quest.getName())); return null; } else { //On the server side System.out.println("Receiving quest completion request"); //Get the list of inputs to be checked @SuppressWarnings("unchecked") ArrayList<ItemStack> toBeChecked = (ArrayList<ItemStack>) quest.getInputs().clone(); //Go through every single input while(toBeChecked.size() > 0) { ItemStack currentStack = toBeChecked.get(0); //The amount of items of this type in the inventory int itemCount = 0; //Go through each stack in the inventory and add together the total amount of the same item for(int i = 0; i < player.inventory.mainInventory.length; i++) { ItemStack checkStack = player.inventory.mainInventory[i]; if(checkStack != null) { if(checkStack.isItemEqual(currentStack)) { itemCount += checkStack.stackSize; } } } if(itemCount >= currentStack.stackSize) { toBeChecked.remove(0); } else { return false; } } //If the game has reached this point, the player's inventory has everything the quest needs //Get the list of inputs to be taken @SuppressWarnings("unchecked") ArrayList<ItemStack> toBeTaken = (ArrayList<ItemStack>) quest.getInputs().clone(); //Go through every single input and remove them while(toBeTaken.size() > 0) { ItemStack currentStack = toBeTaken.get(0); //The amount of items of this type in the inventory int itemCount = currentStack.stackSize; //Go through each stack in the inventory and add together the total amount of the same item for(int i = 0; i < player.inventory.mainInventory.length; i++) { ItemStack checkStack = player.inventory.mainInventory[i]; if(checkStack != null) { if(checkStack.isItemEqual(currentStack)) { if(checkStack.stackSize > itemCount) { player.inventory.mainInventory[i] = player.inventory.decrStackSize(i, itemCount); itemCount = 0; } else { itemCount -= checkStack.stackSize; player.inventory.mainInventory[i] = null; } } } } toBeTaken.remove(0); } //Reward the player //Get the list of rewards to be given @SuppressWarnings("unchecked") ArrayList<ItemStack> toBeRewarded = (ArrayList<ItemStack>) quest.getInputs().clone(); for(int i = 0; i < toBeRewarded.size(); i++) { //If adding an item stack to the inventory fails if(player.inventory.addItemStackToInventory(toBeRewarded.get(i).copy()) == false) { //Spawn an item on the ground player.worldObj.loadedEntityList.add(new EntityItem(player.worldObj, player.posX, player.posY + 1.0, player.posZ, toBeRewarded.get(i).copy())); } } player.inventory.inventoryChanged = true; player.inventory.markDirty(); //Save the quest completion saveQuestCompletion(quest, player); return true; } } I have debugged the code and seen that it does indeed get changed, but then outside of the scope it gets brought back to its original value. Is there something I'm missing? This code is only server-side, but that shouldn't matter, because when I reload the world it doesn't change. Does inventory.inventoryChanged need to be changed back to false next tick? I have been incredibly frustrated by this issue, because none of my solutions work.

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.