Added ad_astra integration

This commit is contained in:
Sollace 2023-09-10 23:28:53 +01:00
parent 6d7345c389
commit af76a4fef6
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
10 changed files with 155 additions and 3 deletions

View file

@ -18,8 +18,11 @@ public class Config extends com.minelittlepony.common.util.settings.Config {
public final Setting<Set<String>> wantItNeedItEntityExcludelist = value("server", "wantItNeedItEntityExcludelist", (Set<String>)new HashSet<>(Set.of("minecraft:creeper")))
.addComment("A list of entity types that are immune to the want it need it spell's effects");
public final Setting<Set<String>> dimensionsWithoutAtmosphere = value("server", "dimensionsWithoutAtmosphere", (Set<String>)new HashSet<String>())
.addComment("A list of dimensions ids that do not have an atmosphere, and thus shouldn't allow pegasi to fly.");
public final Setting<Boolean> enableCheats = value("server", "enableCheats", false)
.addComment("Allows use of the /race, /disguise, and /gravity commands");
.addComment("Allows use of the /tribe, /unicopia disguise, and /unicopia gravity commands");
public final Setting<Race> preferredRace = value("client", "preferredRace", Race.EARTH)
.addComment("The default preferred race")

View file

@ -32,6 +32,9 @@ public class UnicopiaMixinPlugin implements IMixinConfigPlugin {
if (mixinClassName.indexOf("seasons") != -1) {
return FabricLoader.getInstance().isModLoaded("seasons");
}
if (mixinClassName.indexOf("ad_astra") != -1) {
return FabricLoader.getInstance().isModLoaded("ad_astra");
}
}
return true;
}

View file

@ -0,0 +1,94 @@
package com.minelittlepony.unicopia.command;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import com.minelittlepony.common.util.settings.Config;
import com.minelittlepony.common.util.settings.Setting;
import com.minelittlepony.unicopia.Unicopia;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.CommandSource;
import net.minecraft.command.argument.*;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
public class ConfigCommand {
public static LiteralArgumentBuilder<ServerCommandSource> create(CommandRegistryAccess registries) {
return CommandManager.literal("config").requires(s -> s.hasPermissionLevel(2))
.then(createSet("dimensionswithoutatmosphere", createSuggestion(registries, RegistryKeys.DIMENSION_TYPE)))
.then(createSet("wantitneeditentityexcludelist", createSuggestion(registries, RegistryKeys.ENTITY_TYPE)));
}
private static LiteralArgumentBuilder<ServerCommandSource> createSet(String configName, SuggestionProvider<ServerCommandSource> suggestions) {
return CommandManager.literal(configName)
.then(CommandManager.literal("clear").executes(source -> {
source.getSource().sendFeedback(() -> Text.translatable("command.unicopia.config.clear", configName), true);
return changeProperty(configName, values -> new HashSet<>());
}))
.then(CommandManager.literal("add").then(
CommandManager.argument("id", IdentifierArgumentType.identifier()).suggests(suggestions).executes(source -> ConfigCommand.<Set<String>>changeProperty(configName, values -> {
String value = IdentifierArgumentType.getIdentifier(source, "id").toString();
source.getSource().sendFeedback(() -> Text.translatable("command.unicopia.config.add", value, configName), true);
values.add(value);
return values;
})))
)
.then(CommandManager.literal("remove").then(
CommandManager.argument("id", IdentifierArgumentType.identifier()).suggests((context, builder) -> {
return CommandSource.suggestIdentifiers(Unicopia.getConfig().getCategory("server").<Set<String>>get(configName).get().stream()
.map(Identifier::tryParse)
.filter(Objects::nonNull)
.toList(), builder);
}).executes(source -> ConfigCommand.<Set<String>>changeProperty(configName, values -> {
String value = IdentifierArgumentType.getIdentifier(source, "id").toString();
source.getSource().sendFeedback(() -> Text.translatable("command.unicopia.config.remove", value, configName), true);
values.remove(value);
return values;
})))
)
.then(CommandManager.literal("list").executes(source -> ConfigCommand.<Set<String>>getProperty(configName, values -> {
ServerPlayerEntity player = source.getSource().getPlayerOrThrow();
player.sendMessage(Text.translatable("command.unicopia.config.list", configName, values.size()), false);
values.forEach(line -> player.sendMessage(Text.literal(line)));
}))
);
}
private static <T> SuggestionProvider<ServerCommandSource> createSuggestion(CommandRegistryAccess registries, RegistryKey<Registry<T>> registryKey) {
RegistryWrapper<T> wrapper = registries.createWrapper(registryKey);
return (context, builder) -> CommandSource.suggestIdentifiers(wrapper.streamKeys().map(RegistryKey::getValue), builder);
}
private static <T> int changeProperty(String configName, Function<T, T> changer) {
Config config = Unicopia.getConfig();
Setting<T> setting = config.getCategory("server").get(configName);
setting.set(changer.apply(setting.get()));
config.save();
return 0;
}
private static <T> int getProperty(String configName, UnsafeConsumer<T> reader) throws CommandSyntaxException {
Config config = Unicopia.getConfig();
Setting<T> setting = config.getCategory("server").get(configName);
reader.accept(setting.get());
return 0;
}
interface UnsafeConsumer<T> {
void accept(T t) throws CommandSyntaxException;
}
}

