Created
January 19, 2020 21:27
-
-
Save ToMe25/9b5242a7df98755c9c2b55f4797f46be to your computer and use it in GitHub Desktop.
A tiny minecraft mod to get the ore rarity values for botania based on https://gist.github.com/Vazkii/9493322.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modLoader="javafml" #mandatory | |
loaderVersion="[28,)" #mandatory (28 is current forge version) | |
[[mods]] #mandatory | |
modId="worldprofiler" #mandatory | |
version="${file.jarVersion}" #mandatory | |
displayName="World Profiler" #mandatory | |
[[dependencies.worldprofiler]] #optional | |
modId="forge" #mandatory | |
mandatory=true #mandatory | |
versionRange="[28,)" #mandatory | |
ordering="NONE" | |
side="BOTH" | |
[[dependencies.worldprofiler]] | |
modId="minecraft" | |
mandatory=true | |
versionRange="[1.14.4]" | |
ordering="NONE" | |
side="BOTH" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tome.worldprofiler; | |
import java.io.File; | |
import java.io.FileOutputStream; | |
import java.util.Collection; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
import com.mojang.brigadier.CommandDispatcher; | |
import com.mojang.brigadier.context.CommandContext; | |
import net.minecraft.block.Block; | |
import net.minecraft.block.BlockState; | |
import net.minecraft.client.Minecraft; | |
import net.minecraft.command.CommandSource; | |
import net.minecraft.command.Commands; | |
import net.minecraft.tags.BlockTags; | |
import net.minecraft.util.ResourceLocation; | |
import net.minecraft.util.math.BlockPos; | |
import net.minecraft.util.text.StringTextComponent; | |
import net.minecraftforge.common.MinecraftForge; | |
import net.minecraftforge.eventbus.api.SubscribeEvent; | |
import net.minecraftforge.fml.common.Mod; | |
import net.minecraftforge.fml.event.server.FMLServerStartingEvent; | |
@Mod(WorldProfiler.MODID) | |
public class WorldProfiler { | |
private static final Logger LOGGER = LogManager.getLogger(); | |
public static final String MODID = "worldprofiler"; | |
public WorldProfiler() { | |
MinecraftForge.EVENT_BUS.register(this); | |
} | |
@SubscribeEvent | |
public void onServerStarting(FMLServerStartingEvent event) { | |
ProfileCommand.register(event.getCommandDispatcher()); | |
} | |
public static class ProfileCommand { | |
public static void register(CommandDispatcher<CommandSource> dispatcher) { | |
dispatcher.register(Commands.literal("profile_ores") | |
.requires(source -> source.hasPermissionLevel(4) && Minecraft.getInstance().isSingleplayer()) | |
.executes(context -> profile(context))); | |
} | |
public static int profile(CommandContext<CommandSource> context) { | |
try { | |
LOGGER.info("Lag incoming!"); | |
Map<String, Integer> ores = new HashMap<String, Integer>(); | |
int chunks = 256; | |
int range = (int) Math.sqrt(chunks); | |
for (int x = 0; x < (16 * range); x++) | |
for (int y = 0; y < 128; y++) | |
for (int z = 0; z < (16 * range); z++) { | |
BlockState state = context.getSource().getWorld().getBlockState(new BlockPos(x, y, z)); | |
Block block = state.getBlock(); | |
if (block != null) { | |
Collection<ResourceLocation> tags = BlockTags.getCollection().getOwningTags(block); | |
for (ResourceLocation tag : tags) { | |
String oredict = tag.toString(); | |
if (oredict.toString().toLowerCase().startsWith("forge:ores/")) { | |
int count = ores.containsKey(oredict) ? ores.get(oredict) : 0; | |
ores.put(oredict, count + 1); | |
} | |
} | |
} | |
} | |
String str = "Chunks checked: " + chunks + "\n\n"; | |
for (String s : ores.keySet()) | |
str = str + s + " = " + ores.get(s) + " (avg " + ((double) ores.get(s) / (double) chunks) | |
+ " per chunk)\n"; | |
File output = new File("worldprofiler.txt"); | |
FileOutputStream fiout = new FileOutputStream(output); | |
fiout.write(str.getBytes()); | |
fiout.close(); | |
context.getSource().sendFeedback( | |
new StringTextComponent(String.format("[%s] §aResults saved to %s.", MODID, output.getAbsolutePath())), | |
true); | |
} catch (Exception e) { | |
LOGGER.catching(e); | |
} | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment