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 think I'm doing something stupid, but I just can't see past the code blindness.

Here's the provider:

package com.nosrick.masterofmagic.capabilities;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.INBTSerializable;

public class PlayerResearchProvider implements ICapabilityProvider, INBTSerializable
{
@CapabilityInject(IBaseResearchCapability.class)
public static Capability<IBaseResearchCapability> s_Research = null;

protected IBaseResearchCapability m_Research = null;

public PlayerResearchProvider()
{
	m_Research = new PlayerResearchCapability();
}

public PlayerResearchProvider(PlayerResearchCapability capability)
{
	m_Research = capability;
}

public static IBaseResearchCapability Get(EntityPlayer player) 
{
	if(player.hasCapability(s_Research, null))
	{
		return player.getCapability(s_Research, null);
	}
	return null;
}

@Override
public NBTBase serializeNBT() 
{
	return m_Research.saveNBTData();
}

@Override
public void deserializeNBT(NBTBase nbt) 
{
	m_Research.loadNBTData((NBTTagCompound) nbt);
}

@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) 
{
	return s_Research != null && capability == s_Research;
}

@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) 
{
	if (s_Research != null && capability == s_Research) 
		return (T)m_Research;

	return null;
}

}

 

What am I doing wrong? Why is s_Research always null?

Have you called

CapabilityManager#register

for your capability interface?

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

Have you called

CapabilityManager#register

for your capability interface?

Hah! Was just about to post saying "Always check you've registered your capabilities" but you got there before me.

 

So yeah, always check you've registered your capabilities.

 

Thanks Choonster!

Guest
This topic is now closed to further replies.

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.