View file

@ -11,6 +11,7 @@ class UnicopiaCommand {
public static LiteralArgumentBuilder<ServerCommandSource> create(CommandRegistryAccess registries, RegistrationEnvironment environment) {
return CommandManager.literal("unicopia")
.then(EmoteCommand.create())
.then(ConfigCommand.create(registries))
.then(SpeciesCommand.create(environment))
.then(RacelistCommand.create())
.then(WorldTribeCommand.create())

View file

@ -0,0 +1,18 @@
package com.minelittlepony.unicopia.compat.ad_astra;
import com.minelittlepony.unicopia.mixin.ad_astra.MixinOxygenUtils;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.LivingEntity;
import net.minecraft.world.World;
public interface OxygenUtils {
boolean MOD_LOADED = FabricLoader.getInstance().isModLoaded("ad_astra");
static boolean entityHasOxygen(World world, LivingEntity entity) {
if (MOD_LOADED) {
return MixinOxygenUtils.entityHasOxygen(world, entity);
}
return false;
}
}

View file

@ -9,6 +9,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.advancement.UCriteria;
import com.minelittlepony.unicopia.client.minelittlepony.MineLPDelegate;
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
import com.minelittlepony.unicopia.compat.ad_astra.OxygenUtils;
import com.minelittlepony.unicopia.entity.*;
import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
import com.minelittlepony.unicopia.entity.duck.LivingEntityDuck;
@ -182,7 +183,9 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
public FlightType getFlightType() {
DimensionType dimension = entity.getWorld().getDimension();
if (RegistryUtils.isIn(entity.getWorld(), dimension, RegistryKeys.DIMENSION_TYPE, UTags.HAS_NO_ATMOSPHERE)) {
if ((RegistryUtils.isIn(entity.getWorld(), dimension, RegistryKeys.DIMENSION_TYPE, UTags.HAS_NO_ATMOSPHERE)
|| Unicopia.getConfig().dimensionsWithoutAtmosphere.get().contains(RegistryUtils.getId(entity.getWorld(), dimension, RegistryKeys.DIMENSION_TYPE).toString()))
&& !OxygenUtils.entityHasOxygen(entity.getWorld(), entity)) {
return FlightType.NONE;
}

View file

@ -0,0 +1,20 @@
package com.minelittlepony.unicopia.mixin.ad_astra;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.gen.Invoker;
import net.minecraft.entity.LivingEntity;
import net.minecraft.world.World;
@Pseudo
@Mixin(
targets = { "earth.terrarium.ad_astra.common.util.OxygenUtils" },
remap = false
)
public interface MixinOxygenUtils {
@Invoker("entityHasOxygen")
static boolean entityHasOxygen(World world, LivingEntity entity) {
return true;
}
}

View file

@ -53,4 +53,8 @@ public interface RegistryUtils {
static <T> boolean isIn(World world, T obj, RegistryKey<? extends Registry<T>> registry, TagKey<T> tag) {
return world.getRegistryManager().get(registry).getEntry(obj).isIn(tag);
}
static <T> Identifier getId(World world, T obj, RegistryKey<? extends Registry<T>> registry) {
return world.getRegistryManager().get(registry).getId(obj);
}
}

View file

@ -681,6 +681,11 @@
"unicopia.options.world": "World Settings",
"unicopia.options.world.default_race": "Default Race: %s",
"unicopia.options.lan": "Multiplayer (LAN) Settings",
"command.unicopia.config.add": "[Config] Added %s to property %s",
"command.unicopia.config.remove": "[Config] Removed %s from property %s",
"command.unicopia.config.list": "[Config] Property (%s) contains (%s) entries: ",
"command.unicopia.config.clear": "[Config] Cleared all values from property %s",
"unicopia.race.unset": "Unset",
"unicopia.race.unset.alt": "Unset",

View file

@ -49,7 +49,8 @@
"trinkets.MixinTrinketItem",
"trinkets.MixinTrinketInventory",
"trinkets.MixinScreenHandler",
"seasons.MixinFertilizableUtil"
"seasons.MixinFertilizableUtil",
"ad_astra.MixinOxygenUtils"
],
"client": [
"client.MixinAnimalModel",