Sign in to follow this  
joedobo

[WIP] Various Farming changes, like crops don't turn to weeds.

Recommended Posts

3. Buff farm yields

in the server's Terraforming.class (com.wurmonline.server.behaviours) and under the harvest method is a line kinda like the one on top and what I changed is on the bottom:

short bonusYield = (short)((int)((float)resource / div / 1.5F));short bonusYield = (short)((int)((float)resource / div / 1.5F) + 2 );

This add 2 more crops to all outcomes.

 

 

 

 

i meant this from joes first post...

is this really so complicated? i dont have any idea of java like i told you before XD

Edited by Biervampyr

Share this post


Link to post
Share on other sites

Regards to the yield buff, we can increase the farm growth frequency. Effectively this does the same thing. I only added that yield buff thing because Tich's WO 1.1 farming nerf pissed me off and I wanted to undue it asap.


 


If you set your farming growth frequency variable to 0.5 you can have ripe fields in 2 to 3 hours. I guess if your trying to make an experience very similar to WO it would be more important.


 


 




i meant this from joes first post...


is this really so complicated? i dont have any idea of java like i told you before XD


 




 


I don't understand Ago's modding approach well enough to better explain what he means by say yield buffing is "deep" in the method. The line where I added two to the bonusYield is deep in the Terraforming.class, harvest() method. There is a lot going on in that method.


Share this post


Link to post
Share on other sites

There are basicly two approaches to modding.

* Decompile to source, make changes, recompile to class and replace the class

This give the greatest freedom of what you can do in the code since you can completly change the behaviour.

The downside is the static nature. If two people want to modify then same class then only one set of changes can be used unless they work together to merge the changes.

This also depends on the decompiler to do the right things. Procyon sometimes misses a cast to float which results in bugs when the code is recompiled.

* Bytecode manipulation / Dynamicly change the code

This is what I'm doing in my modloader. During class loading I rename some method and create wrapper mapper to replace them.

During execution the wrapper methods are called and can perform stuff before, after or instead of the original code. So far there is no way to change stuff in the method body like adding a "+2" to the farm yield.

The advantage is independence from the original code. The wrapper will work as long as the method parameters do not change. It'll work with the original class or modfied classes.

But it also needs a separate loader to do the changes to the class files before they are loaded.

  • Like 1

Share this post


Link to post
Share on other sites

Is the crop age a single byte, or can it hold a larger value?


If it can, add more crop ages to the logic, say 32, and make 6 through 31 be ripe, 32 weeds.


 


EDIT:  I just re-read Ago's post.  This won't work unless the tile structure is changed.  Sorry about that.

Edited by Ricowan

Share this post


Link to post
Share on other sites

 unless they work together to merge the changes.

 

 

So far there is no way to change stuff in the method body like adding a "+2" to the farm yield.

 

Is it unrealistic to think that there can be a standard modders client and server jar file? With this any modder can request his or her customization be added in. I suspect the job of making sure there aren't any technical problems would be excessive. Especially since many inexperience coders will try out modding.

 

Instead of trying to add 2 couldn't the modder copy all the code from the server's method and make a new method incorporating the +2 in your loader. It would run instead of the one in the server?

Edited by joedobo

Share this post


Link to post
Share on other sites

Is it unrealistic to think that there can be a standard modders client and server jar file? With this any modder can request his or her customization be added in. I suspect the job of making sure there aren't any technical problems would be excessive. Especially since many inexperience coders will try out modding.

Yes, it'd probably be a nightmare to maintain.

 

Instead of trying to add 2 couldn't the modder copy all the code from the server's method and make a new method incorporating the +2 in your loader. It would run instead of the one in the server?

I just got through all the byte code and managed to change this

int quantity = (int)((baseYield + bonusYield) * ageYieldFactor);
to this

int quantity = (int)((baseYield + bonusYield) * ageYieldFactor) + 123;
But writing Java byte code is hardly a useful way. Javassist allows changing the method body with java source code. Maybe that's a solution.

Calling a replacement method will work too but may require changes to field and method visibility. the harvest() method uses the Crops class which is not public.

