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!"));
}
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;
}
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);
}
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;
}
}
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;
}
Aggregations