Sign in to follow this  
joedobo

Is there a better way to deal with ItemTemplateCreator class?

Recommended Posts

I made a mod for mod launcher that changes a bunch of things in the server.jar's ItemTemplateCreator class. My approach is to copy from a modified class I created ("BigContainersCopy", in source 7z) and use "setbody()" to change the methods in the server.jar into the ones in my modified class.

 

I"m not sure if this is a good way to do this but there is so much going on in the ItemTemplateCreator (and its continued class cousin) that I don't know of any other way. A major problem with this is it would change other modders changes to this same method and visa versa.

 

Any thoughts? Thank you.

 

source:

https://dl.dropboxusercontent.com/u/27144902/bigcontainersBAEAmodsrc.7z

 

here's the mod file (it's in the source 7z also).

Spoiler

package com.jase2z.WUmod;


import javassist.*;

import org.gotti.wurmunlimited.modloader.classhooks.HookException;

import org.gotti.wurmunlimited.modloader.classhooks.HookManager;

import org.gotti.wurmunlimited.modloader.interfaces.Configurable;

import org.gotti.wurmunlimited.modloader.interfaces.Initable;

import org.gotti.wurmunlimited.modloader.interfaces.WurmMod;


import java.util.Properties;


public class BigContainersBAEAMod implements WurmMod, Initable, Configurable {

    public void configure(Properties properties) {

    }


    public void init() {

        try {

            CtClass ctcItemTemplateCreator = HookManager.getInstance().getClassPool().get("com.wurmonline.server.items.ItemTemplateCreator");

            CtClass ctcItemTemplateCreatorContinued = HookManager.getInstance().getClassPool().get("com.wurmonline.server.items.ItemTemplateCreatorContinued");

            CtClass ctcBigContainersMod = HookManager.getInstance().getClassPool().get("com.jase2z.WUmod.BigContainersCopy");


            CtMethod ctmInitialiseItemTemplates = ctcItemTemplateCreator.getMethod("initialiseItemTemplates", "()V");

            CtMethod ctmInitialiseItemTemplates1 = ctcBigContainersMod.getMethod("initialiseItemTemplates", "()V");

            ClassMap classMap = new ClassMap();

            // Had to use BigContainersMod class in one case because of Private in server.jar.

            // This will map all occurrences of BigContainersMod to ItemTemplateCreator.

            classMap.put(ctcBigContainersMod.getName(), ctcItemTemplateCreator.getName());

            ctmInitialiseItemTemplates.setBody(ctmInitialiseItemTemplates1, classMap);


            CtMethod ctmInitializeTemplates = ctcItemTemplateCreatorContinued.getMethod("initializeTemplates", "()V");

            CtMethod ctmInitializeTemplates1 = ctcBigContainersMod.getMethod("initializeTemplates", "()V");

            ctmInitializeTemplates.setBody(ctmInitializeTemplates1, null);


        } catch (NotFoundException| CannotCompileException e) {

        throw new HookException(e);

        }

    }

}

 

 

P.S. If you're curious the mod:

Spoiler

mod: https://dl.dropboxusercontent.com/u/27144902/bigcontainersBAEAmod.7z

 

Big containers be-all-end-all mod.

 

1. Makes containers bigger on the inside then outside and sets the internal dimensions to something close to the largest possbile number without getting erros. Contianer x, y, and Z values are used by a volume method that multiplies them and returns a integer. One possible way to find the largest value is to take the cube root on Max Interger. I rounded down to a nice even number and set all containers to (1200, 1200, 1200).

 

2. remove all the "one item per tile" flags. well almost, I left some in place for those epic thingies.

 

3. Add many items to bulk storage bins by adding the bulk type flag: fish, slabs, pelts, mushrooms.

 

4. change the external size of a couple things: smaller pelts, smaller mushrooms for 5 and 4 HC and rest big pumpkin-size mushroom for food.

 

5. make more things loadable: atars, boats loaded into anything (well part of it anyway, the other part is changes to "CargoTransportationMethods" which I"ll do in another mod.) and  couple others.

 

Note, you don't want to change the external size of too many things as Wurm's code for proximity requirements to interact with an object (for example, place/take things from a dragged cart's inventory) scales the distance based on object size. Make something too small and suddenly you'll have stand right on top of it do anything.

 

 

Edited by joedobo
  • Like 1

Share this post


Link to post
Share on other sites

Does this work with Ago's Mod loader?  and would it have a conflict with Bag of Holding spell especially if its already on some containers?


Edited by Drpox

Share this post


Link to post
Share on other sites

I'd probably patch the templates after initialiseItemTemplates()

ReflectionUtil.setPrivateField can be used to change the internals of each template

 

Map<Integer, ItemTemplate> templates = (Map<Integer, ItemTemplate>) ReflectionUtil.getPrivateField(ItemTemplateFactory.class, ReflectionUtil.getField(ItemTemplate.class, "templates"));Field fieldUsesSpecifiedContainerSizes = ReflectionUtil.getField(ItemTemplate.class, "usesSpecifiedContainerSizes");for (Itemtemplate template : templates) {   if (template.isHollow()) {       ReflectionUtil.setPrivateField(template, fieldUsesSpecifiedContainerSizes, Boolean.TRUE);       template.setContainerSize(1200, 1200, 1200);   }}
Edited by ago
  • Like 2

Share this post


Link to post
Share on other sites

Does this work with Ago's Mod loader?  and would it have a conflict with Bag of Holding spell especially if its already on some containers?

This would conflict with the Bag of Holding spell since the bag of holding spell will increase the volume even more and probably push it over the max allowed integer value.

Share this post


Link to post
Share on other sites

ahh okay,


thank you very much


 


I am wondering if 2, 3, 4, 5 parts of the mod could be seperated from the mod?


 


I will test this mod with ago's mod Boh on a private server and see if it causes issues?


Edited by Drpox

Share this post


Link to post
Share on other sites

I'm going to try and do what Ago suggested in concept to change the other things.


 


in the mean time...


Every container has been set to that huge number. I'm not sure why one wouldn't just disable bag-of-holding. Since every container is magnitudes larger on the inside then the outside you can nest any container infinitely in repetition. You could put 100 jewelry smithing bowls/cauldrons/pottery bowls/sauce pans in a forge and each of those bowl holds many times what goes in a Caravel for default WU.

Share this post


Link to post
Share on other sites

I think its because he has the Bag of holding integral to his spell mod.  I may be mistaking and will have to look at it when i get home.


 


Turns out its a separate mod :) so I can disable it :)​


Edited by Drpox

Share this post


Link to post
Share on other sites

Actually just tested this.  They work together quite well.  No hangups or server errors. :)


Share this post


Link to post
Share on other sites

So how would I install this?

Could you make it modlauncher compatible please?

 

Basically, I want to use this to make several 'fountain pan' type items to hide away, then turn this off so regular players can't utilise it, making these nested containers extra rare for event rewards...

 

Thanks

Share this post


Link to post
Share on other sites

No, it isn't... the file that downloads just has a few nested folders and 2 .java files.... they won't do anything if I drop them into the /mods folder of my dedicated server...

 

Which bring me back to the first line of my original post.. how do I install this?

Share this post


Link to post
Share on other sites

Okay, I just know that I am currently using the mod the same way I am using a few others that are mod loader compatible.  Are you downloading the BigcontainersBAEAmod?

 

Let me cut and paste the part of the first post for you:

mod: https://dl.dropboxusercontent.com/u/27144902/bigcontainersBAEAmod.7z

Big containers be-all-end-all mod.

1. Makes containers bigger on the inside then outside and sets the internal dimensions to something close to the largest possbile number without getting erros. Contianer x, y, and Z values are used by a volume method that multiplies them and returns a integer. One possible way to find the largest value is to take the cube root on Max Interger. I rounded down to a nice even number and set all containers to (1200, 1200, 1200).

2. remove all the "one item per tile" flags. well almost, I left some in place for those epic thingies.

3. Add many items to bulk storage bins by adding the bulk type flag: fish, slabs, pelts, mushrooms.

4. change the external size of a couple things: smaller pelts, smaller mushrooms for 5 and 4 HC and rest big pumpkin-size mushroom for food.

5. make more things loadable: atars, boats loaded into anything (well part of it anyway, the other part is changes to "CargoTransportationMethods" which I"ll do in another mod.) and  couple others.

Note, you don't want to change the external size of too many things as Wurm's code for proximity requirements to interact with an object (for example, place/take things from a dragged cart's inventory) scales the distance based on object size. Make something too small and suddenly you'll have stand right on top of it do anything.

 

 

Edited by Drpox

Share this post


Link to post
Share on other sites

ahh ok... I'm an idiot lol

 

Thats what I get for staying awake for 36 hrs and then trying to do technical things.... *sigh*

 

Thanks Drpox

Share this post


Link to post
Share on other sites

Is there something in this mod that changes the Dredges capacity for dirt to 1 and causes the server to crash??  My server started crashing tonight, and only mod I have that effects dredges is the Bigcontainers mod.  I was wondering if you could take a peak and see if this breaks dredges?

Share this post


Link to post
Share on other sites
17 hours ago, Drpox said:

Is there something in this mod that changes the Dredges capacity for dirt to 1 and causes the server to crash??  My server started crashing tonight, and only mod I have that effects dredges is the Bigcontainers mod.  I was wondering if you could take a peak and see if this breaks dredges?

I didn't do anything to the dredge. I tested this out and didn't experience any issues.

 

On 11/20/2015, 4:50:37, Vanyel said:

Basically, I want to use this to make several 'fountain pan' type items to hide away, then turn this off so regular players can't utilise it, making these nested containers extra rare for event rewards...

I am not sure if this will work. The ".setContainerSize(x, y, z)'" thing ends up getting used even after the object is created (I believe anyway). What this means is that items will end up using the smaller original numbers when you disable the mod. Now, if you could enable the mod and put a big container inside a small one and then disable the mod it should work. One problem with a fountain is I don't think you can pick it up into inventory so you can drag it into say a sauce pan. Fountains have to be loaded. 

Share this post


Link to post
Share on other sites

Anyone know more ways to access the itemTypes entry for the ItemTemplateCreator? I'm having trouble finding a way to check if an entry has the ITEM_TYPE_ONE_PER_TILE flag and then I want to remove it if so.

 

Some of the itemType flagses I can access. Here is the code I got so far. Using IntelliJ's suggestive code I'm not seeing any possibilities. I think the problem is I'm looking in the wrong area. 

source at:  http://pastebin.com/QpqpUWXg

 

UPDATE...got it working. 1) I had the reflection code in the wrong modlauncher section and 2) contrary to Ago's code example, ItemTypes.class does not have a templates field. Changing that bit to ItemTemplateFactory.class solved it.

this edit's source: http://pastebin.com/ryq421kF

Edited by joedobo

Share this post


Link to post
Share on other sites

Feels almost as if i'm having a conversation with myself here. I want to document this anyway.

 

I finished changing this over so that it uses reflection. Here is a link to the source: http://pastebin.com/PWpw1nta.

 

I'm not sure how to make this into a proper mod. All the options needed so folks could change whatever would be numerous. Another approach would be to do separate simple standalone mods for popular things, etc: smaller pelts, loadable altars.

Anyway, my intent was to experiment and share the results more so then make an official mod.

Share this post


Link to post
Share on other sites

With the loadable altars, are they also movable?(Push,Pull,etc) I'd love to have it as a standalone mod!

Share this post


Link to post
Share on other sites

Fantastic Mod here.  Question: what are the limits you can set for the capacity of crates, or volumes of BSBs and FSBs?

 

 

Share this post


Link to post
Share on other sites
36 minutes ago, Wurmhole said:

Fantastic Mod here.  Question: what are the limits you can set for the capacity of crates, or volumes of BSBs and FSBs?

I'd say a potential for a neat mod if I could figure out a good way to add options for every possible combination of item and configuration.  At the moment is more of a blog of my journey.

 

Crates are weird. I haven't messed with them at all. (imo) It was a mistake to add a new item to the game the defies Wurm's longstanding storage mechanics.

 

BSB and FSB by default have dimensions of: 200, 200, 400 (volume of 16,000). I changed those numbers to 1200, 1200, 1200 (volume of 1,728,000).

 

I haven't tested it to see what values actually break the server. Limits are defined by the data types which Wurm uses to store the x, y, and z dimensions. Those are integers thus 2^31-1. Although, those dimensions are used in a method that multiplies them together to get volume which is also an integer.  I guessed a good maximum value I could use was the cube root of Java's max integer value. The approximate value is 1,290. I rounded down to 1200 because it's even and I'm a safe distance from max integer.

I don't need larger anyway. The 1200 cubed value makes a container that is 100 times larger. If you combine this with loadable bins (empty or not) it works well.

 

 

What I'd really like to make is a way to have have containers be more unique and toggle between standard and bulk type. For example, lets say you made two small barrels. One would be the standard we know well. The other would be a small barrel with double the volume (increase the outside dimensions) and store bulk type items. I'd choose some tool in game to change between bulk storage and standard storage. It wouldn't require anything special to change. Increasing size would require either making magic rifts (bigger on the inside then the outside) inside it or using some kind of a expansion kit (physically larger item) on it.

The changes I've made so far alter the template used to create new item and thus alter all items of like type. I need to look more at individual items and the data base to see what is possible.

Edited by joedobo

Share this post


Link to post
Share on other sites

Hello Joedobo,

Iis there something about this mod with the current update that would prevent opening BSBs and FSBs? When I disable the mod I can access my bsbs, fsbs.  When I reenabled it I get "refreshing"  even when I went and created a brand new BSB it would let me drop it from gm inventory. 

 

Good news though, disabling the mod has led so some hilarious high jinks with some BSBs with 10k dirt in them.  We can still pull the dirt out but till we get under the 853 max we wont beable to add more.

Edited by Drpox

Share this post


Link to post
Share on other sites

I'd guess this is broken because the the copy being used to replace is based on code from december 2015.

 

I can make something like this in function that doesn't use a copy and replace, but it uses reflection. The only problem with maxing containers happens when you fill them with liquid (usualy water). I can make all containers that don't have ITEM_TYPE_CONTAINER_LIQUID item type flag be big.

Share this post


Link to post
Share on other sites

I can also confirm, that BSBs and FSBs are not openable anymore with this mod + WU update.

 

Hangs at "refreshing".

I hope for an update soon, if its not oo big of a hassle.

 

Also... can you exclude the "fish and stuff go to FSB" stuff from the "huge containers" stuff, please?

As I primarily use that mod for the fish into the FSB and I guess that one is easy to make and maintain anyway?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this