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

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