Jump to content

1.14.4 NullPointerException


LK1905

Recommended Posts

Hello, I'm working on a capability that allows the player to train rpg-like skills, but I have come across a problem that I can't see the cause of.

 

Relevant part of the crash report:

java.lang.NullPointerException: null
	at net.minecraftforge.common.capabilities.CapabilityManager.register(CapabilityManager.java:79) ~[?:?]
	at com.lk1905.gielinorcraft.capability.skill.CapabilitySkills.register(CapabilitySkills.java:26) ~[?:?]
	at com.lk1905.gielinorcraft.Gielinorcraft.<init>(Gielinorcraft.java:21) ~[?:?]

 

The error is on the CapabilityManager.INSTANCE.register line in the CapabilitySkills class.

 

CapabilitySkills.java

package com.lk1905.gielinorcraft.capability.skill;

import com.lk1905.gielinorcraft.api.capability.ISkillContainer;
import com.lk1905.gielinorcraft.api.utils.CapabilityUtils;
import com.lk1905.gielinorcraft.capability.CommonCapabilityProvider;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber
public class CapabilitySkills {

	@CapabilityInject(ISkillContainer.class)
	private static Capability<ISkillContainer> skillContainerCapability;
	
	public static void register() {
		
		CapabilityManager.INSTANCE.register(ISkillContainer.class, new SkillStorage(), () -> new SkillContainer());//<---THIS LINE
	}
	
	@SubscribeEvent
	public static void attachCapability(AttachCapabilitiesEvent<Entity> e) {
		
		if(!(e.getObject() instanceof PlayerEntity)) {
			return;
		}
		
		SkillContainer newContainer = new SkillContainer();
		
		e.addCapability(newContainer.getCapabilityID(), 
						new CommonCapabilityProvider<>(skillContainerCapability, null, newContainer));
	}
	
	@SubscribeEvent
	public static void onPlayerClone(final PlayerEvent.Clone e) {
		
		ISkillContainer oldCapability = (ISkillContainer) CapabilityUtils.getCapability(e.getOriginal(), null);
		ISkillContainer newCapability = (ISkillContainer) CapabilityUtils.getCapability(e.getPlayer(), null);
		
		newCapability.setAllSkills(oldCapability.getAllSkills());
	}
	
	public static ISkillContainer getSkillContainer(ICapabilityProvider provider) {
		
		return (ISkillContainer) CapabilityUtils.getCapability(provider, skillContainerCapability);
	}
	
	public static Capability<ISkillContainer> getSkillCapability(){
		
		return skillContainerCapability;
	}
}

 

My main  class:

 

Gielinorcraft.java

package com.lk1905.gielinorcraft;

import org.apache.logging.log4j.Logger;

import com.lk1905.gielinorcraft.capability.skill.CapabilitySkills;
import com.lk1905.gielinorcraft.capability.skill.SkillContainer;
import com.lk1905.gielinorcraft.skills.AttackSkill;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;

@Mod(Gielinorcraft.MODID)
public class Gielinorcraft {

	public static Logger logger;
	
	public static final String MODID = "gielinorcraft";
	
	public Gielinorcraft() {
		
		CapabilitySkills.register();
		
		SkillContainer.registerNewSkill(AttackSkill.class);
		
		MinecraftForge.EVENT_BUS.register(AttackSkill.class);
	}
}

 

SkillStorage.java

package com.lk1905.gielinorcraft.capability.skill;

import java.util.Map;

import com.lk1905.gielinorcraft.api.capability.ISkillContainer;
import com.lk1905.gielinorcraft.api.skills.ISkill;

import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;

public class SkillStorage implements Capability.IStorage<ISkillContainer>{

	public SkillStorage() {
		
	}
	
	@Override
	public CompoundNBT writeNBT(Capability<ISkillContainer> capability, ISkillContainer instance, Direction side) {
		
		CompoundNBT skillData = new CompoundNBT();
		
		for(Map.Entry<String, ISkill> entry : instance.getAllSkills().entrySet()) {
			
			skillData.put(entry.getKey(), entry.getValue().serializeNBT());
		}
		
		return skillData;
	}
	
