Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.13] How to add a custom game rule?
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 1
qouteall

[1.13] How to add a custom game rule?

By qouteall, March 10 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

qouteall    0

qouteall

qouteall    0

  • Tree Puncher
  • qouteall
  • Members
  • 0
  • 10 posts
Posted March 10 (edited)

GameRules class has a private field storing all types of game rules.

public class GameRules {
	//...
	private final TreeMap<String, GameRules.Value> rules = new TreeMap<>();
	//...
}

If I use access transformer to make it public then I can add a new game rule.

But in GameRuleCommand class:

public class GameRuleCommand {
   public static void register(CommandDispatcher<CommandSource> dispatcher) {
      LiteralArgumentBuilder<CommandSource> literalargumentbuilder = Commands.literal("gamerule").requires((p_198491_0_) -> {
         return p_198491_0_.hasPermissionLevel(2);
      });

      for(Entry<String, GameRules.ValueDefinition> entry : GameRules.getDefinitions().entrySet()) {
         literalargumentbuilder.then(Commands.literal(entry.getKey()).executes((p_198489_1_) -> {
            return queryRule(p_198489_1_.getSource(), entry.getKey());
         }).then(entry.getValue().getType().createArgument("value").executes((p_198490_1_) -> {
            return setRule(p_198490_1_.getSource(), entry.getKey(), p_198490_1_);
         })));
      }

      dispatcher.register(literalargumentbuilder);
   }

   //...
}

It reads all the game rule types and creates the command format structure. If I add the game rule after the command registered, the /gamerule command will not work on my custom game rule.

Edited March 10 by qouteall
  • Quote

Share this post


Link to post
Share on other sites

peter1745    4

peter1745

peter1745    4

  • Tree Puncher
  • peter1745
  • Members
  • 4
  • 26 posts
Posted March 10

You can do something like this:

private void doClientStuff(final FMLClientSetupEvent event)
{
  GameRules.getDefinitions().put("test", new GameRules.ValueDefinition("1", GameRules.ValueType.NUMERICAL_VALUE));
}

 

There's also a method in GameRules called setOrCreateGameRule, however that doesn't actually seem to create a gamerule, only sets the value, so that probably should only be used when setting the value, not creating the gamerule.

 

Quick tip: If you're trying to do something that vanilla already does (GameRules, Commands, etc...), look through the code and look at how vanilla does it, or just dig around the code and try to figure out how to solve your problem 🙂

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

qouteall    0

qouteall

qouteall    0

  • Tree Puncher
  • qouteall
  • Members
  • 0
  • 10 posts
Posted March 11

It works. Thanks.

  • Quote

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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • AdieCraft
      Japanese Style Temple Base

      By AdieCraft · Posted 17 minutes ago

      Hello there!   Check out my latest tutorial in my Japanese Builds series, building a Japanese Temple base.   Make sure to Subscribe, so you don't miss any future videos.   Thanks   Adie   Japanese Style Temple Base    
    • DaemonUmbra
      Forge crashes on start

      By DaemonUmbra · Posted 57 minutes ago

      Forge for 1.13+ requires Java 8-10 Forge for 1.12.2- requires Java 8
    • GttiqwT
      [1.12.2] Multiple Structure Generation

      By GttiqwT · Posted 1 hour ago

      Yeah I get where you're coming from. I also watched harry talk's tutorial and at first it worked but then I got the problem that it wont spawn more than one structure otherwise it'll overlap and only spawn the latest one added. I tried to follow this tutorial again and it just didnt seem to work at all now. When I get more time ill have to do it again and then afterwards try and fix the issues with spawning more than one structure. I'm currently trying to fix the issue where it causes cascading gen lag but I dont know how to fix that quite yet either.
    • Draco18s
      Distinguish singleplayer vs. multiplayer

      By Draco18s · Posted 1 hour ago

      No. Your client code is sending information to make the server do things. Your server code is telling the server to do those same things (again).
    • solitone
      Distinguish singleplayer vs. multiplayer

      By solitone · Posted 2 hours ago

      This isn’t an issue but normal behaviour, is it?
  • Topics

    • AdieCraft
      0
      Japanese Style Temple Base

      By AdieCraft
      Started 17 minutes ago

    • bitman
      1
      Forge crashes on start

      By bitman
      Started 2 hours ago

    • Merthew
      7
      [1.12.2] Multiple Structure Generation

      By Merthew
      Started November 7, 2018

    • solitone
      24
      Distinguish singleplayer vs. multiplayer

      By solitone
      Started December 5

    • TheGreenSquarez
      5
      Forge 28.1.10 won't show on launcher + 28.1.0 fails to work

      By TheGreenSquarez
      Started Wednesday at 11:21 AM

  • Who's Online (See full list)

    • Mango106
    • Creeperslayercc
    • Gamercraft99
    • Alpvax
    • thinkverse
    • AdieCraft
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.13] How to add a custom game rule?
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community