Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author
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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.