Created
March 11, 2014 19:33
-
-
Save Vazkii/9493322 to your computer and use it in GitHub Desktop.
This file contains 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 vazkii.oredetector; | |
import java.awt.Toolkit; | |
import java.awt.datatransfer.Clipboard; | |
import java.awt.datatransfer.StringSelection; | |
import java.util.HashMap; | |
import java.util.Map; | |
import net.minecraft.block.Block; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.world.World; | |
import net.minecraft.world.biome.BiomeGenBase; | |
import net.minecraftforge.oredict.OreDictionary; | |
import cpw.mods.fml.common.Mod; | |
import cpw.mods.fml.common.Mod.EventHandler; | |
import cpw.mods.fml.common.event.FMLPostInitializationEvent; | |
import cpw.mods.fml.common.event.FMLPreInitializationEvent; | |
import cpw.mods.fml.common.registry.GameRegistry; | |
@Mod(modid = "oreDetector") | |
public class OreDetector { | |
@EventHandler | |
public void preInit(FMLPreInitializationEvent event) { | |
new ItemOreDetector(); | |
OreDictionary.registerOre("oreCoal", Block.oreCoal); | |
} | |
@EventHandler | |
public void postInit(FMLPostInitializationEvent event) { | |
for(BiomeGenBase biome : BiomeGenBase.biomeList) | |
if(biome != BiomeGenBase.extremeHills) | |
GameRegistry.removeBiome(biome); | |
} | |
class ItemOreDetector extends Item { | |
public ItemOreDetector() { | |
super(15555); | |
setUnlocalizedName("oredetector"); | |
} | |
@Override | |
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { | |
Map<String, Integer> ores = new HashMap(); | |
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++) { | |
int id = par2World.getBlockId(x, y, z); | |
int meta = par2World.getBlockMetadata(x, y, z); | |
Block block = Block.blocksList[id]; | |
if(block != null) { | |
String oredict = OreDictionary.getOreName(OreDictionary.getOreID(new ItemStack(block, 1, meta))); | |
if(oredict.toLowerCase().contains("ore")) { | |
int count = ores.containsKey(oredict) ? ores.get(oredict) : 0; | |
ores.put(oredict, count + 1); | |
} | |
} | |
} | |
String selectionStr = "Chunks checked: " + chunks + "\n\n"; | |
for(String s : ores.keySet()) | |
selectionStr = selectionStr + s + " = " + ores.get(s) + " (avg " + ((double) ores.get(s) / (double) chunks) + " per chunk)\n"; | |
StringSelection selection = new StringSelection(selectionStr); | |
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); | |
clipboard.setContents(selection, selection); | |
par3EntityPlayer.addChatMessage("Results copied to clipboard."); | |
return par1ItemStack; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment