generated from CleanroomMC/TemplateDevEnv
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add Default GameRules * add command to apply gamerules * add some debug logs for the default gamerules * restore boolean to default value * fix use_examples_folder server using `run/examples` * fastutil the map
- Loading branch information
1 parent
c9eb5d9
commit 2de715d
Showing
6 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/com/cleanroommc/groovyscript/compat/vanilla/GameRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.cleanroommc.groovyscript.compat.vanilla; | ||
|
||
import com.cleanroommc.groovyscript.api.GroovyBlacklist; | ||
import com.cleanroommc.groovyscript.api.GroovyLog; | ||
import com.cleanroommc.groovyscript.api.IScriptReloadable; | ||
import com.cleanroommc.groovyscript.api.documentation.annotations.MethodDescription; | ||
import com.cleanroommc.groovyscript.registry.NamedRegistry; | ||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; | ||
import net.minecraft.world.GameRules; | ||
|
||
import java.util.Map; | ||
|
||
public class GameRule extends NamedRegistry implements IScriptReloadable { | ||
|
||
private static final String LOG_MESSAGE = "Could not find an already existing rule with the name {}. This may be intentional! If it is, you can disable this via `gameRule.setWarnNewGameRule(false)`"; | ||
private final Map<String, String> defaultGameRules = new Object2ObjectOpenHashMap<>(); | ||
private boolean warnNewGameRule; | ||
|
||
@GroovyBlacklist | ||
public void setDefaultGameRules(GameRules gameRules) { | ||
defaultGameRules.forEach((k, v) -> { | ||
if (warnNewGameRule && !gameRules.hasRule(k)) GroovyLog.get().warn(LOG_MESSAGE, k); | ||
GroovyLog.get().debug("Setting the GameRule '{}' to the value '{}'", k, v); | ||
gameRules.setOrCreateGameRule(k, v); | ||
}); | ||
GroovyLog.get().debug("Set or created {} GameRules", defaultGameRules.size()); | ||
} | ||
|
||
@MethodDescription | ||
public void add(String gameRule, String value) { | ||
defaultGameRules.put(gameRule, value); | ||
} | ||
|
||
@MethodDescription | ||
public void add(Map<String, String> gameRules) { | ||
defaultGameRules.putAll(gameRules); | ||
} | ||
|
||
@MethodDescription | ||
public void setWarnNewGameRule(boolean value) { | ||
warnNewGameRule = value; | ||
} | ||
|
||
@Override | ||
@GroovyBlacklist | ||
public void onReload() { | ||
defaultGameRules.clear(); | ||
warnNewGameRule = false; | ||
} | ||
|
||
@Override | ||
@GroovyBlacklist | ||
public void afterScriptLoad() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters