Jump to content

Recommended Posts

Posted (edited)

Hey, so I want to spawn an entity when the player joins the world but I get a crash every time I join the world:

Spoiler
 
 
 
 
Spoiler

---- Minecraft Crash Report ----
// Shall we play a game?

Time: 3/8/20 2:19 PM
Description: Ticking memory connection

java.lang.NullPointerException: Ticking memory connection
	at net.minecraft.entity.Entity.<init>(Entity.java:205) ~[forge-1.14.4-28.2.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.entity.LivingEntity.<init>(LivingEntity.java:192) ~[forge-1.14.4-28.2.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.MobEntity.<init>(MobEntity.java:99) ~[forge-1.14.4-28.2.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.entity.CreatureEntity.<init>(CreatureEntity.java:13) ~[forge-1.14.4-28.2.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.AgeableEntity.<init>(AgeableEntity.java:23) ~[forge-1.14.4-28.2.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.entity.passive.AnimalEntity.<init>(AnimalEntity.java:30) ~[forge-1.14.4-28.2.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at tk.bytiny.epicmod.entitys.testmob.<init>(testmob.java:13) ~[main/:?] {re:classloading}
	at tk.bytiny.epicmod.listener.p_replacer.plogin(p_replacer.java:25) ~[main/:?] {re:classloading}
	at net.minecraftforge.eventbus.ASMEventHandler_7_p_replacer_plogin_PlayerLoggedInEvent.invoke(.dynamic) ~[?:?] {}
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80) ~[eventbus-1.0.0-service.jar:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258) ~[eventbus-1.0.0-service.jar:?] {}
	at net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerLoggedIn(BasicEventHooks.java:43) ~[?:?] {re:classloading}
	at net.minecraft.server.management.PlayerList.initializeConnectionToPlayer(PlayerList.java:206) ~[?:?] {re:classloading}
	at net.minecraft.network.login.ServerLoginNetHandler.tryAcceptPlayer(ServerLoginNetHandler.java:119) ~[?:?] {re:classloading}
	at net.minecraft.network.login.ServerLoginNetHandler.tick(ServerLoginNetHandler.java:63) ~[?:?] {re:classloading}
	at net.minecraft.network.NetworkManager.tick(NetworkManager.java:241) ~[?:?] {re:classloading}
	at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:148) ~[?:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:882) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:800) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:646) [?:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_191] {}


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

-- Head --
Thread: Server thread
Stacktrace:
	at net.minecraft.entity.Entity.<init>(Entity.java:205)
	at net.minecraft.entity.LivingEntity.<init>(LivingEntity.java:192)
	at net.minecraft.entity.MobEntity.<init>(MobEntity.java:99)
	at net.minecraft.entity.CreatureEntity.<init>(CreatureEntity.java:13)
	at net.minecraft.entity.AgeableEntity.<init>(AgeableEntity.java:23)
	at net.minecraft.entity.passive.AnimalEntity.<init>(AnimalEntity.java:30)
	at tk.bytiny.epicmod.entitys.testmob.<init>(testmob.java:13)
	at tk.bytiny.epicmod.listener.p_replacer.plogin(p_replacer.java:25)
	at net.minecraftforge.eventbus.ASMEventHandler_7_p_replacer_plogin_PlayerLoggedInEvent.invoke(.dynamic)
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258)
	at net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerLoggedIn(BasicEventHooks.java:43)
	at net.minecraft.server.management.PlayerList.initializeConnectionToPlayer(PlayerList.java:206)
	at net.minecraft.network.login.ServerLoginNetHandler.tryAcceptPlayer(ServerLoginNetHandler.java:119)
	at net.minecraft.network.login.ServerLoginNetHandler.tick(ServerLoginNetHandler.java:63)
	at net.minecraft.network.NetworkManager.tick(NetworkManager.java:241)

-- Ticking connection --
Details:
	Connection: net.minecraft.network.NetworkManager@6a6d93d6
Stacktrace:
	at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:148)
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:882)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:800)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
	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_191, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 567013392 bytes (540 MB) / 1816657920 bytes (1732 MB) up to 3806855168 bytes (3630 MB)
	CPUs: 16
	JVM Flags: 1 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
	ModLauncher: 4.1.0+62+5bfa59b
	ModLauncher launch target: fmluserdevclient
	ModLauncher naming: mcp
	ModLauncher services: 
		/eventbus-1.0.0-service.jar eventbus PLUGINSERVICE 
		/forge-1.14.4-28.2.0_mapped_snapshot_20190719-1.14.3-launcher.jar object_holder_definalize PLUGINSERVICE 
		/forge-1.14.4-28.2.0_mapped_snapshot_20190719-1.14.3-launcher.jar runtime_enum_extender PLUGINSERVICE 
		/accesstransformers-1.0.1-milestone.0.1+94458e7-shadowed.jar accesstransformer PLUGINSERVICE 
		/forge-1.14.4-28.2.0_mapped_snapshot_20190719-1.14.3-launcher.jar capability_inject_definalize PLUGINSERVICE 
		/forge-1.14.4-28.2.0_mapped_snapshot_20190719-1.14.3-launcher.jar runtimedistcleaner PLUGINSERVICE 
		/forge-1.14.4-28.2.0_mapped_snapshot_20190719-1.14.3-launcher.jar fml TRANSFORMATIONSERVICE 
	FML: 28.2
	Forge: net.minecraftforge:28.2.0
	FML Language Providers: 
		[email protected]
		minecraft@1
	Mod List: 
		client-extra.jar Minecraft {[email protected] DONE}
		forge-1.14.4-28.2.0_mapped_snapshot_20190719-1.14.3-recomp.jar Forge {[email protected] DONE}
		main Epic Mod {em@NONE DONE}
	Player Count: 1 / 8; [ServerPlayerEntity['Dev'/95, l='test', x=0.00, y=5.00, z=0.00]]
	Data Packs: vanilla, mod:em, mod:forge
	Type: Integrated Server (map_client.txt)
	Is Modded: Definitely; Client brand changed to 'forge'

 

