Skip to content

Instantly share code, notes, and snippets.

@AlexIIL
Last active June 18, 2016 19:06
Show Gist options
  • Save AlexIIL/1e10b087053f3448a45b782e01cc6b60 to your computer and use it in GitHub Desktop.
Save AlexIIL/1e10b087053f3448a45b782e01cc6b60 to your computer and use it in GitHub Desktop.
Oredictionary additions list -- for minecraft 1.8.9
/* Copyright (c) 2016 AlexIIL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
package alexiil.mc.mod.oredict;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.event.FMLConstructionEvent;
import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent;
@Mod(modid = "oredictlistener")
public class OreDictionaryListener {
public static final Logger LOG = LogManager.getLogger("OreListener");
private static final List<Regstration> registrations = new ArrayList<>();
private static void printLine(boolean sysout, String message) {
if (sysout) {
System.out.print(message + "\n");
} else {
LOG.info(message);
}
}
@Mod.EventHandler
public void preInit(FMLConstructionEvent evt) {
MinecraftForge.EVENT_BUS.register(EventListener.INSTANCE);
}
@Mod.EventHandler
public void complete(FMLLoadCompleteEvent complete) {
registrations.sort(Comparator.naturalOrder());
String modid = "?minecraft?";
boolean[] bools = { true, false };
for (boolean sysout : bools) {
printLine(sysout, "");
for (Regstration reg : registrations) {
if (!modid.equals(reg.modid)) {
modid = reg.modid;
printLine(sysout, "");
printLine(sysout, "Registered by " + modid);
printLine(sysout, "");
printLine(sysout, "| Oredictionary Name | ItemStack Name |");
printLine(sysout, "| ------------------ | -------------- |");
}
reg.printInfo(sysout);
}
printLine(sysout, "");
}
}
public enum EventListener {
INSTANCE;
@SubscribeEvent
public void oreDictRegister(OreRegisterEvent event) {
String modid;
ModContainer current = Loader.instance().activeModContainer();
if (current == null) {
modid = "unknown/minecraft";
} else {
modid = current.getModId();
}
registrations.add(new Regstration(modid, event.Name, event.Ore));
}
}
public static class Regstration implements Comparable<Regstration> {
public final String modid;
public final String name;
public final ItemStack ore;
public Regstration(String modid, String name, ItemStack ore) {
this.modid = modid;
this.name = name;
this.ore = ore;
}
@Override
public String toString() {
return "OreDicRegistration[" + modid + " reg: " + name + " for " + ore + "]";
}
public void printInfo(boolean sysout) {
printLine(sysout, "| ````" + name + "```` | " + ore.getDisplayName() + " |");
}
@Override
public int compareTo(Regstration o) {
int diff = modid.compareTo(o.modid);
if (diff != 0) return diff;
return name.compareTo(o.name);
}
}
}
@AlexIIL
Copy link
Author

AlexIIL commented Jun 18, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment