mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-24 05:54:27 +00:00
52 lines
1.1 KiB
Java
52 lines
1.1 KiB
Java
package crazypants.util;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemBlock;
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
public class Util {
|
|
|
|
public static Block getBlock(int blockId) {
|
|
if (blockId <= 0) {
|
|
return null;
|
|
}
|
|
if (blockId > Block.blocksList.length) {
|
|
return null;
|
|
}
|
|
return Block.blocksList[blockId];
|
|
}
|
|
|
|
public static Item getItem(int itemId) {
|
|
if (itemId <= 0) {
|
|
return null;
|
|
}
|
|
if (itemId > Item.itemsList.length) {
|
|
return null;
|
|
}
|
|
return Item.itemsList[itemId];
|
|
}
|
|
|
|
public static Block getBlockFromItemId(int itemId) {
|
|
Item item = getItem(itemId);
|
|
if (item instanceof ItemBlock) {
|
|
return getBlock(((ItemBlock) item).getBlockID());
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static ItemStack consumeItem(ItemStack stack) {
|
|
if (stack.stackSize == 1) {
|
|
if (stack.getItem().hasContainerItem()) {
|
|
return stack.getItem().getContainerItemStack(stack);
|
|
} else {
|
|
return null;
|
|
}
|
|
} else {
|
|
stack.splitStack(1);
|
|
return stack;
|
|
}
|
|
}
|
|
|
|
}
|