I tried figuring out what the problem might be but all I could find out was that it might have to do something with getting the world.

 

This is the class where I'm spawning the entity. I tested this with a Minecraft villager and it worked:

Spoiler
 
 
 
 
 
 
 
 
Spoiler

package tk.bytiny.epicmod.listener;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import tk.bytiny.epicmod.main;
import tk.bytiny.epicmod.entitys.mobentity;
import tk.bytiny.epicmod.entitys.testmob;

@EventBusSubscriber(modid = main.MODID, bus = Bus.FORGE)
public class p_replacer {

	public static EntityType<testmob> entity2 = mobentity.TESTMOB;
	public static testmob person2;
	public static PlayerEntity p;
	
	@SubscribeEvent
	public static void plogin(PlayerLoggedInEvent event) {
		if(event.getEntity() instanceof PlayerEntity)
		{
			p = (PlayerEntity) event.getEntity();			
			person2 = new testmob(entity2, p.world);
			p.world.addEntity(person2);
			person2.setPosition(p.getPosition().getX(), p.getPosition().getY(), p.getPosition().getZ());
		}
	}
}

 

 

For the entity I followed the tutorial of Jorrit Tyberghein:

Spoiler
 
 
 
 
Spoiler

 

 

And those are my entity classes:

Spoiler
 
 
 
 
Spoiler

package tk.bytiny.epicmod.entitys;

import javax.annotation.Nullable;

import net.minecraft.entity.AgeableEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.world.World;

public class testmob extends AnimalEntity {

	public testmob(EntityType<? extends AnimalEntity> type, World worldIn) {
		super(type, worldIn);
	}
	
	@Nullable
	@Override
	public AgeableEntity createChild(AgeableEntity ageable) {
		return null;
	}

}

package tk.bytiny.epicmod.entitys;

import net.minecraft.entity.EntityType;
import net.minecraftforge.registries.ObjectHolder;

public class mobentity {

	@ObjectHolder("em:testmob")
	public static EntityType<testmob> TESTMOB;
	
}

package tk.bytiny.epicmod.entitys;

import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.entity.model.RendererModel;

public class TestmobModel extends EntityModel<testmob> {

	public RendererModel body;
	
	public TestmobModel() {
		body = new RendererModel(this, 0, 0);
		body.addBox(-3, -3, -3, 6, 6, 6);
	}
	
	@Override
	public void render(testmob entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
		setRotationAngles(entityIn, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale);
		body.render(scale);
	}
	
	@Override
	public void setRotationAngles(testmob entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor) {
	}
	
}

package tk.bytiny.epicmod.entitys;

import javax.annotation.Nullable;

import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.util.ResourceLocation;
import tk.bytiny.epicmod.main;

public class TestmobRenderer extends MobRenderer<testmob, TestmobModel>{
	
	public TestmobRenderer(EntityRendererManager manager) {
		super(manager, new TestmobModel(), 0.5f);
	}

	@Nullable
	@Override
	protected ResourceLocation getEntityTexture(testmob entity) {
		return new ResourceLocation(main.MODID, "textures/entity/testmob.png");
	}

}

package tk.bytiny.epicmod.init;

import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraftforge.event.RegistryEvent.Register;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import tk.bytiny.epicmod.main;
import tk.bytiny.epicmod.entitys.TestmobRenderer;
import tk.bytiny.epicmod.entitys.testmob;
import tk.bytiny.epicmod.item.BasicItem;

@EventBusSubscriber(modid = main.MODID, bus = Bus.MOD)
public class Epicmobs{

	public static final BasicItem BASIC_ITEM = new BasicItem();
	
	@SubscribeEvent
	public static void registerEntity(Register<EntityType<?>> event) {
		event.getRegistry().register(EntityType.Builder.create(testmob::new, EntityClassification.CREATURE).size(1, 1).setShouldReceiveVelocityUpdates(false).build("testmob").setRegistryName(main.MODID, "testmob"));
		RenderingRegistry.registerEntityRenderingHandler(testmob.class, TestmobRenderer::new);
	}
}

 

I tried my best to find out what the problem is and this is the first time I ask online for help. I hope I didn't overlock something stupid and that you guys can maybe help me.

Edited by byTiny
Edited title to fit better.
Posted

Thanks very much for the reply it helped me a lot and I fixed the problem now and I'm sorry that you had to look at the terrible code I wrote.

I tried addressing the problems you mentioned. I now added comments to everything so it's not confusing anymore. I cleaned the code from all unused code, for example, the BASICI_ITEM line which wasn't supposed to be there.

But I still have a question: I'm currently using this project for testing code and then copy it into my real project. There my ModID is "gamechanger" and the reason why the other project has the short ModID "em" is that it is faster to type. So my question is: is there a specific reason why the ModID has to be long?

Posted
3 hours ago, byTiny said:

is there a specific reason why the ModID has to be long?

Imagine if everyone used 2 character mod IDs. That means there would be a lot of conflicts, as there are only 26² possible combinations, but some would be more popular than others.

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.