Edited by ago

Share this post


Link to post
Share on other sites

I would love to have woad added to the farming growth list, use one of the 2 available slots. This way you wouldn't have to forage for your supplies.

Share this post


Link to post
Share on other sites

I attempted to add the Terraforming.class and the croptilepoller.class files for the "crops not turning into weeds" mod into the .class file and add it to the .jar and it didn't work, the server won;t run. although i think it's because i dont have the propor programs to try this...What would be some free programs that can be used to open and mod the .class files?


 


 


Edit: I Found a program "Java Decompiler" or "JD-Gui" as it is installed as from http://jd.benow.ca/


 


I'm going to test this a bit.


Edited by KainZero

Share this post


Link to post
Share on other sites

I highly recommend Intellij IDEA. The free community edition works fine and is really easy to work with.

Share this post


Link to post
Share on other sites

I'm going to download and try this one now, thanks! that being said, I tried making the changes from the first post, but does the .class need to be changed in the .jar on my  dedicated server, or on the .jar for the game itself? and I have a modded .class in the game from another mod "digging like mining" (http://forum.wurmonline.com/index.php?/topic/132826-wip-digging-like-mining/)


Share this post


Link to post
Share on other sites

The changes need to be made to the decompiled .java file, then recompiled into .class, and then placed in the server.jar on which ever machine is running the server. If you aren't interested in making the changes yourself, you can use the .class file provided in this thread and simply place it in the server.jar.


Share this post


Link to post
Share on other sites

There are no class flies in this thread. I don't want to do that because it's a hassle for me.


 


The OP thread tells you want to change.


 


Ago made a farming related mod addition for his mod loader tool that will stop weeds. Its a few posts up from here.


 


"digging like mining" changes the Terraforming.class.  When you drop class files into your server.jar file that class will replace whatever is in your server.jar. The act of one file replacing another and that modders aren't collaborating so far results in one modder's work replacing anothers. A few changes in this farming thread do alter the Terraforming.class and so a compiled class file with just these farming changes would override the changes made for "digging like mining". It is possible that one could provide class files that include both changes but that is where the problem comes in. I'm pretty sure modders don't want to provide countless combination of differently combined modded class files.


 


I'm looking at Javassist now (http://jboss-javassist.github.io/javassist/). It has the potential to do what we need which is basically dynamically inject and alter code in the server or client's classes. Its just that it is complicated stuff for noob like me and is taking time to understand it.


Share this post


Link to post
Share on other sites

okay thanks, I've tried to use the .class from the other mod with the changes from this one as far as stopping growing past a certain point. I added the changes to the second .class and the first but the server wont load, then I did the change to only the terraforming.class, and still no joy...so i did the changes to only the other .class mentioned and it ran, but the plants literally wont grow at all, so for now I'm going to just keep my files unchanged since I reallllllly like having the digging like mining mod, due to the amount of leveling im having to do at the moment


Share this post


Link to post
Share on other sites

Im completely green to this and the stuff up there is greek to me. 


 


Could one of you wise men explain very simple, is this a safe thing to do to a server? I have one rented at bluefantsolutions, with a few players on. If i were to edit the files to stop field rot.  Would my players have to do anything? Or would server side settings be enough?


Im only interested in the first option btw.


 


If its all good and safe thats a incredible improvement, as many cant really play for as long it takes to reach ripe stage of crops. They usually return to a field of rotted weeds.


Share this post


Link to post
Share on other sites

(most) server mods are only needed at the server level. And for the most part, it is safe to make these changes, I would recommend testing them out locally before uploading the modified server.jar to your public server though.


  • Like 1

Share this post


Link to post
Share on other sites

(most) server mods are only needed at the server level. And for the most part, it is safe to make these changes, I would recommend testing them out locally before uploading the modified server.jar to your public server though.

Share this post


Link to post
Share on other sites

Im way to retarded for this, i did find the line in the class file, but I dont know how to edit it. Also, from what im seeing you say about decompiling, editing, putting back together. Im sure i would break something before i actually got it working. 


 


Will this be available as a mod at some point? Or would that be unlikely?


 


