Make GameRule a FeatureDependant (#12429)

This commit is contained in:
DerEchtePilz 2025-04-14 13:21:14 +02:00 committed by GitHub
parent 91bfb6fb7e
commit 121a7bf4eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 8 deletions

View File

@ -575,6 +575,7 @@ public net.minecraft.world.level.BaseSpawner spawnCount
public net.minecraft.world.level.BaseSpawner spawnDelay public net.minecraft.world.level.BaseSpawner spawnDelay
public net.minecraft.world.level.BaseSpawner spawnPotentials public net.minecraft.world.level.BaseSpawner spawnPotentials
public net.minecraft.world.level.BaseSpawner spawnRange public net.minecraft.world.level.BaseSpawner spawnRange
public net.minecraft.world.level.GameRules GAME_RULE_TYPES
public net.minecraft.world.level.GameRules$Value deserialize(Ljava/lang/String;)V public net.minecraft.world.level.GameRules$Value deserialize(Ljava/lang/String;)V
public net.minecraft.world.level.GameRules$Value onChanged(Lnet/minecraft/server/MinecraftServer;)V public net.minecraft.world.level.GameRules$Value onChanged(Lnet/minecraft/server/MinecraftServer;)V
public net.minecraft.world.level.Level blockEntityTickers public net.minecraft.world.level.Level blockEntityTickers

View File

@ -1,6 +1,7 @@
package org.bukkit; package org.bukkit;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.papermc.paper.world.flag.FeatureDependant;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -15,7 +16,7 @@ import org.jetbrains.annotations.Nullable;
* *
* @param <T> type of rule (Boolean or Integer) * @param <T> type of rule (Boolean or Integer)
*/ */
public final class GameRule<T> implements net.kyori.adventure.translation.Translatable { // Paper - Adventure translations public final class GameRule<T> implements net.kyori.adventure.translation.Translatable, FeatureDependant {
private static Map<String, GameRule<?>> gameRules = new HashMap<>(); private static Map<String, GameRule<?>> gameRules = new HashMap<>();
// Boolean rules // Boolean rules
@ -377,10 +378,9 @@ public final class GameRule<T> implements net.kyori.adventure.translation.Transl
return gameRules.values().toArray(new GameRule<?>[gameRules.size()]); return gameRules.values().toArray(new GameRule<?>[gameRules.size()]);
} }
// Paper start
@Override @Override
public @NotNull String translationKey() { public @NotNull String translationKey() {
return "gamerule." + this.name; return "gamerule." + this.name;
} }
// Paper end
} }

View File

@ -14,7 +14,7 @@
+ +
public static final int DEFAULT_RANDOM_TICK_SPEED = 3; public static final int DEFAULT_RANDOM_TICK_SPEED = 3;
static final Logger LOGGER = LogUtils.getLogger(); static final Logger LOGGER = LogUtils.getLogger();
private static final Map<GameRules.Key<?>, GameRules.Type<?>> GAME_RULE_TYPES = Maps.newTreeMap(Comparator.comparing(entry -> entry.id)); public static final Map<GameRules.Key<?>, GameRules.Type<?>> GAME_RULE_TYPES = Maps.newTreeMap(Comparator.comparing(entry -> entry.id));
@@ -86,10 +_,10 @@ @@ -86,10 +_,10 @@
"sendCommandFeedback", GameRules.Category.CHAT, GameRules.BooleanValue.create(true) "sendCommandFeedback", GameRules.Category.CHAT, GameRules.BooleanValue.create(true)
); );
@ -225,8 +225,12 @@
final String id; final String id;
private final GameRules.Category category; private final GameRules.Category category;
@@ -575,7 +_,7 @@ @@ -572,10 +_,10 @@
public static class Type<T extends GameRules.Value<T>> { }
}
- public static class Type<T extends GameRules.Value<T>> {
+ public static class Type<T extends GameRules.Value<T>> implements net.minecraft.world.flag.FeatureElement { // Paper - FeatureDependant for GameRule
final Supplier<ArgumentType<?>> argument; final Supplier<ArgumentType<?>> argument;
private final Function<GameRules.Type<T>, T> constructor; private final Function<GameRules.Type<T>, T> constructor;
- final BiConsumer<MinecraftServer, T> callback; - final BiConsumer<MinecraftServer, T> callback;

View File

@ -4,15 +4,16 @@ import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableBiMap;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import net.minecraft.world.flag.FeatureElement; import net.minecraft.world.flag.FeatureElement;
import net.minecraft.world.flag.FeatureFlagSet; import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.flag.FeatureFlags; import net.minecraft.world.flag.FeatureFlags;
import net.minecraft.world.level.GameRules;
import org.bukkit.FeatureFlag; import org.bukkit.FeatureFlag;
import org.bukkit.GameRule;
import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.craftbukkit.entity.CraftEntityType;
import org.bukkit.craftbukkit.entity.CraftEntityTypes;
import org.bukkit.craftbukkit.potion.CraftPotionType; import org.bukkit.craftbukkit.potion.CraftPotionType;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.potion.PotionType; import org.bukkit.potion.PotionType;
@ -50,8 +51,19 @@ public class PaperFeatureFlagProviderImpl implements FeatureFlagProvider {
return CraftEntityType.bukkitToMinecraft(entityType); return CraftEntityType.bukkitToMinecraft(entityType);
} else if (dependant instanceof final PotionType potionType) { } else if (dependant instanceof final PotionType potionType) {
return CraftPotionType.bukkitToMinecraft(potionType); return CraftPotionType.bukkitToMinecraft(potionType);
} else if (dependant instanceof final GameRule<?> gameRule) {
return getGameRuleType(gameRule.getName());
} else { } else {
throw new IllegalArgumentException(dependant + " is not a valid feature dependant"); throw new IllegalArgumentException(dependant + " is not a valid feature dependant");
} }
} }
private static GameRules.Type<?> getGameRuleType(final String name) {
for (final Map.Entry<GameRules.Key<?>, GameRules.Type<?>> gameRules : GameRules.GAME_RULE_TYPES.entrySet()) {
if (gameRules.getKey().getId().equals(name)) {
return gameRules.getValue();
}
}
return null;
}
} }