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

75 lines
2.1 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 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 {
2022-07-03 12:17:51 +08:00
public static Mod forestry;
public static Mod ic2;
public static Mod botania;
2016-10-20 02:56:31 +02:00
2022-07-03 12:17:51 +08:00
private static Item findItem(String modId, String name) {
Item stack = GameRegistry.findItem(modId, name);
if (stack == null && modId.equals("Forestry")) {
throw new RuntimeException("Item not found: " + modId + ":" + name);
}
return stack;
}
2016-10-20 02:56:31 +02:00
2022-07-03 12:17:51 +08:00
private static ItemStack findItemStack(String modId, String name, int stackSize) {
ItemStack stack = GameRegistry.findItemStack(modId, name, stackSize);
if (stack == null && modId.equals("Forestry")) {
throw new RuntimeException("Stack not found: " + modId + ":" + name);
}
return stack;
}
2016-10-20 02:56:31 +02:00
2022-07-03 12:17:51 +08:00
private static Block findBlock(String modId, String name) {
Block stack = GameRegistry.findBlock(modId, name);
if (stack == null && modId.equals("Forestry")) {
throw new RuntimeException("Block not found: " + modId + ":" + name);
}
return stack;
}
2016-10-20 02:56:31 +02:00
2022-07-03 12:17:51 +08:00
static {
Mods.forestry = new Mod("Forestry");
Mods.ic2 = new Mod("IC2");
Mods.botania = new Mod("Botania");
}
2016-10-20 02:56:31 +02:00
2022-07-03 12:17:51 +08:00
public static class Mod {
private String id;
2016-10-20 02:56:31 +02:00
2022-07-03 12:17:51 +08:00
private Mod(String id) {
this.id = id;
}
2016-10-20 02:56:31 +02:00
2022-07-03 12:17:51 +08:00
public Item item(String name) {
return findItem(id, name);
}
2016-10-20 02:56:31 +02:00
2022-07-03 12:17:51 +08:00
public Block block(String name) {
return findBlock(id, name);
}
2016-10-20 02:56:31 +02:00
2022-07-03 12:17:51 +08:00
public ItemStack stack(String name, int stackSize) {
return findItemStack(id, name, stackSize);
}
2016-10-20 02:56:31 +02:00
2022-07-03 12:17:51 +08:00
public ItemStack stack(String name) {
return stack(name, 1);
}
2016-10-20 02:56:31 +02:00
2022-07-03 12:17:51 +08:00
public ItemStack stack(String string, int i, int j) {
return new ItemStack(item(string), i, j);
}
2016-10-20 02:56:31 +02:00
2022-07-03 12:17:51 +08:00
public boolean active() {
return Loader.isModLoaded(id);
}
}
2016-10-20 02:56:31 +02:00
}