	@Override
	public void readNBT(Capability<ISkillContainer> capability, ISkillContainer instance, Direction side, INBT nbt) {
		
		CompoundNBT skillData = (CompoundNBT) nbt;
		
		for(String key : skillData.keySet()) {
			
			instance.getSkill(key).deserializeNBT(skillData.getCompound(key));
		}
	}

}

 

SkillContainer.java

package com.lk1905.gielinorcraft.capability.skill;

import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.lk1905.gielinorcraft.Gielinorcraft;
import com.lk1905.gielinorcraft.api.capability.ISkillContainer;
import com.lk1905.gielinorcraft.api.skills.ISkill;

import io.netty.buffer.ByteBuf;
import net.minecraft.util.ResourceLocation;

public class SkillContainer implements ISkillContainer{

	private final static Set<Class<? extends ISkill>> skillClasses = new HashSet<>();
	private final Map<String, ISkill> skills;
	
	public SkillContainer() {
		
		skills = new HashMap<>();
		
		for(Class<? extends ISkill> skillClass : skillClasses) {
			
			ISkill skill;
			
			try {
				skill = skillClass.newInstance();
				
			}catch(InstantiationException | IllegalAccessException e) {
				
				Gielinorcraft.logger.error("Failed to initialise skill instance from class descriptor: " + skillClass.getName());
				continue;
			}
			
			skills.put(skill.getName(), skill);
		}
	}
	
	@Override
	public ISkill getSkill(String name) {
		
		return this.skills.get(name);
	}
	
	@Override
	public void setAllSkills(Map<String, ISkill> newSkills) {
		
		this.skills.putAll(newSkills);
	}
	
	@Override
	public void serializePacket(ByteBuf buf) {
		
		buf.writeInt(skills.size());
		
		for(ISkill skill : skills.values()) {
			
			buf.writeInt(skill.getName().length());
			buf.writeCharSequence(skill.getName(), Charset.defaultCharset());
			skill.serializePacket(buf);
		}
	}
	
	@Override
	public void deserializePacket(ByteBuf buf) {
		
		int numberOfSkills = buf.readInt();
		
		for(int i = 0; i < numberOfSkills; i++) {
			
			int lengthOfSkillName = buf.readInt();
			String skillName = buf.readCharSequence(lengthOfSkillName, Charset.defaultCharset()).toString();
			getSkill(skillName).deserializePacket(buf);
		}
	}
	
	@Override
	public ResourceLocation getCapabilityID() {
		
		return new ResourceLocation(Gielinorcraft.MODID, "skills");
	}
	
	@Override
	public Map<String, ISkill> getAllSkills(){
		return skills;
	}
	
	@Override
	public Map<String, Double> getAllSkillXP(){
		
		Map<String, Double> skillXP = new HashMap<>();
		
		for(Map.Entry<String, ISkill> entry : skills.entrySet())	{
			
			skillXP.put(entry.getKey(), entry.getValue().getXP());
		}
		
		return skillXP;
	}
	
	public static void registerNewSkill(Class<? extends ISkill> skillClass) {
		
		skillClasses.add(skillClass);
	}
}

 

I think thats all the relevant classes, If you need to see others let me know.

 

I'm guessing the problem is with either the SkillContainer or SkillStorage class, but I Can't see what.

 

Thanks

Link to comment
Share on other sites

My Github:

 

https://github.com/LK1905/GielinorCraft

 

Log:

