You should upload that lines which is mentioned in error
|
I've spent the better part of a couple of hours over the last 2 days trying to diagnose this issue, and I've done the best of my ability to try to find the cause of the issue, but to no avail. I'm not sure why this is happening at this point. I've highlighted part of the offending code in red below where I'm beginning to think issue lies as of right now, but figured I'd still come for advice just in case I'm barking up the wrong tree (again).
Code:for (final NPCLoot loot : NPCLootTable.forID(npcs[i].npcType).getGeneratedLoot((int) addChance)) { Server.itemHandler.createGroundItem(c, loot.getItemID(), npcs[i].absX, npcs[i].absY, Misc.random(loot.getMinAmount(), loot.getMaxAmount()), c.playerId); }Spoiler for Exception:
The problem I'm having with diagnosing this is that sometimes it works flawlessly, other times it'll throw that exception and crash the server and I haven't been able to figure out what is happening when it runs into the problem. I've even tried catching the NullPointerException with a try/catch statement, but that still didn't let me keep the server from crashing and give me the cause of the problem.
You should upload that lines which is mentioned in error
Post the full code with proper line numbers and we can probably help you,
alternatively post line 93 and maybe we can help you.
Edit: Here you go. This is the method from line 93 of NPCLootTable. I'm not at my computer right now, but anything you need I should be able to dig up.
Code:private ArrayList<NPCLoot> getRolledLoot(final double chanceOffset) { //A 'copy' of the dynamicDrops. final ArrayList<NPCLoot> temp = new ArrayList<>(dynamicDrops); final ArrayList<NPCLoot> rolledLoot = new ArrayList<>(); final Random random = new Random(); for (int i = 0; i < rolls; i++) { final double roll = (random.nextDouble() * ROLL_MULTIPLIER); //Randomizes the loot ArrayList copy. Collections.shuffle(temp); for (final NPCLoot loot : temp) { final double _chanceOffset = (loot.getHitRollCeil() * chanceOffset); if ((loot.getHitRollCeil() + _chanceOffset) >= roll) { rolledLoot.add(loot); temp.remove(loot); break; } } } return rolledLoot; }
rolledLoot shouldn't be null because the drop table has items in it. There's a staticDrops table for items that should always drop, and then dynamicDrops which are rolled by % chance. Also as I said, sometimes it works and both drops show up, works when only the 100% drop drops. I haven't been able to debug this to the point of finding out what is exactly happening for anything to return null.
For starters I don't know why you're casting it to an int makes it being a decimal number redundant because it will round it to the closest whole number so it'll be equal to 1 whether they have the ring or not.
Output:Code:private static boolean hasRow; private static double addChance = hasRow ? 1.25 : 1; private static boolean getRowEquipped() { return hasRow; } public static void main(String[] args) { System.out.println("Ring of Wealth: " + getRowEquipped() + "\tDrop Chance: " + (int) addChance); hasRow = true; System.out.println("Ring of Wealth: " + getRowEquipped() + "\tDrop Chance: " + (int) addChance); }
As for the main problem,Code:Ring of Wealth: false Drop Chance: 1 Ring of Wealth: true Drop Chance: 1
Can you please highlight line 93 & 116 of NPCLootTable.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |