Post your full checkitemonobject method
|
Tried adding basic farming to my 317 source, I cleared up all the errors but when I click my rake and then the patch nothing happens and this come up in eclipse.
UseItem.java 52
ItemOnObject 215
PacketHnadler 166
Client 1137
PlayerHandler 162
Server 141
Post your full checkitemonobject method
Actually just realized I don't have a method for it, how would I go about doing that?
That's in the Farming code
Code:public void checkItemOnObject(int itemId) { for (int j = 0; j < VALID_SEEDS.length; j++) { if (itemId == VALID_SEEDS[j]) { plantSeed(VALID_SEEDS[j], HERBS[j], HERB_EXPS[j], j); } //so if you use valid seeds on the patch it does plantSeed, cool. } if (itemId == WATER_CAN && !seedWatered) { waterSeed(); //watering is called } else if (itemId == RAKE && !patchRaked) { rakePatch(); //raking is called } else if (c.getItemAssistant().playerHasItem(SEED_DIBBER, 0)); { c.getActionSender().sendMessage("You need a seed dibber to plant seeds."); //if you dont have a seed dibber it gets mad at you. } }
Thank you for posting the code related to your error, it makes helping you 100x easier
The error "NullPointerException" means that something was null, from the line you posted
There are 3 variables in use: c, itemId & farming (which is inside the getter "getFarming()")
As an integer cannot be null we can discard itemId
And it's unlikely that the player/client c is null as well
So we can safely assume that getFarming() is returning null.
This is probably because it hasn't be initalized in the player/client class.
is what I would assume it should look like, in a method along the lines of "init()" or "initEntity()"Code:farming = new Farming(this);
It probably doesn't exist, which is why you are getting this error.
Hey really appreciate you taking the time to help out, luckily for me I kept working at it and figured it out myself and you were right. I do have another issue I've been working at but I think it's way above me. So I'm using a farming code for a different source (PI) and trying to add it to mine, I've got it raking the plot but the plot doesn't change I'll post my code for farming and explain what I think the problem is and maybe you can help.
Farming Code
now here is where I think the problem is, eclipse told me to use my method "ObjectAnim" instead of what the code was "object". Here is my code vs the code it was using in the PlayerAssistant.Code:package redone.game.content.skills.farming; import redone.game.players.Client; import redone.util.Misc; import redone.game.content.skills.SkillHandler; public class Farming { private Client c; private final static int[] VALID_SEEDS = {5291, 5292, 5293, 5294, 5295, 5296, 5297, 5298, 5299, 5300, 5301, 5302, 5303, 5304}; private final static int[] HERBS = {199, 201, 203, 205, 207, 3049, 209, 211, 213, 3051, 215, 2485, 217, 219}; private final static int[] SEED_PLANT_EXP = {11, 14, 16, 22, 27, 34, 43, 55, 69, 88, 107, 135, 171, 200}; private final static int[] HERB_EXPS = {13, 15, 18, 24, 31, 39, 49, 62, 78, 99, 120, 152, 192, 225}; private final static int[] FARMING_REQS = {1, 14, 19, 26, 32, 38, 44, 50, 56, 62, 67, 73, 79, 85}; /* all of our arrays are fine */ /** * Single integars */ private final static int PATCH_HERBS = 8143; private final static int PATCH_CLEAN = 8132; private final static int PATCH_WEEDS = 8389; private final static int WATER_CAN = 5340; private final static int RAKE = 5341; private final static int SEED_DIBBER = 5343; /* all of our static integers are fine */ private boolean seedPlanted = false, seedWatered = false, patchRaked = false, patchCleaned = false; /* all booleans are false, cool */ /** * Constructor */ public Farming(Client c) { this.c = c; } public void checkItemOnObject(int itemId) { for (int j = 0; j < VALID_SEEDS.length; j++) { if (itemId == VALID_SEEDS[j]) { plantSeed(VALID_SEEDS[j], HERBS[j], HERB_EXPS[j], j); } //so if you use valid seeds on the patch it does plantSeed, cool. } if (itemId == WATER_CAN && !seedWatered) { waterSeed(); //watering is called } else if (itemId == RAKE && !patchRaked) { rakePatch(); //raking is called } else if (c.getItemAssistant().playerHasItem(SEED_DIBBER, 0)); { c.getActionSender().sendMessage("You need a seed dibber to plant seeds."); //if you dont have a seed dibber it gets mad at you. } } private void plantSeed(int seedId, int herbId, int exp, int slot) { if (c.playerLevel[c.playerFarming] < FARMING_REQS[slot]) { c.getActionSender().sendMessage("You require a farming level of " + FARMING_REQS[slot] + " to farm this seed."); } else if (!seedPlanted && patchRaked && c.getItemAssistant().playerHasItem(seedId, 1) && c.getItemAssistant().playerHasItem(SEED_DIBBER, 1)) { c.getItemAssistant().deleteItem(seedId, c.getItemAssistant().getItemSlot(seedId), 1); c.getPlayerAssistant().addSkillXP(SEED_PLANT_EXP[slot] * SkillHandler.FARMING_EXPERIENCE, c.playerFarming); c.startAnimation(2291); c.getPlayerAssistant().refreshSkill(c.playerFarming); int herbAmount = Misc.random(5) + 3; c.farm[0] = herbId; c.farm[1] = herbAmount; c.getActionSender().sendMessage("You plant your seed. Water it and watch it grow."); seedPlanted = true; } else { c.getActionSender().sendMessage("You need to rake the patch or you've already planted a seed!"); } } /* the old handlefarming method, works fine */ private void waterSeed() { if (seedPlanted && !seedWatered) { c.startAnimation(2293); updateHerbPatch(); seedWatered = true; } else { c.getActionSender().sendMessage("You must plant a seed before you can water the patch!"); } } /* seed watering, cool */ public int getExp() { for (int j = 0; j < HERBS.length; j++) { if (HERBS[j] == c.farm[0]) { return HERB_EXPS[j]; } } return 0; } /* this works awesome!!!*/ private void cleanPatch() { if (!patchCleaned) { c.getPlayerAssistant().objectAnim(PATCH_CLEAN, 2813, 3463, -1, 10); patchCleaned = true; } else { c.getActionSender().sendMessage("You have already cleaned the patch."); } } /* cleans off the patch during raking, awesome */ public void updateHerbPatch() { if (c.farm[0] > 0 && c.farm[1] > 0) { c.getPlayerAssistant().objectAnim(PATCH_HERBS, 2813, 3463, -1, 10); } else { c.getPlayerAssistant().objectAnim(PATCH_WEEDS, 2813, 3463, -1, 10); patchRaked = false; seedWatered = false; seedPlanted = false; patchCleaned = false; } } /*updates to herb or weed. the clean patch should be part too but fuck it */ private void rakePatch() { ///step three, once you've planted and watered you can rake the patch clean to pick your herbs. if (!patchRaked && System.currentTimeMillis() - c.waitTime > 2000) { c.startAnimation(2273); cleanPatch(); //calls the clear patch. c.getPlayerAssistant().addSkillXP(getExp() * SkillHandler.FARMING_EXPERIENCE, c.playerFarming); patchRaked = true; } else { c.getActionSender().sendMessage("You must plant and water a seed before you can rake here!"); } } public void pickHerb() { /// Final step, picks the herbs from the grown herb patch. if (c.farm[0] > 0 && c.farm[1] > 0) { if (System.currentTimeMillis() - c.waitTime > 2000) { if (c.getItemAssistant().addItem(c.farm[0], 1)) { c.getPlayerAssistant().addSkillXP(getExp() * SkillHandler.FARMING_EXPERIENCE, c.playerFarming); c.farm[1]--; if (c.farm[1] == 0) { c.farm[0] = -1; } c.startAnimation(2286); c.getActionSender().sendMessage("You pick a herb."); updateHerbPatch(); //finish, lets try this. } } } } }
My PlayerAssistant
PI PlayerAssistantCode:public void objectAnim(int animationID, int X, int Y, int tileObjectType, int orientation) { for (Player p : PlayerHandler.players) { if(p != null) { Client players = (Client)p; if(players.distanceToPoint(X, Y) <= 25) { player.getActionSender().createPlayersObjectAnim(animationID, X, Y, tileObjectType, orientation); } } } }
Code:public void object(int objectId, int objectX, int objectY, int face, int objectType) { synchronized(c) { if(c.getOutStream() != null && c != null) { c.getOutStream().createFrame(85); c.getOutStream().writeByteC(objectY - (c.getMapRegionY() * 8)); c.getOutStream().writeByteC(objectX - (c.getMapRegionX() * 8)); c.getOutStream().createFrame(101); c.getOutStream().writeByteC((objectType<<2) + (face&3)); c.getOutStream().writeByte(0); if (objectId != -1) { // removing c.getOutStream().createFrame(151); c.getOutStream().writeByteS(0); c.getOutStream().writeWordBigEndian(objectId); c.getOutStream().writeByteS((objectType<<2) + (face&3)); } c.flushOutStream(); } } }
Thanks again for the help, I searched the codes from my source and the improved PI Farming and noticed what had to be changed to make it work with my source. The problem is and always has been that after it rakes it immediately says "You need a seed dibber to plant seeds" even though I have one in my inventory and it wont go to the next stage of planting.
Here is the Farming.java
Also the GetItem method which I copied and replaced from PI.Code:package redone.game.content.skills.farming; import redone.game.players.Client; import redone.util.Misc; import redone.game.content.skills.SkillHandler; public class Farming { private Client c; private final static int[] VALID_SEEDS = {5291, 5292, 5293, 5294, 5295, 5296, 5297, 5298, 5299, 5300, 5301, 5302, 5303, 5304}; private final static int[] HERBS = {199, 201, 203, 205, 207, 3049, 209, 211, 213, 3051, 215, 2485, 217, 219}; private final static int[] SEED_PLANT_EXP = {11, 14, 16, 22, 27, 34, 43, 55, 69, 88, 107, 135, 171, 200}; private final static int[] HERB_EXPS = {13, 15, 18, 24, 31, 39, 49, 62, 78, 99, 120, 152, 192, 225}; private final static int[] FARMING_REQS = {1, 14, 19, 26, 32, 38, 44, 50, 56, 62, 67, 73, 79, 85}; /* all of our static integers are fine */ private boolean seedPlanted = false, seedWatered = false, patchRaked = false, patchCleaned = false; /* all booleans are false, cool */ /** * Constructor */ public Farming(Client c) { this.c = c; } public void checkItemOnObject(int itemId) { for (int j = 0; j < VALID_SEEDS.length; j++) { if (itemId == VALID_SEEDS[j]) { plantSeed(VALID_SEEDS[j], HERBS[j], HERB_EXPS[j], j); } //so if you use valid seeds on the patch it does plantSeed, cool. } if (itemId == 5340 && !seedWatered) { waterSeed(); //watering is called } else if (itemId == 5341 && !patchRaked) { rakePatch(); //raking is called } else if (c.getItemAssistant().playerHasItem(5343, 1)); { c.getActionSender().sendMessage("You need a seed dibber to plant seeds."); //if you dont have a seed dibber it gets mad at you. } } private void plantSeed(int seedId, int herbId, int exp, int slot) { if (c.playerLevel[c.playerFarming] < FARMING_REQS[slot]) { c.getActionSender().sendMessage("You require a farming level of " + FARMING_REQS[slot] + " to farm this seed."); } else if (!seedPlanted && patchRaked && c.getItemAssistant().playerHasItem(seedId, 1) && c.getItemAssistant().playerHasItem(5343, 1)) { c.getItemAssistant().deleteItem(seedId, c.getItemAssistant().getItemSlot(seedId), 1); c.getPlayerAssistant().addSkillXP(SEED_PLANT_EXP[slot] * SkillHandler.FARMING_EXPERIENCE, c.playerFarming); c.startAnimation(2291); c.getPlayerAssistant().refreshSkill(c.playerFarming); int herbAmount = Misc.random(5) + 3; c.farm[0] = herbId; c.farm[1] = herbAmount; c.getActionSender().sendMessage("You plant your seed. Water it and watch it grow."); seedPlanted = true; } else { c.getActionSender().sendMessage("You need to rake the patch or you've already planted a seed!"); } } /* the old handlefarming method, works fine */ private void waterSeed() { if (seedPlanted && !seedWatered) { c.startAnimation(2293); updateHerbPatch(); seedWatered = true; } else { c.getActionSender().sendMessage("You must plant a seed before you can water the patch!"); } } /* seed watering, cool */ public int getExp() { for (int j = 0; j < HERBS.length; j++) { if (HERBS[j] == c.farm[0]) { return HERB_EXPS[j]; } } return 0; } /* this works awesome!!!*/ private void cleanPatch() { if (!patchCleaned) { c.getPlayerAssistant().object(8132, 2813, 3463, -1, 10); patchCleaned = true; } else { c.getActionSender().sendMessage("You have already cleaned the patch."); } } /* cleans off the patch during raking, awesome */ public void updateHerbPatch() { if (c.farm[0] > 0 && c.farm[1] > 0) { c.getPlayerAssistant().object(8143, 2813, 3463, -1, 10); } else { c.getPlayerAssistant().object(8389, 2813, 3463, -1, 10); patchRaked = false; seedWatered = false; seedPlanted = false; patchCleaned = false; } } /*updates to herb or weed. the clean patch should be part too but fuck it */ private void rakePatch() { ///step three, once you've planted and watered you can rake the patch clean to pick your herbs. if (!patchRaked && System.currentTimeMillis() - c.waitTime > 2000) { c.startAnimation(2273); cleanPatch(); //calls the clear patch. c.getPlayerAssistant().addSkillXP(getExp() * SkillHandler.FARMING_EXPERIENCE, c.playerFarming); patchRaked = true; } else { c.getActionSender().sendMessage("You must plant and water a seed before you can rake here!"); } } public void pickHerb() { /// Final step, picks the herbs from the grown herb patch. if (c.farm[0] > 0 && c.farm[1] > 0) { if (System.currentTimeMillis() - c.waitTime > 2000) { if (c.getItemAssistant().addItem(c.farm[0], 1)) { c.getPlayerAssistant().addSkillXP(getExp() * SkillHandler.FARMING_EXPERIENCE, c.playerFarming); c.farm[1]--; if (c.farm[1] == 0) { c.farm[0] = -1; } c.startAnimation(2286); c.getActionSender().sendMessage("You pick a herb."); updateHerbPatch(); //finish, lets try this. } } } } }
sorry the first playerHasItem (5343, 1)); should actually be (5343, 0)); I was just seeing if the 1 would change anythingCode:public boolean playerHasItem(int itemID, int amt, int slot) { itemID++; int found = 0; if (c.playerItems[slot] == (itemID)) { for (int i = 0; i < c.playerItems.length; i++) { if (c.playerItems[i] == itemID) { if(c.playerItemsN[i] >= amt) { return true; } else { found++; } } } if(found >= amt) { return true; } return false; } return false; } public boolean playerHasItem(int itemID) { itemID++; for (int i = 0; i < c.playerItems.length; i++) { if (c.playerItems[i] == itemID) return true; } return false; } public boolean playerHasItem(int itemID, int amt) { itemID++; int found = 0; for (int i = 0; i < c.playerItems.length; i++) { if (c.playerItems[i] == itemID) { if(c.playerItemsN[i] >= amt){ return true; } else{ found++; } } } if(found >= amt) { return true; } return false; }
Isn't valid java syntax, doesn't need the ; at the endCode:} else if (c.getItemAssistant().playerHasItem(5343, 1)); {
And it's doing as it's told, the code says "if player has item 5343 tell player they need a seed dibber"
It's probably meant to be the inverse
"} else if(!c.getItemAssist..."
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |