Jump to content

Recommended Posts

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?

Posted

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.

Posted

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.

Announcements



×
×
  • Create New...

Important Information

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