[16Feb2020 10:24:40.474] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmluserdevclient, --fml.mcpVersion, 20190829.143755, --fml.mcVersion, 1.14.4, --fml.forgeGroup, net.minecraftforge, --fml.forgeVersion, 28.1.0, --version, MOD_DEV, --assetIndex, 1.14, --assetsDir, C:\Users\Liam\.gradle\caches\forge_gradle\assets, --username, Dev, --accessToken, ????????, --userProperties, {}]
[16Feb2020 10:24:40.505] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 3.2.0+60+b86c1d4 starting: java version 1.8.0_161 by Oracle Corporation
[16Feb2020 10:24:44.057] [main/INFO] [net.minecraftforge.fml.loading.FixSSL/CORE]: Added Lets Encrypt root certificates as additional trust
[16Feb2020 10:24:51.727] [main/INFO] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Launching target 'fmluserdevclient' with arguments [--version, MOD_DEV, --gameDir, ., --assetsDir, C:\Users\Liam\.gradle\caches\forge_gradle\assets, --assetIndex, 1.14, --username, Dev, --accessToken, ????????, --userProperties, {}]
[16Feb2020 10:25:15.154] [Client thread/INFO] [net.minecraft.client.Minecraft/]: Setting user: Dev
[16Feb2020 10:26:15.541] [Client thread/WARN] [net.minecraft.client.GameSettings/]: Skipping bad option: lastServer:
[16Feb2020 10:26:15.895] [Client thread/INFO] [net.minecraft.client.Minecraft/]: LWJGL Version: 3.2.2 build 10
[16Feb2020 10:26:39.403] [modloading-worker-2/INFO] [net.minecraftforge.common.ForgeMod/FORGEMOD]: Forge mod loading, version 28.1.0, for MC 1.14.4 with MCP 20190829.143755
[16Feb2020 10:26:39.404] [modloading-worker-2/INFO] [net.minecraftforge.common.MinecraftForge/FORGE]: MinecraftForge v28.1.0 Initialized
[16Feb2020 10:26:39.809] [modloading-worker-1/ERROR] [net.minecraftforge.fml.javafmlmod.FMLModContainer/LOADING]: Failed to create mod instance. ModID: gielinorcraft, class com.lk1905.gielinorcraft.Gielinorcraft
java.lang.NullPointerException: null
	at net.minecraftforge.common.capabilities.CapabilityManager.register(CapabilityManager.java:79) ~[?:?]
	at com.lk1905.gielinorcraft.capability.skill.CapabilitySkills.register(CapabilitySkills.java:26) ~[?:?]
	at com.lk1905.gielinorcraft.Gielinorcraft.<init>(Gielinorcraft.java:21) ~[?:?]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_161]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_161]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_161]
	at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_161]
	at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_161]
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:131) ~[?:28.1]
	at java.util.function.Consumer.lambda$andThen$0(Unknown Source) ~[?:1.8.0_161]
	at java.util.function.Consumer.lambda$andThen$0(Unknown Source) ~[?:1.8.0_161]
	at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112) ~[?:?]
	at net.minecraftforge.fml.ModList.lambda$null$10(ModList.java:133) ~[?:?]
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source) ~[?:1.8.0_161]
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source) ~[?:1.8.0_161]
	at java.util.stream.AbstractPipeline.copyInto(Unknown Source) ~[?:1.8.0_161]
	at java.util.stream.ForEachOps$ForEachTask.compute(Unknown Source) ~[?:1.8.0_161]
	at java.util.concurrent.CountedCompleter.exec(Unknown Source) ~[?:1.8.0_161]
	at java.util.concurrent.ForkJoinTask.doExec(Unknown Source) ~[?:1.8.0_161]
	at java.util.concurrent.ForkJoinTask.doInvoke(Unknown Source) ~[?:1.8.0_161]
	at java.util.concurrent.ForkJoinTask.invoke(Unknown Source) ~[?:1.8.0_161]
	at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(Unknown Source) ~[?:1.8.0_161]
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(Unknown Source) ~[?:1.8.0_161]
	at java.util.stream.AbstractPipeline.evaluate(Unknown Source) ~[?:1.8.0_161]
	at java.util.stream.ReferencePipeline.forEach(Unknown Source) ~[?:1.8.0_161]
	at java.util.stream.ReferencePipeline$Head.forEach(Unknown Source) ~[?:1.8.0_161]
	at net.minecraftforge.fml.ModList.lambda$dispatchParallelEvent$11(ModList.java:133) ~[?:?]
	at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.ForkJoinTask.doExec(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.ForkJoinPool.runWorker(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) [?:1.8.0_161]
[16Feb2020 10:26:41.171] [Client thread/FATAL] [net.minecraftforge.fml.ModLoader/LOADING]: Failed to complete lifecycle event CONSTRUCT, 1 errors found
[16Feb2020 10:26:41.172] [Client thread/FATAL] [net.minecraftforge.eventbus.EventBus/EVENTBUS]: EventBus 0 shutting down - future events will not be posted.
java.lang.Exception: stacktrace
	at net.minecraftforge.eventbus.EventBus.shutdown(EventBus.java:278) ~[eventbus-1.0.0-service.jar:?]
	at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$5(ClientModLoader.java:97) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?]
	at net.minecraftforge.fml.client.ClientModLoader.begin(ClientModLoader.java:79) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?]
	at net.minecraft.client.Minecraft.init(Minecraft.java:456) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?]
	at net.minecraft.client.Minecraft.run(Minecraft.java:365) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?]
	at net.minecraft.client.main.Main.main(Main.java:128) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_161]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_161]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_161]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_161]
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55) ~[forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?]
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-3.2.0.jar:?]
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:50) [modlauncher-3.2.0.jar:?]
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:68) [modlauncher-3.2.0.jar:?]
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:80) [modlauncher-3.2.0.jar:?]
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-3.2.0.jar:?]
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:101) [forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?]
[16Feb2020 10:26:55.621] [Client thread/INFO] [com.mojang.text2speech.NarratorWindows/]: Narrator library for x64 successfully loaded
[16Feb2020 10:26:58.384] [Thread-1/FATAL] [net.minecraftforge.common.ForgeConfig/CORE]: Forge config just got changed on the file system!
[16Feb2020 10:26:58.386] [Server-Worker-4/ERROR] [net.minecraftforge.fml.ModLoader/LOADING]: Skipping lifecycle event SETUP, 1 errors found.
[16Feb2020 10:26:58.387] [Server-Worker-4/FATAL] [net.minecraftforge.fml.ModLoader/LOADING]: Failed to complete lifecycle event SETUP, 1 errors found
[16Feb2020 10:26:58.387] [Server-Worker-4/FATAL] [net.minecraftforge.eventbus.EventBus/EVENTBUS]: EventBus 0 shutting down - future events will not be posted.
java.lang.Exception: stacktrace
	at net.minecraftforge.eventbus.EventBus.shutdown(EventBus.java:278) ~[eventbus-1.0.0-service.jar:?]
	at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$5(ClientModLoader.java:97) ~[?:?]
	at net.minecraftforge.fml.client.ClientModLoader.startModLoading(ClientModLoader.java:105) ~[?:?]
	at net.minecraftforge.fml.client.ClientModLoader.lambda$onreload$3(ClientModLoader.java:87) ~[?:?]
	at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$5(ClientModLoader.java:95) ~[?:?]
	at java.util.concurrent.CompletableFuture$AsyncRun.run(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.CompletableFuture$AsyncRun.exec(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.ForkJoinTask.doExec(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.ForkJoinPool.runWorker(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) [?:1.8.0_161]
[16Feb2020 10:27:07.462] [Realms Notification Availability checker #1/INFO] [com.mojang.realmsclient.client.RealmsClient/]: Could not authorize you against Realms server: Invalid session id
[16Feb2020 10:27:27.487] [Server-Worker-4/ERROR] [net.minecraftforge.fml.ModLoader/LOADING]: Skipping lifecycle event ENQUEUE_IMC, 1 errors found.
[16Feb2020 10:27:27.488] [Server-Worker-4/FATAL] [net.minecraftforge.fml.ModLoader/LOADING]: Failed to complete lifecycle event ENQUEUE_IMC, 1 errors found
[16Feb2020 10:27:27.488] [Server-Worker-4/FATAL] [net.minecraftforge.eventbus.EventBus/EVENTBUS]: EventBus 0 shutting down - future events will not be posted.
java.lang.Exception: stacktrace
	at net.minecraftforge.eventbus.EventBus.shutdown(EventBus.java:278) ~[eventbus-1.0.0-service.jar:?]
	at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$5(ClientModLoader.java:97) ~[?:?]
	at net.minecraftforge.fml.client.ClientModLoader.finishModLoading(ClientModLoader.java:118) ~[?:?]
	at net.minecraftforge.fml.client.ClientModLoader.lambda$onreload$4(ClientModLoader.java:89) ~[?:?]
	at java.util.concurrent.CompletableFuture.uniRun(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.CompletableFuture$UniRun.tryFire(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.CompletableFuture$Completion.exec(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.ForkJoinTask.doExec(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.ForkJoinPool.runWorker(Unknown Source) [?:1.8.0_161]
	at java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) [?:1.8.0_161]
[16Feb2020 10:27:27.533] [Client thread/WARN] [net.minecraft.client.GameSettings/]: Skipping bad option: lastServer:
[16Feb2020 10:27:29.123] [Client thread/INFO] [net.minecraft.client.audio.SoundSystem/]: OpenAL initialized.
[16Feb2020 10:27:29.162] [Client thread/INFO] [net.minecraft.client.audio.SoundEngine/SOUNDS]: Sound engine started
[16Feb2020 10:27:30.550] [Client thread/INFO] [net.minecraft.client.renderer.texture.AtlasTexture/]: Created: 512x512 textures-atlas
[16Feb2020 10:27:34.989] [Client thread/INFO] [net.minecraft.client.renderer.texture.AtlasTexture/]: Created: 256x256 textures/particle-atlas
[16Feb2020 10:27:35.013] [Client thread/INFO] [net.minecraft.client.renderer.texture.AtlasTexture/]: Created: 256x256 textures/painting-atlas
[16Feb2020 10:27:35.020] [Client thread/INFO] [net.minecraft.client.renderer.texture.AtlasTexture/]: Created: 128x128 textures/mob_effect-atlas

 

Link to comment
Share on other sites

I solved the problem. I was trying to register my capabilities in my Main class like this:

public Gielinorcraft() {
		
		CapabilitySkills.register();
		
		SkillContainer.registerNewSkill(AttackSkill.class);
		
		MinecraftForge.EVENT_BUS.register(AttackSkill.class);
	}

 

When i should have been registering them in a FMLCommonSetupEvent, like this:

public Gielinorcraft() {
		
	}
	
@SubscribeEvent
public static void onCommonSetup(FMLCommonSetupEvent e) {
		
	CapabilitySkills.register();
		
	SkillContainer.registerNewSkill(AttackSkill.class);
		
	MinecraftForge.EVENT_BUS.register(AttackSkill.class);
}

 

I can now load Minecraft. However, I now have another problem. When I try to load a world, I get this error:

[16Feb2020 17:53:25.510] [Server thread/ERROR] [net.minecraft.server.MinecraftServer/]: Encountered an unexpected exception
net.minecraft.crash.ReportedException: Saving entity NBT
	at net.minecraft.entity.Entity.writeWithoutTypeId(Entity.java:1592) ~[?:?]
	at net.minecraft.server.integrated.IntegratedPlayerList.writePlayerData(IntegratedPlayerList.java:27) ~[?:?]
	at net.minecraft.server.management.PlayerList.saveAllPlayerData(PlayerList.java:626) ~[?:?]
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:112) ~[?:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:646) [?:?]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_161]
Caused by: java.lang.NullPointerException
	at com.lk1905.gielinorcraft.capability.CommonCapabilityProvider.serializeNBT(CommonCapabilityProvider.java:49) ~[?:?]
	at net.minecraftforge.common.capabilities.CapabilityDispatcher.serializeNBT(CapabilityDispatcher.java:127) ~[?:?]
	at net.minecraftforge.common.capabilities.CapabilityProvider.serializeCaps(CapabilityProvider.java:86) ~[?:?]
	at net.minecraft.entity.Entity.writeWithoutTypeId(Entity.java:1567) ~[?:?]
	... 5 more
[16Feb2020 17:53:25.670] [Server thread/ERROR] [net.minecraft.server.MinecraftServer/]: This crash report has been saved to: C:\Users\Liam\eclipse-workspace\Gielinorcraft\run\.\crash-reports\crash-2020-02-16_17.53.25-server.txt
[16Feb2020 17:53:25.690] [Server thread/INFO] [net.minecraft.server.MinecraftServer/]: Stopping server
[16Feb2020 17:53:25.693] [Server thread/INFO] [net.minecraft.server.MinecraftServer/]: Saving players
[16Feb2020 17:53:25.695] [Server thread/ERROR] [net.minecraft.server.MinecraftServer/]: Exception stopping the server
net.minecraft.crash.ReportedException: Saving entity NBT
	at net.minecraft.entity.Entity.writeWithoutTypeId(Entity.java:1592) ~[?:?]
	at net.minecraft.server.integrated.IntegratedPlayerList.writePlayerData(IntegratedPlayerList.java:27) ~[?:?]
	at net.minecraft.server.management.PlayerList.saveAllPlayerData(PlayerList.java:626) ~[?:?]
	at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:559) ~[?:?]
	at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:235) ~[?:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:685) [?:?]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_161]
Caused by: java.lang.NullPointerException
	at com.lk1905.gielinorcraft.capability.CommonCapabilityProvider.serializeNBT(CommonCapabilityProvider.java:49) ~[?:?]
	at net.minecraftforge.common.capabilities.CapabilityDispatcher.serializeNBT(CapabilityDispatcher.java:127) ~[?:?]
	at net.minecraftforge.common.capabilities.CapabilityProvider.serializeCaps(CapabilityProvider.java:86) ~[?:?]
	at net.minecraft.entity.Entity.writeWithoutTypeId(Entity.java:1567) ~[?:?]
	... 6 more
[16Feb2020 17:53:27.042] [Client thread/INFO] [STDOUT/]: [net.minecraft.util.registry.Bootstrap:printToSYSOUT:106]: ---- Minecraft Crash Report ----
// Hey, that tickles! Hehehe!

Time: 16/02/20 5:53 PM
Description: Saving entity NBT

java.lang.NullPointerException: Saving entity NBT
	at com.lk1905.gielinorcraft.capability.CommonCapabilityProvider.serializeNBT(CommonCapabilityProvider.java:49) ~[?:?] {}
	at net.minecraftforge.common.capabilities.CapabilityDispatcher.serializeNBT(CapabilityDispatcher.java:127) ~[?:?] {}
	at net.minecraftforge.common.capabilities.CapabilityProvider.serializeCaps(CapabilityProvider.java:86) ~[?:?] {}
	at net.minecraft.entity.Entity.writeWithoutTypeId(Entity.java:1567) ~[?:?] {pl:accesstransformer:B}
	at net.minecraft.server.integrated.IntegratedPlayerList.writePlayerData(IntegratedPlayerList.java:27) ~[?:?] {pl:runtimedistcleaner:A}
	at net.minecraft.server.management.PlayerList.saveAllPlayerData(PlayerList.java:626) ~[?:?] {}
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:112) ~[?:?] {pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:646) ~[?:?] {pl:accesstransformer:B}
	at java.lang.Thread.run(Unknown Source) ~[?:1.8.0_161] {}


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
	at com.lk1905.gielinorcraft.capability.CommonCapabilityProvider.serializeNBT(CommonCapabilityProvider.java:49)
	at net.minecraftforge.common.capabilities.CapabilityDispatcher.serializeNBT(CapabilityDispatcher.java:127)
	at net.minecraftforge.common.capabilities.CapabilityProvider.serializeCaps(CapabilityProvider.java:86)

-- Entity being saved --
Details:
	Entity Type: minecraft:player (net.minecraft.entity.player.ServerPlayerEntity)
	Entity ID: 103
	Entity Name: Dev
	Entity's Exact location: 106.12, 64.00, 258.45
	Entity's Block location: World: (106,64,258), Chunk: (at 10,4,2 in 6,16; contains blocks 96,0,256 to 111,255,271), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
	Entity's Momentum: 0.00, -0.08, 0.00
	Entity's Passengers: []
	Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
	at net.minecraft.entity.Entity.writeWithoutTypeId(Entity.java:1567)
	at net.minecraft.server.integrated.IntegratedPlayerList.writePlayerData(IntegratedPlayerList.java:27)
	at net.minecraft.server.management.PlayerList.saveAllPlayerData(PlayerList.java:626)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:112)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:646)
	at java.lang.Thread.run(Unknown Source)

-- System Details --
Details:
	Minecraft Version: 1.14.4
	Minecraft Version ID: 1.14.4
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 1.8.0_161, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 187450632 bytes (178 MB) / 598736896 bytes (571 MB) up to 820510720 bytes (782 MB)
	CPUs: 4
	JVM Flags: 1 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
	ModLauncher: 3.2.0+60+b86c1d4
	ModLauncher launch target: fmluserdevclient
	ModLauncher naming: mcp
	ModLauncher services: 
		/eventbus-1.0.0-service.jar eventbus PLUGINSERVICE 
		/forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar object_holder_definalize PLUGINSERVICE 
		/forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar runtime_enum_extender PLUGINSERVICE 
		/accesstransformers-1.0.0-shadowed.jar accesstransformer PLUGINSERVICE 
		/forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar capability_inject_definalize PLUGINSERVICE 
		/forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar runtimedistcleaner PLUGINSERVICE 
		/forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar fml TRANSFORMATIONSERVICE 
	FML: 28.1
	Forge: net.minecraftforge:28.1.0
	FML Language Providers: 
		[email protected]
		minecraft@1
	Mod List: 
		forge-1.14.4-28.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar Forge {[email protected] DONE}
		main Gielinorcraft {[email protected] DONE}
		client-extra.jar Minecraft {[email protected] DONE}
	Player Count: 1 / 8; [ServerPlayerEntity['Dev'/103, l='Test world', x=106.12, y=64.00, z=258.45]]
	Data Packs: vanilla, mod:gielinorcraft, mod:forge
	Type: Integrated Server (map_client.txt)
	Is Modded: Definitely; Client brand changed to 'forge'
