package com.hbm.tileentity; import java.util.ArrayList; import com.hbm.util.CompatExternal; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public interface IPersistentNBT { public static final String NBT_PERSISTENT_KEY = "persistent"; public void writeNBT(NBTTagCompound nbt); public void readNBT(NBTTagCompound nbt); public default ArrayList getDrops(Block b) { ArrayList list = new ArrayList(); ItemStack stack = new ItemStack(b); NBTTagCompound data = new NBTTagCompound(); writeNBT(data); if(!data.hasNoTags()) stack.stackTagCompound = data; list.add(stack); return list; } public static ArrayList getDrops(World world, int x, int y, int z, Block b) { TileEntity tile = CompatExternal.getCoreFromPos(world, x, y, z); if(tile instanceof IPersistentNBT) { return ((IPersistentNBT) tile).getDrops(b); } return new ArrayList(); } public static void restoreData(World world, int x, int y, int z, ItemStack stack) { try { if(!stack.hasTagCompound()) return; TileEntity tile = world.getTileEntity(x, y, z); if(!(tile instanceof IPersistentNBT)) return; IPersistentNBT persistent = (IPersistentNBT) tile; persistent.readNBT(stack.stackTagCompound); } catch(Exception ex) { ex.printStackTrace(); } } }