Jump to content

Recommended Posts

Posted (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

image.png.3473ec3ff073a01780bdd2ea16af4d0f.png

 

	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 by TEXHIK
Posted (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 by TEXHIK

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I was trying to find a mod that added something specific, and was unable to find it with what limited memory I had of seeing it. I don't know why there isn't an option to include words in overviews of mods. I could see it being in the sort tab near filters on the app in my opinion. It might help someone trying to find something specific, only based off something from the overview tab, but idk
    • Please read the FAQ and post logs as described there.   Also, do not just add a post onto someone else's thread with your issue, create a new one please.
    • I am creating a server with mods but when i try tostart it it say in the logs:   [29Jan2025 20:36:50.715] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/fmlcore/1.20.1-47.3.27/fmlcore-1.20.1-47.3.27.jar is missing mods.toml file 159[29Jan2025 20:36:50.717] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/javafmllanguage/1.20.1-47.3.27/javafmllanguage-1.20.1-47.3.27.jar 160[29Jan2025 20:36:50.717] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/javafmllanguage/1.20.1-47.3.27/javafmllanguage-1.20.1-47.3.27.jar is missing mods.toml file 161[29Jan2025 20:36:50.718] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/lowcodelanguage/1.20.1-47.3.27/lowcodelanguage-1.20.1-47.3.27.jar 162[29Jan2025 20:36:50.718] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/lowcodelanguage/1.20.1-47.3.27/lowcodelanguage-1.20.1-47.3.27.jar is missing mods.toml file 163[29Jan2025 20:36:50.719] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/mclanguage/1.20.1-47.3.27/mclanguage-1.20.1-47.3.27.jar 164[29Jan2025 20:36:50.719] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/mclanguage/1.20.1-47.3.27/mclanguage-1.20.1-47.3.27.jar is missing mods.toml file
    • How do you configure the entity reach of a custom weapon? Asking for 1.21 Minecraft parchment
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.