[16Feb2020 17:53:27.044] [Client thread/INFO] [STDOUT/]: [net.minecraft.util.registry.Bootstrap:printToSYSOUT:106]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2020-02-16_17.53.25-server.txt

 

CommonCapabilityProvider.java:

package com.lk1905.gielinorcraft.capability;

import net.minecraft.nbt.INBT;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.LazyOptional;

public class CommonCapabilityProvider<HANDLER> implements ICapabilitySerializable<INBT>{

	protected final Capability<HANDLER> capability;
	protected final Direction side;
	protected final HANDLER instance;
	
	protected final LazyOptional<HANDLER> lazyOptional;
	
	public CommonCapabilityProvider(Capability<HANDLER> capability, Direction side, HANDLER instance) {
		
		this.capability = capability;
		this.side = side;
		this.instance = instance;
		
		if(this.instance != null) {
			
			lazyOptional = LazyOptional.of(() -> this.instance);
			
		}else {
			
			lazyOptional = LazyOptional.empty();
		}
	}
	
	


	@Override
	public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
		
		return getCapability().orEmpty(cap, lazyOptional);
	}
	
	public final Capability<HANDLER> getCapability(){
		return capability;
	}

	@Override
	public INBT serializeNBT() {

		return getCapability().writeNBT(getInstance(), getFacing());//<-- THIS LINE
	}

	@Override
	public void deserializeNBT(INBT nbt) {

		getCapability().readNBT(getInstance(), getFacing(), nbt);
	}
	
	public Direction getFacing() {
		return side;
	}
	
	public HANDLER getInstance() {
		return instance;
	}
}

 

Can anyone see what I'm doing wrong in this class?

Link to comment
Share on other sites

I tried removing the second getCapability() constructor(the one that returns capability) and referring to capability directly. Made no difference. Also added the @Nullable annotation to see if that did anything. Made no difference either.

Current code for CommonCapabilityProvider.java

package com.lk1905.gielinorcraft.capability;

import javax.annotation.Nullable;

import net.minecraft.nbt.INBT;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.LazyOptional;

public class CommonCapabilityProvider<HANDLER> implements ICapabilitySerializable<INBT>{

	protected final Capability<HANDLER> capability;
	protected final Direction side;
	protected final HANDLER instance;
	
	protected final LazyOptional<HANDLER> lazyOptional;
	
	public CommonCapabilityProvider(final Capability<HANDLER> capability, @Nullable final Direction side, @Nullable final HANDLER instance) {
		
		this.capability = capability;
		this.side = side;
		this.instance = instance;
		
		if(this.instance != null) {
			
			lazyOptional = LazyOptional.of(() -> this.instance);
			
		}else {
			
			lazyOptional = LazyOptional.empty();
		}
	}

	@Override
	public <T> LazyOptional<T> getCapability(final Capability<T> cap, @Nullable final Direction side) {
		
		return capability.orEmpty(cap, lazyOptional);
	}

	@Nullable
	@Override
	public INBT serializeNBT() {

		return capability.writeNBT(getInstance(), getFacing());//<-- THIS LINE
	}

	@Override
	public void deserializeNBT(INBT nbt) {

		capability.readNBT(getInstance(), getFacing(), nbt);
	}
	
	@Nullable
	public Direction getFacing() {
		return side;
	}
	
	@Nullable
	public HANDLER getInstance() {
		return instance;
	}
}

 

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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