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
4 changed files with 25 additions and 8 deletions

View File

@ -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;

View File

@ -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;
}
}