diff --git a/assets/opencomputers/textures/items/placeholder.png b/assets/opencomputers/textures/items/placeholder.png new file mode 100644 index 000000000..3f34c8daf Binary files /dev/null and b/assets/opencomputers/textures/items/placeholder.png differ diff --git a/li/cil/oc/api/example/component/ExampleItem.java b/li/cil/oc/api/example/component/ExampleItem.java new file mode 100644 index 000000000..93212f651 --- /dev/null +++ b/li/cil/oc/api/example/component/ExampleItem.java @@ -0,0 +1,16 @@ +package li.cil.oc.api.example.component; + + +import net.minecraft.item.Item; + +public class ExampleItem extends Item{ + //for convenience reasons + public static ExampleItem thisItem; + public ExampleItem(int id){ + super(id); + thisItem = this; + setTextureName("opencomputers:placeholder"); + } + //add all the important methods for your item like images and logic (not lua stuff) + +} diff --git a/li/cil/oc/api/example/component/ExampleItemDriver.java b/li/cil/oc/api/example/component/ExampleItemDriver.java new file mode 100644 index 000000000..43bd7be43 --- /dev/null +++ b/li/cil/oc/api/example/component/ExampleItemDriver.java @@ -0,0 +1,59 @@ +package li.cil.oc.api.example.component; + +import cpw.mods.fml.common.event.FMLInitializationEvent; +import li.cil.oc.api.Driver; +import li.cil.oc.api.driver.Item; +import li.cil.oc.api.driver.Slot; +import li.cil.oc.api.network.ManagedEnvironment; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; + + +public class ExampleItemDriver implements Item { + + + @Override + public boolean worksWith(ItemStack item) { + return item.getItem().equals(ExampleItem.thisItem); + } + + @Override + public ManagedEnvironment createEnvironment(ItemStack stack, TileEntity container) { + //return the environment for the item + return new ExampleItemEnvironment(); + } + + @Override + public Slot slot(ItemStack stack) { + return Slot.Upgrade;//This is the part where you define in which slot the item fits. + } + + /** + * This is a example implementation of dataTag. If you prefere a different way to retrieve the compund + * feel free to use it + * @param stack the item to get the child tag from. + * @return + */ + @Override + public NBTTagCompound dataTag(ItemStack stack) { + if (!stack.hasTagCompound()) { + stack.setTagCompound(new NBTTagCompound("tag")); + } + NBTTagCompound nbt = stack.getTagCompound(); + if (!nbt.hasKey("yournamespace" + "data")) { + nbt.setCompoundTag("yournamespace" + "data", new NBTTagCompound()); + } + return nbt.getCompoundTag("yournamespace" + "data"); + } + + //This is supposed to be your proxy where you init your stuff + public class Proxy{ + + + public void init(FMLInitializationEvent e) { + //in the init methode add this to register the driver + Driver.add(new ExampleItemDriver()); + } + } +} diff --git a/li/cil/oc/api/example/component/ExampleItemEnvironment.java b/li/cil/oc/api/example/component/ExampleItemEnvironment.java new file mode 100644 index 000000000..80e7e9e95 --- /dev/null +++ b/li/cil/oc/api/example/component/ExampleItemEnvironment.java @@ -0,0 +1,86 @@ +package li.cil.oc.api.example.component; + + +import li.cil.oc.api.Network; +import li.cil.oc.api.network.*; +import net.minecraft.nbt.NBTTagCompound; + +public class ExampleItemEnvironment implements ManagedEnvironment { + /** + * ********************************************Default methods*************************** + */ + private Node node; + + public ExampleItemEnvironment() { + //for a more detailed description read the documentation of each parameter + node = Network + //Visibility defines who can reach the component + .newNode(this, Visibility.Network) + //if the component shall be reached in the component network, + // Visibility defines from where the component can be accessed with lua ( + .withComponent("ExampleItem", Visibility.Neighbors) + //if you want to have power + .withConnector() + //finally creates the node required! + .create(); + } + + + @Override + public Node node() { + return node; + } + + @Override + public void onConnect(Node node) { + //do stuff + } + + @Override + public void onDisconnect(Node node) { + //do stuff + + } + @Override + public void onMessage(Message message) { + //do stuff + } + + @Override + public boolean canUpdate() { + //used to indicate if the component shall be updated every tick only called once! + return false; + } + + @Override + public void update() { + //do stuff on update (only called if canUpdate returns true) + } + + @Override + public void load(NBTTagCompound nbt) { + //example if you want different implementation do so! + if (node != null) + node.load(nbt.getCompoundTag("node")); + } + + @Override + public void save(NBTTagCompound nbt) { + //example if you want different implementation do so! + if (node != null) { + NBTTagCompound compound = new NBTTagCompound(); + node.save(compound); + nbt.setCompoundTag("node", compound); + } + + } + /** + * ********************************************Custom methods*************************** + */ + //This is a example method that can be called from lua. The lua name and java name don't need + //to be the same + @LuaCallback("test") + public Object[] testName(Context computer, Arguments arguments) { + return new Object[]{"Hello", " Lua"}; + } +}