Files
Binnie/src/main/java/binnie/core/Mods.java
T

90 lines
2.3 KiB
Java
Raw Normal View History

2016-10-20 02:56:31 +02:00
package binnie.core;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.versioning.DefaultArtifactVersion;
import cpw.mods.fml.common.versioning.Restriction;
import net.minecraft.block.Block;
2016-10-20 02:56:31 +02:00
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
2016-10-20 02:56:31 +02:00
public class Mods {
2017-06-03 08:50:03 +03:00
public static Mod forestry;
public static Mod ic2;
public static Mod botania;
private static boolean warn;
2016-10-20 02:56:31 +02:00
private static Item findItem(String modId, String name) {
Item stack = GameRegistry.findItem(modId, name);
2017-06-03 08:50:03 +03:00
if (stack == null && Mods.warn && modId.equals("FORESTRY")) {
2016-10-20 02:56:31 +02:00
throw new RuntimeException("Item not found: " + modId + ":" + name);
}
return stack;
}
private static ItemStack findItemStack(String modId, String name, int stackSize) {
ItemStack stack = GameRegistry.findItemStack(modId, name, stackSize);
2017-06-03 08:50:03 +03:00
if (stack == null && Mods.warn && modId.equals("FORESTRY")) {
2016-10-20 02:56:31 +02:00
throw new RuntimeException("Stack not found: " + modId + ":" + name);
}
return stack;
}
private static Block findBlock(String modId, String name) {
Block stack = GameRegistry.findBlock(modId, name);
2017-06-03 08:50:03 +03:00
if (stack == null && Mods.warn && modId.equals("FORESTRY")) {
2016-10-20 02:56:31 +02:00
throw new RuntimeException("Block not found: " + modId + ":" + name);
}
return stack;
}
static {
2017-06-03 08:50:03 +03:00
Mods.forestry = new Mod("FORESTRY") {
2016-10-20 02:56:31 +02:00
@Override
public boolean dev() {
2017-06-03 08:50:03 +03:00
String forVersion = Loader.instance().getIndexedModList().get("FORESTRY").getVersion();
Restriction rest = new Restriction(new DefaultArtifactVersion("3.6"), true, null, false);
2016-10-20 02:56:31 +02:00
return rest.containsVersion(new DefaultArtifactVersion(forVersion));
}
};
2017-06-03 08:50:03 +03:00
Mods.ic2 = new Mod("IC2");
Mods.botania = new Mod("BOTANIA");
Mods.warn = true;
2016-10-20 02:56:31 +02:00
}
public static class Mod {
2016-10-20 02:56:31 +02:00
private String id;
private Mod(String id) {
2016-10-20 02:56:31 +02:00
this.id = id;
}
public Item item(String name) {
2017-04-27 01:09:09 +03:00
return findItem(id, name);
2016-10-20 02:56:31 +02:00
}
public Block block(String name) {
2017-04-27 01:09:09 +03:00
return findBlock(id, name);
2016-10-20 02:56:31 +02:00
}
public ItemStack stack(String name, int stackSize) {
2017-04-27 01:09:09 +03:00
return findItemStack(id, name, stackSize);
2016-10-20 02:56:31 +02:00
}
public ItemStack stack(String name) {
2017-04-27 01:09:09 +03:00
return stack(name, 1);
2016-10-20 02:56:31 +02:00
}
public ItemStack stack(String string, int i, int j) {
2017-04-27 01:09:09 +03:00
return new ItemStack(item(string), i, j);
2016-10-20 02:56:31 +02:00
}
public boolean active() {
2017-04-27 01:09:09 +03:00
return Loader.isModLoaded(id);
2016-10-20 02:56:31 +02:00
}
public boolean dev() {
return false;
}
}
}