TEXHIK Posted August 17, 2018 Posted August 17, 2018 (edited) I have an ItemStack, that has only one capability - SocketCapability. When i'm trying to check/get it, i'm getting false/null. But if I call methods right on it's provider, all is fine public void preInit() { CapabilityManager.INSTANCE.register(ISocketCapability.class, new SocketCapabilityStorage(), new SocketCapabilityFactory()); GameRegistry.registerTileEntity(TileInlayTable.class, ModBlocks.INLAY_TABLE.getRegistryName());//TODO universal tileEntity registing } public class SocketCapabilityFactory implements Callable<SocketCapability> { @Override public SocketCapability call() throws Exception { return new SocketCapability(); } } public class SocketCapabilityProvider implements ICapabilitySerializable<NBTBase> { @CapabilityInject(ISocketCapability.class) public static final Capability<ISocketCapability> SOCKET_CAPABILITY = null; private ISocketCapability instance = SOCKET_CAPABILITY.getDefaultInstance(); @Override public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) { return capability == SOCKET_CAPABILITY; } @Nullable @Override public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) { return capability == SOCKET_CAPABILITY ? SOCKET_CAPABILITY.cast(instance) : null; } @Override public NBTBase serializeNBT() { return SOCKET_CAPABILITY.getStorage().writeNBT(SOCKET_CAPABILITY, instance, null); } @Override public void deserializeNBT(NBTBase nbt) { SOCKET_CAPABILITY.getStorage().readNBT(SOCKET_CAPABILITY, instance, null, nbt); } } public class SocketCapabilityStorage implements Capability.IStorage<ISocketCapability> { @Nullable @Override public NBTBase writeNBT(Capability<ISocketCapability> capability, ISocketCapability instance, EnumFacing side) { NBTTagCompound compound = new NBTTagCompound(); NBTTagList list = new NBTTagList(); if (instance.getSocketsCount() > 0) { for (Socket socket : instance.getSockets()) { list.appendTag(socket.serializeNBT()); } } compound.setTag("sockets", list); return compound; } @Override public void readNBT(Capability<ISocketCapability> capability, ISocketCapability instance, EnumFacing side, NBTBase nbt) { NBTTagList list = ((NBTTagCompound) nbt).getTagList("sockets", 10); if (list.isEmpty()) { instance.setSockets(new Socket[0]); } else { Socket[] sockets = new Socket[list.tagCount()]; for (int i = 0; i < list.tagCount(); i++) { sockets[i] = new Socket(list.getCompoundTagAt(i)); } instance.setSockets(sockets); } } Edited August 17, 2018 by TEXHIK Quote
TEXHIK Posted August 17, 2018 Author Posted August 17, 2018 25 minutes ago, diesieben07 said: Show your code. updated topic with my copabilities code. Full souce https://bitbucket.org/RedTEXHIK/runewords/src/master/src/main/java/ru/htd/runewords/ Quote
TEXHIK Posted August 18, 2018 Author Posted August 18, 2018 (edited) On 8/17/2018 at 2:08 PM, diesieben07 said: This is broken. You need to use a ResourceLocation that represents your capability provider, not the stack's item's name. Fixed it, but it didn't fix the bug. And bug only when I shift-click, when taking item in regular way, all is ok. Figured out, that the problem is that on successfull getting item by shift-click, itemStack passed into onTake is empty. What is the right way to change item, before taking it? Edited August 18, 2018 by TEXHIK Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.