If it wont, i guess i should keep trying, but how do i actually change that "7" in the growFarm line to a "6"?


Edited by Tallion

Share this post


Link to post
Share on other sites

Im way to retarded for this, i did find the line in the class file, but I dont know how to edit it. Also, from what im seeing you say about decompiling, editing, putting back together. Im sure i would break something before i actually got it working. 

 

Will this be available as a mod at some point? Or would that be unlikely?

 

If it wont, i guess i should keep trying, but how do i actually change that "7" in the growFarm line to a "6"?

  • Like 1

Share this post


Link to post
Share on other sites

I took server.jar and opened it with 7zip, finding all the .class files.


 


I used DJ Java Decompiler to open the two .class files listed in the original post and made one change in each file, changing the integer 7 to 6.


 


I saved the file to my desktop, resulting in Terraforming.java and CropTilePoller.java


 


I used the official Java 8 development kit to attempt to first recompile Terraforming.java using "javac Terraforming.java" but it failed. It gave me ONE HUNDRED errors, all of which are on lines of code that I did not edit.


 


What am I doing wrong? Do I need to use a different decompiler? Do I need to use a different java version to compile this .java into .class?


Edited by StanleyClark

Share this post


Link to post
Share on other sites

So does the stopping from turning to weeds work alright? After I decompile it I get a lot of errors when I try to recompile I am using JD gui to decompile. Should I be doing something different? I have only changed those 2 7 to 6


Share this post


Link to post
Share on other sites

....

 

....

 

Yes it works, I'm using it now. I only know how to use Intellij IDEA. I bet you all's problem is you didn't provided some kind of a library reference to the common.jar and server.jar.

 

Anyway, I made a video using intellij that hopefully will help solve your problems. It's about a different change. However, the actual code changes are all that is different and all other steps are the same.

http://forum.wurmonline.com/index.php?/topic/134211-quick-video-of-using-intellij-to-make-a-serverjar-code-change/

Share this post


Link to post
Share on other sites

Tried to compile (com.wurmonline.server.behaviours.Terraforming) but i keep getting 5-6 error messages.

 

Error messages below. Halp?

1.Error:(88, 24) java: cannot find symbol
  symbol:   class Nullable
  location: package javax.annotation                    - source import javax.annotation.Nullable;
 
2.Error:(3674, 115) java: cannot find symbol
  symbol:   class Nullable
  location: class com.wurmonline.server.behaviours.Terraforming           - source static boolean harvest(Creature performer, int tilex, int tiley, boolean onSurface, int tile, float counter, @Nullable Item item) {
 
3.Error:(4326, 69) java: cannot find symbol
  symbol:   class Nullable
  location: class com.wurmonline.server.behaviours.Terraforming      - source public static Set<int[]> getEastMineDoor(int tilex, int tiley, @Nullable Set<int[]> toReturn) {
 
4. Error:(4338, 70) java: cannot find symbol
  symbol:   class Nullable
  location: class com.wurmonline.server.behaviours.Terraforming     - source public static Set<int[]> getNorthMineDoor(int tilex, int tiley, @Nullable Set<int[]> toReturn) {
 
5. Error:(4350, 70) java: cannot find symbol
  symbol:   class Nullable
  location: class com.wurmonline.server.behaviours.Terraforming     - source public static Set<int[]> getSouthMineDoor(int tilex, int tiley, @Nullable Set<int[]> toReturn) {

Edited by PleagueX

Share this post


Link to post
Share on other sites

Yes it works, I'm using it now. I only know how to use Intellij IDEA. I bet you all's problem is you didn't provided some kind of a library reference to the common.jar and server.jar.

 

Anyway, I made a video using intellij that hopefully will help solve your problems. It's about a different change. However, the actual code changes are all that is different and all other steps are the same.

http://forum.wurmonline.com/index.php?/topic/134211-quick-video-of-using-intellij-to-make-a-serverjar-code-change/

By the way, thank you for the video. You taught me how to do this. I managed to get the ItemTemplateCreator and CropTilePoller to work and compile flawlessly, however not so much with terraforming. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this