Skip to content

Commit

Permalink
Port fabric-game-rule-api-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Jun 15, 2024
1 parent 29f188c commit 583274e
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import net.fabricmc.fabric.api.gamerule.v1.rule.EnumRule;
import net.fabricmc.fabric.impl.gamerule.EnumRuleType;
import net.fabricmc.fabric.impl.gamerule.rule.BoundedIntRule;
import net.fabricmc.fabric.mixin.gamerule.GameRulesBooleanRuleAccessor;

/**
* A utility class containing factory methods to create game rule types.
Expand Down Expand Up @@ -69,7 +68,7 @@ public static GameRules.Type<GameRules.BooleanValue> createBooleanRule(boolean d
* @return a boolean rule type
*/
public static GameRules.Type<GameRules.BooleanValue> createBooleanRule(boolean defaultValue, BiConsumer<MinecraftServer, GameRules.BooleanValue> changedCallback) {
return GameRulesBooleanRuleAccessor.invokeCreate(defaultValue, changedCallback);
return GameRules.BooleanValue.create(defaultValue, changedCallback);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private GameRuleRegistry() {
* @throws IllegalStateException if a rule of the same name already exists
*/
public static <T extends GameRules.Value<T>> GameRules.Key<T> register(String name, GameRules.Category category, GameRules.Type<T> type) {
return GameRulesAccessor.callRegister(name, category, type);
return GameRules.register(name, category, type);
}

/**
Expand All @@ -58,7 +58,7 @@ public static <T extends GameRules.Value<T>> GameRules.Key<T> register(String na
* @throws IllegalStateException if a rule of the same name already exists
*/
public static <T extends GameRules.Value<T>> GameRules.Key<T> register(String name, CustomGameRuleCategory category, GameRules.Type<T> type) {
final GameRules.Key<T> key = GameRulesAccessor.callRegister(name, GameRules.Category.MISC, type);
final GameRules.Key<T> key = GameRules.register(name, GameRules.Category.MISC, type);
((RuleKeyExtensions) (Object) key).fabric_setCustomCategory(category);
return key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package net.fabricmc.fabric.mixin.gamerule;

import com.mojang.brigadier.context.CommandContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.commands.GameRuleCommand;
import net.minecraft.world.level.GameRules;
Expand All @@ -25,12 +24,7 @@

@Mixin(GameRuleCommand.class)
public interface GameRuleCommandAccessor {
@Invoker
static <T extends GameRules.Value<T>> int invokeExecuteSet(CommandContext<CommandSourceStack> commandContext, GameRules.Key<T> ruleKey) {
throw new AssertionError("This shouldn't happen!");
}

@Invoker
@Invoker("queryRule")
static <T extends GameRules.Value<T>> int invokeExecuteQuery(CommandSourceStack serverCommandSource, GameRules.Key<T> ruleKey) {
throw new AssertionError("This shouldn't happen!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@

@Mixin(GameRules.class)
public interface GameRulesAccessor {
@Invoker("register")
static <T extends GameRules.Value<T>> GameRules.Key<T> callRegister(String name, GameRules.Category category, GameRules.Type<T> type) {
throw new AssertionError("This shouldn't happen!");
}

@Accessor("GAME_RULE_TYPES")
static Map<GameRules.Key<?>, GameRules.Type<?>> getRuleTypes() {
throw new AssertionError("This shouldn't happen!");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"package": "net.fabricmc.fabric.mixin.gamerule",
"compatibilityLevel": "JAVA_17",
"mixins": [
"GameRulesBooleanRuleAccessor",

"GameRuleCommandAccessor",
"GameRuleCommandVisitorMixin",
"GameRulesAccessor",
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ include("fabric-command-api-v2")
//include 'fabric-dimensions-v1'
//include 'fabric-entity-events-v1'
//include 'fabric-events-interaction-v0'
//include("fabric-game-rule-api-v1")
include("fabric-game-rule-api-v1")
include("fabric-gametest-api-v1")
//include 'fabric-item-api-v1'
//include 'fabric-item-group-api-v1'
Expand Down

0 comments on commit 583274e

Please sign in to comment.