Skip to content

Commit

Permalink
set gamerule
Browse files Browse the repository at this point in the history
  • Loading branch information
friendlyhj committed Jan 16, 2025
1 parent f0b687f commit 5e87800
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/java/youyihj/zenutils/api/world/GameRuleHelper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package youyihj.zenutils.api.world;

import crafttweaker.annotations.ZenRegister;
import crafttweaker.mc1120.CraftTweaker;
import net.minecraft.command.CommandGameRule;
import net.minecraft.world.GameRules;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
Expand Down Expand Up @@ -41,6 +43,36 @@ public boolean hasRule(String name) {
return rules.hasRule(name);
}

@ZenMethod
public void setInt(String name, int value) {
if (rules.areSameType(name, GameRules.ValueType.NUMERICAL_VALUE)) {
rules.setOrCreateGameRule(name, Integer.toString(value));
CommandGameRule.notifyGameRuleChange(rules, name, CraftTweaker.server);
} else {
throw new IllegalArgumentException("GameRule " + name + " is not numerical value.");
}
}

@ZenMethod
public void setBoolean(String name, boolean value) {
if (rules.areSameType(name, GameRules.ValueType.BOOLEAN_VALUE)) {
rules.setOrCreateGameRule(name, Boolean.toString(value));
CommandGameRule.notifyGameRuleChange(rules, name, CraftTweaker.server);
} else {
throw new IllegalArgumentException("GameRule " + name + " is not boolean value.");
}
}

@ZenMethod
public void setString(String name, String value) {
if (rules.areSameType(name, GameRules.ValueType.ANY_VALUE)) {
rules.setOrCreateGameRule(name, value);
CommandGameRule.notifyGameRuleChange(rules, name, CraftTweaker.server);
} else {
throw new IllegalArgumentException("GameRule " + name + " is not string value.");
}
}

@ZenMethod
public void addGameRule(String key, String value, String type) {
if(hasRule(key)) return;
Expand Down

0 comments on commit 5e87800

Please sign in to comment.