Hello i am a new moddeur and i am doing a mod based on Hxh so i would like to attach to the players a quantity of Nen (mana) and a max amount of Nen. So I used the system of capabilities I followed many tutorials to do it but every time I have a error null point exeption so I come here to ask your help, thank you in advance and sorry for my bad English .
here my crash report :
crash-2019-03-30_00.16.20-client.txt
my classes :
public class PlayerNen {
private double Nen = 0.0;
public PlayerNen() {
}
public double getNen() {
return Nen;
}
public void setNen(double nen) {
Nen = nen;
}
public void copyNen(PlayerNen Pnen) {
Nen = Pnen.Nen;
}
public void saveNBTData (NBTTagCompound compound) {compound.setDouble("nen",Nen);}
public void loadNBTData (NBTTagCompound compound){Nen=compound.getDouble("nen");}
}
public class PlayerProp {
@CapabilityInject(PlayerNen.class)
public static Capability<PlayerNen> Player_Nen;
public static PlayerNen getPlayerNen(EntityPlayer player){ return player.getCapability(Player_Nen,null);}
public class PropDispatcher implements ICapabilitySerializable<NBTTagCompound> {
private PlayerNen playerNen = new PlayerNen();
@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
return capability == PlayerProp.Player_Nen;
}
@Nullable
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
if (capability == PlayerProp.Player_Nen){
return (T) playerNen;
}
return null;
}
@Override
public NBTTagCompound serializeNBT() {
NBTTagCompound nbt = new NBTTagCompound();
playerNen.saveNBTData(nbt);
return nbt;
}
@Override
public void deserializeNBT(NBTTagCompound nbt) {
playerNen.loadNBTData(nbt);
}
}
public class PlayerPropEvent {
public static PlayerPropEvent instance = new PlayerPropEvent();
@SubscribeEvent
public void onEntityContstructing (AttachCapabilitiesEvent<net.minecraft.entity.Entity> event){
Entity test = (net.minecraft.entity.Entity) event.getObject();
if (test instanceof EntityPlayer){
if (!event.getObject().hasCapability(PlayerProp.Player_Nen,null)){
event.addCapability(new ResourceLocation(MainHunterXHunter.modId,"nen"),new PropDispatcher());
}
}
}
@SubscribeEvent
public void onPlayerCloned(PlayerEvent.Clone event){
if(event.isWasDeath()){
if(event.getOriginal().hasCapability(PlayerProp.Player_Nen,null)){
PlayerNen old = event.getOriginal().getCapability(PlayerProp.Player_Nen,null);
PlayerNen newstore = PlayerProp.getPlayerNen(event.getEntityPlayer());
newstore.copyNen(old);
}
}
}
}
And here the class to setup a Nen bar, this works fine whithout capabilities
public class NenOverlay extends Gui {
private final ResourceLocation bar = new ResourceLocation(MainHunterXHunter.modId, "textures/barre.png");
@SubscribeEvent
public void renderOverlay (RenderGameOverlayEvent event ){
Minecraft mc = Minecraft.getMinecraft();
EntityPlayer player = mc.player ;
PlayerNen nen = PlayerProp.getPlayerNen(player);
final int externalBarH = 20, externalBarL = 108, internalBarH = 14, internalBarL = 102;
float tmp=0;
int lenthBar =0;
if (event.getType()==RenderGameOverlayEvent.ElementType.TEXT){
mc.renderEngine.bindTexture(bar);
tmp = internalBarL/250;
lenthBar = (int)(tmp*nen.getNen());
drawTexturedModalRect(5,5,0,0,externalBarL,externalBarH);
drawTexturedModalRect(8,8,3,20,lenthBar,internalBarH);
}
}
}
Thank you for reading this.