mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-19 05:30:23 -07:00
Make GameRule a FeatureDependant (#12429)
This commit is contained in:
parent
91bfb6fb7e
commit
121a7bf4eb
@ -575,6 +575,7 @@ public net.minecraft.world.level.BaseSpawner spawnCount
|
||||
public net.minecraft.world.level.BaseSpawner spawnDelay
|
||||
public net.minecraft.world.level.BaseSpawner spawnPotentials
|
||||
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 onChanged(Lnet/minecraft/server/MinecraftServer;)V
|
||||
public net.minecraft.world.level.Level blockEntityTickers
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.bukkit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.papermc.paper.world.flag.FeatureDependant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -15,7 +16,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
*
|
||||
* @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<>();
|
||||
// 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()]);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public @NotNull String translationKey() {
|
||||
return "gamerule." + this.name;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
+
|
||||
public static final int DEFAULT_RANDOM_TICK_SPEED = 3;
|
||||
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 @@
|
||||
"sendCommandFeedback", GameRules.Category.CHAT, GameRules.BooleanValue.create(true)
|
||||
);
|
||||
@ -225,8 +225,12 @@
|
||||
final String id;
|
||||
private final GameRules.Category category;
|
||||
|
||||
@@ -575,7 +_,7 @@
|
||||
public static class Type<T extends GameRules.Value<T>> {
|
||||
@@ -572,10 +_,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
- 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;
|
||||
private final Function<GameRules.Type<T>, T> constructor;
|
||||
- final BiConsumer<MinecraftServer, T> callback;
|
||||
|
@ -4,15 +4,16 @@ import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import net.minecraft.world.flag.FeatureElement;
|
||||
import net.minecraft.world.flag.FeatureFlagSet;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import net.minecraft.world.level.GameRules;
|
||||
import org.bukkit.FeatureFlag;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntityTypes;
|
||||
import org.bukkit.craftbukkit.potion.CraftPotionType;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
@ -50,8 +51,19 @@ public class PaperFeatureFlagProviderImpl implements FeatureFlagProvider {
|
||||
return CraftEntityType.bukkitToMinecraft(entityType);
|
||||
} else if (dependant instanceof final PotionType potionType) {
|
||||
return CraftPotionType.bukkitToMinecraft(potionType);
|
||||
} else if (dependant instanceof final GameRule<?> gameRule) {
|
||||
return getGameRuleType(gameRule.getName());
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user