Thread: Need Help Please java.lang.NullPointerException

Results 1 to 10 of 10
  1. #1 Need Help Please java.lang.NullPointerException 
    Registered Member
    Join Date
    Oct 2018
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    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
    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Jul 2018
    Posts
    121
    Thanks given
    82
    Thanks received
    55
    Rep Power
    0
    Post your full checkitemonobject method
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Oct 2018
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Zac View Post
    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.
            }
    
        }
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Jul 2018
    Posts
    121
    Thanks given
    82
    Thanks received
    55
    Rep Power
    0
    Quote Originally Posted by Dravon View Post
    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.
            }
    
        }
    How did you run without the method lmao...
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Oct 2018
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Zac View Post
    How did you run without the method lmao...
    No errors
    Reply With Quote  
     

  6. #6  
    Renown Programmer
    Greg's Avatar
    Join Date
    Jun 2010
    Posts
    1,179
    Thanks given
    260
    Thanks received
    1,012
    Rep Power
    2003
    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.

    Code:
    farming = new Farming(this);
    is what I would assume it should look like, in a method along the lines of "init()" or "initEntity()"
    It probably doesn't exist, which is why you are getting this error.
    Attached imageAttached image
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Oct 2018
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Greg View Post
    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.

    Code:
    farming = new Farming(this);
    is what I would assume it should look like, in a method along the lines of "init()" or "initEntity()"
    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
    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.
                    }
                }
            }
        }
    }
    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.

    My PlayerAssistant
    Code:
    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);	
    				}
    			}
    		}
    	}
    PI PlayerAssistant
    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();
    			}	
    		}
    	}
    Reply With Quote  
     

  8. #8  
    Renown Programmer
    Greg's Avatar
    Join Date
    Jun 2010
    Posts
    1,179
    Thanks given
    260
    Thanks received
    1,012
    Rep Power
    2003
    Quote Originally Posted by Dravon View Post
    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
    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.
                    }
                }
            }
        }
    }
    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.

    My PlayerAssistant
    Code:
    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);	
    				}
    			}
    		}
    	}
    PI PlayerAssistant
    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();
    			}	
    		}
    	}
    Yeah couldn't tell you the exact issue, but

    Code:
    c.getPlayerAssistant().objectAnim(PATCH_HERBS, 2813, 3463, -1, 10);
    Definitely doesn't look correct.

    Farming patches change using configs, not via object spawning or animations. So might be a good idea to look into those.
    Attached imageAttached image
    Reply With Quote  
     

  9. #9  
    Registered Member
    Join Date
    Oct 2018
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Greg View Post
    Yeah couldn't tell you the exact issue, but

    Code:
    c.getPlayerAssistant().objectAnim(PATCH_HERBS, 2813, 3463, -1, 10);
    Definitely doesn't look correct.

    Farming patches change using configs, not via object spawning or animations. So might be a good idea to look into those.
    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

    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.
                    }
                }
            }
        }
    }
    Also the GetItem method which I copied and replaced from PI.

    Code:
    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;
    	}
    sorry the first playerHasItem (5343, 1)); should actually be (5343, 0)); I was just seeing if the 1 would change anything
    Reply With Quote  
     

  10. #10  
    Renown Programmer
    Greg's Avatar
    Join Date
    Jun 2010
    Posts
    1,179
    Thanks given
    260
    Thanks received
    1,012
    Rep Power
    2003
    Quote Originally Posted by Dravon View Post
    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

    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.
                    }
                }
            }
        }
    }
    Also the GetItem method which I copied and replaced from PI.

    Code:
    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;
    	}
    Code:
    } else if (c.getItemAssistant().playerHasItem(5343, 1));
            {
    Isn't valid java syntax, doesn't need the ; at the end

    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..."
    Attached imageAttached image
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Need help with java.lang.error
    By noob121 in forum Help
    Replies: 0
    Last Post: 04-09-2016, 05:38 AM
  2. Need help please - java - vps - centos6
    By loco1988 in forum Help
    Replies: 2
    Last Post: 10-11-2015, 06:25 AM
  3. Replies: 11
    Last Post: 01-08-2014, 02:28 PM
  4. Replies: 2
    Last Post: 09-20-2013, 08:20 PM
  5. java.lang.NullPointerException - HELP
    By rofl-pvp in forum Help
    Replies: 5
    Last Post: 04-10-2013, 02:52 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •