Jump to content

Decreasing max stack sizes


tuxwonder

Recommended Posts

Hi, I'm new to Minecraft modding (not at all new to programming in general though, no worries), and I'm trying to implement what I thought would be a relatively simple mod to decrease the max stack size of almost all the vanilla items in the game that aren't already at max stack size 1. The goal is to run a multiplayer server with this mod. I've heard read that I'll probably have to re-register all the blocks in the game I want to be modified with new stack size values.

The questions I have are:

1. Is this the easiest strategy for implementing a mod/change like this? Am I correct in understanding it requires re-registering all blocks?

2. If so, what classes in the API should I be looking at for A. grabbing the existing vanilla items in the game, and then B. registering changes made to them? Example code is nice too, but in lieu of that a few pointers to the API will be just fine.

Honestly, I'm mostly just in a bit of disbelief that this seems to be the solution I have to take, why isn't the most popular game on earth more configurable? It seems like you should just be able to modify the value in a datapack, but here we are.

Link to comment
Share on other sites

No dice unfortunately. This is more or less my code:

@Mod("arducraft")
public class ArducraftMod {

  public ArducraftMod() {
    FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onCommonSetup);
  }

  private void onCommonSetup(FMLCommonSetupEvent event) {
    event.enqueueWork(new Runnable() {
      public void run() {
        try {
          Field stackSizeField = Items.COBBLESTONE.getClass().getDeclaredField("maxStackSize");
          stackSizeField.setAccessible(true);
          stackSizeField.set(Items.COBBLESTONE, 4);
          LOGGER.info("Successfully set COBBLESTONE size to 4");
        } catch (NoSuchFieldException ex) {
          LOGGER.error("Failed to set COBBLESTONE size (NoSuchFieldException): " + ex.getMessage());
        } catch (IllegalAccessException ex) {
          LOGGER.error("Failed to set COBBLESTONE size (IllegalAccessException): " + ex.getMessage());
        }
      }
    });
  }
}

With an output of:

[12:28:51] [Render thread/ERROR]: Failed to set COBBLESTONE size (NoSuchFieldException): maxStackSize

Based on the code I found here

Link to comment
Share on other sites

I figured it my above issue, I had to replace the line getting the field to:

Field stackSizeField = Item.class.getDeclaredField("maxStackSize");

Which seems silly because I see no reason they shouldn't do the exact same thing... But this wouldn't be the first time Java has surprised me with how screwy it is!

Thanks for the tip

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.