Search in sources :

Example 16 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project RecurrentComplex by Ivorforce.

the class CommandSanity method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args, "silent", "short");
    boolean sane = true;
    if (StructureRegistry.INSTANCE.ids().isEmpty()) {
        commandSender.sendMessage(new TextComponentString("No registered structures!"));
        sane = false;
    }
    if (!Files.isReadable(ResourceDirectory.getCustomDirectory().toPath())) {
        commandSender.sendMessage(new TextComponentString("Can't read files from custom directory"));
        sane = false;
    }
    for (ModContainer mod : Loader.instance().getModList()) {
        String domain = mod.getModId();
        Path path = null;
        try {
            path = RCFiles.pathFromResourceLocation(new ResourceLocation(domain.toLowerCase(), ""));
        } catch (RCFiles.ResourceLocationLoadException e) {
            RecurrentComplex.logger.error(e);
            commandSender.sendMessage(new TextComponentString("Error reading files from mod " + mod.getModId() + ": "));
            commandSender.sendMessage(new TextComponentString(RCCommands.reason(e)));
            sane = false;
        }
        if (path != null && !Files.isReadable(path)) {
            commandSender.sendMessage(new TextComponentString("Can't read files from mod: " + mod.getModId()));
            sane = false;
        }
    }
    if (!Files.isReadable(ResourceDirectory.getServerDirectory().toPath())) {
        commandSender.sendMessage(new TextComponentString("Can't read files from server directory"));
        sane = false;
    }
    if (!parameters.has("short")) {
        sane &= addStructureLog(commandSender, (s, structure) -> !structure.generationTypes(GenerationType.class).isEmpty(), "Missing generation type");
        sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> StructureSelector.generationWeightInBiome(gen.biomeWeights, b) > 0), "Natural generation type won't accept any known biomes");
        sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> StructureSelector.generationWeightInDimension(gen.dimensionWeights, d.provider) > 0), "Natural generation type won't accept any known dimensions");
        sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> gen.getActiveGenerationWeight() > 0, "Natural generation type has no weight");
        sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> gen.biomeExpression.test(b)), "Vanilla structure generation type won't accept any known biomes");
        sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> gen.getActiveWeight() > 0, "Vanilla structure generation type has no weight");
        sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> gen.minBaseLimit > 0 || gen.maxBaseLimit > 0 || gen.maxScaledLimit > 0 || gen.minScaledLimit > 0, "Vanilla structure is always limited to zero instances");
        sane &= addGenerationLog(commandSender, VanillaDecorationGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> StructureSelector.generationWeightInBiome(gen.biomeWeights, b) > 0), "Vanilla structure generation type won't accept any known biomes");
        sane &= addGenerationLog(commandSender, VanillaDecorationGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> StructureSelector.generationWeightInDimension(gen.dimensionWeights, d.provider) > 0), "Natural generation type won't accept any dimensions");
        sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> gen.getWeight() > 0, "Maze generation type has no weight");
        sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.getMazeID().trim().isEmpty(), "Maze generation type has maze id");
        sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.mazeComponent.rooms.isEmpty(), "Maze generation type has no rooms");
        sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.mazeComponent.exitPaths.isEmpty() || !gen.mazeComponent.defaultConnector.id.equals(ConnectorStrategy.DEFAULT_WALL), "Maze generation type has no walkable exits");
        sane &= addGenerationLog(commandSender, ListGeneration.class, (structure, gen) -> !gen.listID.trim().isEmpty(), "List generation has no list id");
        sane &= addGenerationLog(commandSender, ListGeneration.class, (structure, gen) -> gen.getWeight() > 0, "List generation has no weight");
        sane &= addGenerationLog(commandSender, SaplingGeneration.class, (structure, gen) -> gen.getActiveWeight() > 0, "Sapling generation has no weight");
        sane &= addGenerationLog(commandSender, StaticGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> gen.dimensionExpression.test(d.provider)), "Static generation won't accept any known dimensions");
    }
    if (sane && !parameters.has("silent"))
        commandSender.sendMessage(new TextComponentString("No specific problems found!"));
}
Also used : Path(java.nio.file.Path) CommandSearchStructure(ivorius.reccomplex.commands.structure.CommandSearchStructure) ivorius.reccomplex.world.gen.feature.structure.generic.generation(ivorius.reccomplex.world.gen.feature.structure.generic.generation) Loader(net.minecraftforge.fml.common.Loader) PriorityQueue(java.util.PriorityQueue) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) ServerTranslations(ivorius.reccomplex.utils.ServerTranslations) RCConfig(ivorius.reccomplex.RCConfig) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) BiPredicate(java.util.function.BiPredicate) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) RCFiles(ivorius.reccomplex.files.RCFiles) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) StructureSelector(ivorius.reccomplex.world.gen.feature.selector.StructureSelector) Path(java.nio.file.Path) DimensionManager(net.minecraftforge.common.DimensionManager) Nullable(javax.annotation.Nullable) Files(java.nio.file.Files) World(net.minecraft.world.World) IRegistry(net.minecraft.util.registry.IRegistry) CommandBase(net.minecraft.command.CommandBase) BlockPos(net.minecraft.util.math.BlockPos) ConnectorStrategy(ivorius.reccomplex.world.gen.feature.structure.generic.maze.ConnectorStrategy) TextComponentString(net.minecraft.util.text.TextComponentString) List(java.util.List) Stream(java.util.stream.Stream) ICommandSender(net.minecraft.command.ICommandSender) ResourceLocation(net.minecraft.util.ResourceLocation) ModContainer(net.minecraftforge.fml.common.ModContainer) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Biome(net.minecraft.world.biome.Biome) ModContainer(net.minecraftforge.fml.common.ModContainer) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) ResourceLocation(net.minecraft.util.ResourceLocation) RCFiles(ivorius.reccomplex.files.RCFiles)

Example 17 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project RecurrentComplex by Ivorforce.

the class FMLUtils method addPrefix.

public static String addPrefix(String name) {
    // From FML
    int index = name.lastIndexOf(':');
    String oldPrefix = index == -1 ? "" : name.substring(0, index);
    String prefix;
    ModContainer mc = Loader.instance().activeModContainer();
    if (mc != null)
        prefix = mc.getModId();
    else
        // no mod container, assume minecraft
        prefix = "minecraft";
    if (!oldPrefix.equals(prefix))
        name = prefix + ":" + name;
    return name;
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer)

Example 18 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project MinecraftForge by MinecraftForge.

the class ForgeChunkManager method setForcedChunkLoadingCallback.

/**
     * Set a chunkloading callback for the supplied mod object
     *
     * @param mod  The mod instance registering the callback
     * @param callback The code to call back when forced chunks are loaded
     */
public static void setForcedChunkLoadingCallback(Object mod, LoadingCallback callback) {
    ModContainer container = getContainer(mod);
    if (container == null) {
        FMLLog.warning("Unable to register a callback for an unknown mod %s (%s : %x)", mod, mod.getClass().getName(), System.identityHashCode(mod));
        return;
    }
    callbacks.put(container.getModId(), callback);
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer)

Example 19 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project MinecraftForge by MinecraftForge.

the class ForgeChunkManager method ticketCountAvailableFor.

/**
     * Discover the available tickets for the mod in the world
     *
     * @param mod The mod that will own the tickets
     * @param world The world
     * @return The count of tickets left for the mod in the supplied world
     */
public static int ticketCountAvailableFor(Object mod, World world) {
    ModContainer container = getContainer(mod);
    if (container != null) {
        String modId = container.getModId();
        int allowedCount = getMaxTicketLengthFor(modId);
        return allowedCount - tickets.get(world).get(modId).size();
    } else {
        return 0;
    }
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer)

Example 20 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project MinecraftForge by MinecraftForge.

the class ForgeChunkManager method requestPlayerTicket.

@Nullable
public static Ticket requestPlayerTicket(Object mod, String player, World world, Type type) {
    ModContainer mc = getContainer(mod);
    if (mc == null) {
        FMLLog.log(Level.ERROR, "Failed to locate the container for mod instance %s (%s : %x)", mod, mod.getClass().getName(), System.identityHashCode(mod));
        return null;
    }
    if (playerTickets.get(player).size() > playerTicketLength) {
        FMLLog.warning("Unable to assign further chunkloading tickets to player %s (on behalf of mod %s)", player, mc.getModId());
        return null;
    }
    Ticket ticket = new Ticket(mc.getModId(), type, world, player);
    playerTickets.put(player, ticket);
    tickets.get(world).put(ForgeVersion.MOD_ID, ticket);
    return ticket;
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) Nullable(javax.annotation.Nullable)

Aggregations

ModContainer (net.minecraftforge.fml.common.ModContainer)34 ResourceLocation (net.minecraft.util.ResourceLocation)4 DummyModContainer (net.minecraftforge.fml.common.DummyModContainer)4 LoaderException (net.minecraftforge.fml.common.LoaderException)4 Nullable (javax.annotation.Nullable)3 ForgeModContainer (net.minecraftforge.common.ForgeModContainer)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 InputStream (java.io.InputStream)2 List (java.util.List)2 Map (java.util.Map)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 SetMultimap (com.google.common.collect.SetMultimap)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 RCConfig (ivorius.reccomplex.RCConfig)1