package li.cil.oc.api.prefab; import li.cil.oc.api.network.EnvironmentHost; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; /** * If you wish to create item components such as the network card or hard drives * you will need an item driver. * <p/> * This prefab allows creating a driver that works for a specified list of item * stacks (to support different items with the same id but different damage * values). It also takes care of creating and getting the tag compound on an * item stack to save data to or load data from. * <p/> * You still have to specify your component's slot type and provide the * implementation for creating its environment, if any. * * @see li.cil.oc.api.network.ManagedEnvironment */ @SuppressWarnings("UnusedDeclaration") public abstract class DriverItem implements li.cil.oc.api.driver.Item { protected final ItemStack[] items; protected DriverItem(final ItemStack... items) { this.items = items.clone(); } @Override public boolean worksWith(final ItemStack stack) { if (stack != null) { for (ItemStack item : items) { if (item != null && item.isItemEqual(stack)) { return true; } } } return false; } @Override public int tier(final ItemStack stack) { return 0; } @Override public NBTTagCompound dataTag(final ItemStack stack) { if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } final NBTTagCompound nbt = stack.getTagCompound(); // This is the suggested key under which to store item component data. // You are free to change this as you please. if (!nbt.hasKey("oc:data")) { nbt.setTag("oc:data", new NBTTagCompound()); } return nbt.getCompoundTag("oc:data"); } // Convenience methods provided for HostAware drivers. protected boolean isAdapter(Class<? extends EnvironmentHost> host) { return li.cil.oc.api.internal.Adapter.class.isAssignableFrom(host); } protected boolean isComputer(Class<? extends EnvironmentHost> host) { return li.cil.oc.api.internal.Case.class.isAssignableFrom(host); } protected boolean isRobot(Class<? extends EnvironmentHost> host) { return li.cil.oc.api.internal.Robot.class.isAssignableFrom(host); } protected boolean isRotatable(Class<? extends EnvironmentHost> host) { return li.cil.oc.api.internal.Rotatable.class.isAssignableFrom(host); } protected boolean isServer(Class<? extends EnvironmentHost> host) { return li.cil.oc.api.internal.Server.class.isAssignableFrom(host); } protected boolean isTablet(Class<? extends EnvironmentHost> host) { return li.cil.oc.api.internal.Tablet.class.isAssignableFrom(host); } }