Jump to content

[1.8] Help with creating new entity please


QueenNuffer

Recommended Posts

Hi!

 

I am in need of some help please.  I've completed a simple recipe mod now (SmeltCycle on curse), and am attempting something more complex.  I'm a software dev as a day job, although I haven't done much Java in a while.  Functionally, what I want to do is change some of the behavior when horses are bred (altering stats) - specifically, the createChild method on EntityHorse, I'd like to supplement that logic with my own.

 

So, I've created a new class EntityAdvancedHorse, which extends EntityHorse:

[spoiler=EntityAdvancedHorse]

package com.queennuffer.horsinaround;

 

import net.minecraft.entity.EntityAgeable;

import net.minecraft.entity.passive.EntityHorse;

import net.minecraft.util.BlockPos;

import net.minecraft.world.World;

 

public class EntityAdvancedHorse extends EntityHorse {

 

@Override

    public EntityAgeable createChild(EntityAgeable ageable){

EntityAgeable kid = super.createChild(ageable);

 

kid.setCustomNameTag("Child of " + this.getCustomNameTag() + " and " + ageable.getCustomNameTag());

return kid;   

    }

 

public EntityAdvancedHorse(EntityHorse copyFrom, World worldIn){

super(worldIn);

this.copyDataFromOld(copyFrom);   

}

 

public EntityAdvancedHorse(World worldIn) {

super(worldIn);

// TODO Auto-generated constructor stub

}

 

}

 

 

 

In preInit, I'm registering the entity:

EntityRegistry.registerModEntity(EntityAdvancedHorse.class, "AdvancedHorse", ID, this, 80, 3, true);

   

And then, in init, registering the renderer:

if(initEvent.getSide().isClient()){

  RenderingRegistry.registerEntityRenderingHandler(EntityAdvancedHorse.class,

    new RenderHorse(Minecraft.getMinecraft().getRenderManager(), new ModelHorse(), 0.5F));

}

 

I'm trapping the EntityJoinWorldEvent and replacing an EntityHorse with a new EntityAdvancedHorse:

[spoiler=replaceHorses]

@SubscribeEvent

public void replaceHorses(EntityJoinWorldEvent event){

    if(!event.world.isRemote){

          if (event.entity instanceof EntityHorse){

        EntityHorse theHorse = (EntityHorse) event.entity;

            EntityAdvancedHorse newHorse = new EntityAdvancedHorse(theHorse, event.world);

            newHorse.setPosition(event.entity.posX, event.entity.posY, event.entity.posZ);

            event.entity.setDead();

          }  

    }

}

 

 

 

The horses appear briefly, and then flash out of existence...my assumption is that the code is running, EntityAdvancedHorse is getting created but not rendering?  There's no error in stdout to indicate a problem occurred, but no visible horses either. 

 

Could someone please point me in the right direction?  I'm sure I've made some rookie mistakes here!

Geek girl and professional code wrangler, but new to Forge.

Link to comment
Share on other sites

You are never spawning new horse.

 

event.world.spawnEntityInWorld(newHorse);

 

EDIT

Oh, that's not all. This way (you are doing), you will be spawning normal horse and advancedHorse, where normal one will simply die in 1 tick time.

 

Proper way of doing this is to cancel EntityJoinWorldEvent and inside it - perform "replacement" spawning.

 

Simple example:

@SubscribeEvent
public void onAttack(EntityJoinWorldEvent event)
{
// Checks
event.setCanceled(true);
// your code
}

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Sadly, this did not work, and the game now crashes, but I'm a little stumped as to why.

 

My EntityJoinWorldEvent now looks like this:

[spoiler=EntityJoinWorldEvent]

@SubscribeEvent
public void replaceHorses(EntityJoinWorldEvent event){ 
  if(!event.world.isRemote){
    if (event.entity instanceof EntityHorse && !(event.entity instanceof EntityAdvancedHorse)){
      EntityHorse theHorse = (EntityHorse) event.entity;
      EntityAdvancedHorse newHorse = new EntityAdvancedHorse(event.world);
      newHorse.setPosition(event.entity.posX, event.entity.posY, event.entity.posZ);
      System.out.println("Makey advanced");
      event.world.spawnEntityInWorld(newHorse);
      event.setCanceled(true);
    }	  
  }
}

 

 

When entering my world, the game crashes with the following stack trace:

[spoiler=Stack trace]

[06:52:51] [main/INFO] [FML]: Forge Mod Loader version 8.99.0.1405 for Minecraft 1.8 loading
[06:52:51] [main/INFO] [FML]: Java is Java HotSpot(TM) Client VM, version 1.8.0_45, running on Windows XP:x86:5.1, installed at C:\Program Files\Java\jre1.8.0_45
[06:52:51] [main/INFO] [FML]: Managed to load a deobfuscated Minecraft name- we are in a deobfuscated environment. Skipping runtime deobfuscation
[06:52:51] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.gradle.tweakers.CoremodTweaker
[06:52:51] [main/INFO] [GradleStart]: Injecting location in coremod net.minecraftforge.fml.relauncher.FMLCorePlugin
[06:52:51] [main/INFO] [GradleStart]: Injecting location in coremod net.minecraftforge.classloading.FMLForgePlugin
[06:52:51] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker
[06:52:51] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.FMLDeobfTweaker
[06:52:51] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.gradle.tweakers.AccessTransformerTweaker
[06:52:51] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker
[06:52:51] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLInjectionAndSortingTweaker
[06:52:51] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper
[06:52:52] [main/ERROR] [FML]: The binary patch set is missing. Either you are in a development environment, or things are not going to work!
[06:52:56] [main/ERROR] [FML]: FML appears to be missing any signature data. This is not a good thing
[06:52:56] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper
[06:52:56] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.FMLDeobfTweaker
[06:52:56] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.gradle.tweakers.AccessTransformerTweaker
[06:52:56] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.fml.common.launcher.TerminalTweaker
[06:52:56] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.common.launcher.TerminalTweaker
[06:52:56] [main/INFO] [LaunchWrapper]: Launching wrapped minecraft {net.minecraft.client.main.Main}
[06:52:57] [Client thread/INFO]: Setting user: QueenNuffer
[06:52:59] [Client thread/INFO]: LWJGL Version: 2.9.1
[06:53:00] [Client thread/INFO] [sTDOUT]: [net.minecraftforge.fml.client.SplashProgress:start:224]: ---- Minecraft Crash Report ----
// I let you down. Sorry 

Time: 6/11/15 6:53 AM
Description: Loading screen debug info

java.lang.Throwable
at net.minecraftforge.fml.client.SplashProgress.start(SplashProgress.java:223)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:195)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:446)
at net.minecraft.client.Minecraft.run(Minecraft.java:356)
at net.minecraft.client.main.Main.main(Main.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)


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

-- System Details --
Details:
Minecraft Version: 1.8
Operating System: Windows XP (x86) version 5.1
Java Version: 1.8.0_45, Oracle Corporation
Java VM Version: Java HotSpot(TM) Client VM (mixed mode, sharing), Oracle Corporation
Memory: 61930704 bytes (59 MB) / 127631360 bytes (121 MB) up to 259522560 bytes (247 MB)
JVM Flags: 0 total; 
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: 
Loaded coremods (and transformers): 
GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.5.0 NVIDIA 347.25' Renderer: 'GeForce GT 630/PCIe/SSE2'
[06:53:00] [Client thread/INFO] [MinecraftForge]: Attempting early MinecraftForge initialization
[06:53:00] [Client thread/INFO] [FML]: MinecraftForge v11.14.1.1405 Initialized
[06:53:00] [Client thread/INFO] [FML]: Replaced 204 ore recipies
[06:53:00] [Client thread/INFO] [FML]: Preloading CrashReport classes
[06:53:00] [Client thread/INFO] [MinecraftForge]: Completed early MinecraftForge initialization
[06:53:00] [Client thread/INFO] [FML]: Found 0 mods from the command line. Injecting into mod discoverer
[06:53:00] [Client thread/INFO] [FML]: Searching G:\ForgeDev\Mods\HorsinAround\mods for mods
[06:53:01] [Client thread/INFO] [FML]: Forge Mod Loader has identified 4 mods to load
[06:53:01] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, HorsinAround] at CLIENT
[06:53:01] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, HorsinAround] at SERVER
[06:53:02] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:Horsin' Around
[06:53:02] [Client thread/INFO] [FML]: Processing ObjectHolder annotations
[06:53:02] [Client thread/INFO] [FML]: Found 384 ObjectHolder annotations
[06:53:02] [Client thread/INFO] [FML]: Configured a dormant chunk cache size of 0
[06:53:02] [Client thread/INFO] [FML]: Applying holder lookups
[06:53:02] [Client thread/INFO] [FML]: Holder lookups applied
[06:53:05] [sound Library Loader/INFO]: Starting up SoundSystem...
[06:53:05] [Thread-9/INFO]: Initializing LWJGL OpenAL
[06:53:05] [Thread-9/INFO]: (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
[06:53:07] [Thread-9/INFO]: OpenAL initialized.
[06:53:07] [sound Library Loader/INFO]: Sound engine started
[06:53:10] [Client thread/INFO]: Created: 512x512 textures-atlas
[06:53:10] [Client thread/ERROR] [FML]: Model definition for location horsinaround:PaddedLeather#inventory not found
[06:53:10] [Client thread/ERROR] [FML]: Model definition for location horsinaround:staticator#inventory not found
[06:53:10] [Client thread/ERROR] [FML]: Model definition for location horsinaround:ToffeeApple#inventory not found
[06:53:10] [Client thread/ERROR] [FML]: Model definition for location horsinaround:CookedZombieFlesh#inventory not found
[06:53:11] [Client thread/INFO] [FML]: Forge Mod Loader has successfully loaded 4 mods
[06:53:11] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:Horsin' Around
[06:53:11] [Client thread/INFO]: SoundSystem shutting down...
[06:53:11] [Client thread/WARN]: Author: Paul Lamb, www.paulscode.com
[06:53:11] [sound Library Loader/INFO]: Starting up SoundSystem...
[06:53:12] [Thread-11/INFO]: Initializing LWJGL OpenAL
[06:53:12] [Thread-11/INFO]: (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
[06:53:12] [Thread-11/INFO]: OpenAL initialized.
[06:53:12] [sound Library Loader/INFO]: Sound engine started
[06:53:16] [Client thread/INFO]: Created: 512x512 textures-atlas
[06:53:16] [Client thread/ERROR] [FML]: Model definition for location horsinaround:PaddedLeather#inventory not found
[06:53:16] [Client thread/ERROR] [FML]: Model definition for location horsinaround:staticator#inventory not found
[06:53:16] [Client thread/ERROR] [FML]: Model definition for location horsinaround:ToffeeApple#inventory not found
[06:53:16] [Client thread/ERROR] [FML]: Model definition for location horsinaround:CookedZombieFlesh#inventory not found
[06:53:22] [server thread/INFO]: Starting integrated minecraft server version 1.8
[06:53:22] [server thread/INFO]: Generating keypair
[06:53:22] [server thread/INFO] [FML]: Injecting existing block and item data into this server instance
[06:53:22] [server thread/INFO] [FML]: Applying holder lookups
[06:53:22] [server thread/INFO] [FML]: Holder lookups applied
[06:53:22] [server thread/INFO] [FML]: Loading dimension 0 (New World) (net.minecraft.server.integrated.IntegratedServer@1415cef)
[06:53:22] [server thread/INFO] [FML]: Loading dimension 1 (New World) (net.minecraft.server.integrated.IntegratedServer@1415cef)
[06:53:22] [server thread/INFO] [FML]: Loading dimension -1 (New World) (net.minecraft.server.integrated.IntegratedServer@1415cef)
[06:53:22] [server thread/INFO]: Preparing start region for level 0
[06:53:23] [server thread/INFO] [sTDOUT]: [com.queennuffer.horsinaround.BreedManager:replaceHorses:37]: Makey advanced
[06:53:23] [server thread/ERROR]: Encountered an unexpected exception
java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextNode(Unknown Source) ~[?:1.8.0_45]
at java.util.HashMap$KeyIterator.next(Unknown Source) ~[?:1.8.0_45]
at com.google.common.collect.AbstractMapBasedMultimap$WrappedCollection$WrappedIterator.next(AbstractMapBasedMultimap.java:486) ~[guava-17.0.jar:?]
at net.minecraft.util.ClassInheritanceMultiMap$2.computeNext(ClassInheritanceMultiMap.java:125) ~[forgeSrc-1.8-11.14.1.1405.jar:?]
at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143) ~[guava-17.0.jar:?]
at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138) ~[guava-17.0.jar:?]
at net.minecraft.world.World.loadEntities(World.java:3372) ~[World.class:?]
at net.minecraft.world.chunk.Chunk.onChunkLoad(Chunk.java:1017) ~[Chunk.class:?]
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:46) ~[ChunkIOProvider.class:?]
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:12) ~[ChunkIOProvider.class:?]
at net.minecraftforge.common.util.AsynchronousExecutor.skipQueue(AsynchronousExecutor.java:344) ~[AsynchronousExecutor.class:?]
at net.minecraftforge.common.util.AsynchronousExecutor.getSkipQueue(AsynchronousExecutor.java:302) ~[AsynchronousExecutor.class:?]
at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:12) ~[ChunkIOExecutor.class:?]
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:133) ~[ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:108) ~[ChunkProviderServer.class:?]
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:343) ~[MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:113) ~[integratedServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:130) ~[integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:500) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
[06:53:23] [server thread/ERROR]: This crash report has been saved to: G:\ForgeDev\Mods\HorsinAround\.\crash-reports\crash-2015-06-11_06.53.23-server.txt
[06:53:23] [server thread/INFO] [FML]: Applying holder lookups
[06:53:23] [server thread/INFO] [FML]: Holder lookups applied
[06:53:23] [server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STARTING and forced into state SERVER_STOPPED. Errors may have been discarded.
[06:53:24] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:660]: ---- Minecraft Crash Report ----
// I feel sad now 

Time: 6/11/15 6:53 AM
Description: Exception in server tick loop

java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextNode(Unknown Source)
at java.util.HashMap$KeyIterator.next(Unknown Source)
at com.google.common.collect.AbstractMapBasedMultimap$WrappedCollection$WrappedIterator.next(AbstractMapBasedMultimap.java:486)
at net.minecraft.util.ClassInheritanceMultiMap$2.computeNext(ClassInheritanceMultiMap.java:125)
at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
at net.minecraft.world.World.loadEntities(World.java:3372)
at net.minecraft.world.chunk.Chunk.onChunkLoad(Chunk.java:1017)
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:46)
at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:12)
at net.minecraftforge.common.util.AsynchronousExecutor.skipQueue(AsynchronousExecutor.java:344)
at net.minecraftforge.common.util.AsynchronousExecutor.getSkipQueue(AsynchronousExecutor.java:302)
at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:12)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:133)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:108)
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:343)
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:113)
at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:130)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:500)
at java.lang.Thread.run(Unknown Source)


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

-- System Details --
Details:
Minecraft Version: 1.8
Operating System: Windows XP (x86) version 5.1
Java Version: 1.8.0_45, Oracle Corporation
Java VM Version: Java HotSpot(TM) Client VM (mixed mode, sharing), Oracle Corporation
Memory: 77899184 bytes (74 MB) / 208257024 bytes (198 MB) up to 259522560 bytes (247 MB)
JVM Flags: 0 total; 
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.10 FML v8.99.0.1405 Minecraft Forge 11.14.1.1405 4 mods loaded, 4 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available
FML{8.99.0.1405} [Forge Mod Loader] (forgeSrc-1.8-11.14.1.1405.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available
Forge{11.14.1.1405} [Minecraft Forge] (forgeSrc-1.8-11.14.1.1405.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available
HorsinAround{1.0} [Horsin' Around] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available
Loaded coremods (and transformers): 
GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
Profiler Position: N/A (disabled)
Player Count: 0 / 8; []
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'
[06:53:24] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:660]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2015-06-11_06.53.23-server.txt
AL lib: (EE) alc_cleanup: 1 device not closed

 

 

Things I've tried:

- Adding the spawnEntityInWorld to the server's scheduled tasks as a new Runnable (thinking maybe it was a threading issue).  Same effect.

- Making newHorse an instance of EntityPig, just to rule out being an issue with my class.  Same effect.

 

Any pointers please?

Geek girl and professional code wrangler, but new to Forge.

Link to comment
Share on other sites

Hmm, welp - this works for me:

@SubscribeEvent
public void onEntityJoined(EntityJoinWorldEvent event)
{
if (event.entity instanceof EntityEgg)
{
	event.setCanceled(true);
	EntityCreeper lol = new EntityCreeper(event.world);
	lol.setPosition(event.entity.posX, event.entity.posY, event.entity.posZ);
	event.world.spawnEntityInWorld(lol);
}
}

 

Try this EXACT code - it has to work. (EDIT: You can also add !world.isRemote - doesn't matter (in this case, it's an example)).

 

What might be wrong:

- You are using wrong event bus (should be Forge).

- Something's wrong with your constructor

- I don't know.

- Error is totally elsewhere (weird crash is weird) EDIT

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Ok...that works, and when I throw an egg, I get a creeper.  However I then changed it to:

 

@SubscribeEvent
public void onEntityJoined(EntityJoinWorldEvent event)
{
	if (event.entity instanceof EntityCreeper)
	{
		event.setCanceled(true);
		EntityPig lol = new EntityPig(event.world);
		lol.setPosition(event.entity.posX, event.entity.posY, event.entity.posZ);
		event.world.spawnEntityInWorld(lol);
	}
}

 

This has the same issue as before.  Could there be some timing issue here that in the case of the EntityEgg, that code's not getting called when I first enter the world, but in the case of replace creepers with pigs, it's running at world enter? 

 

This is my code for the event bus:

MinecraftForge.EVENT_BUS.register(new BreedManager());

 

 

Geek girl and professional code wrangler, but new to Forge.

Link to comment
Share on other sites

Indeed.

I belive you/we just discovered glitch in event (or at least unexpected turn).

I did some testing, seems like thee crash occurs when game tries to load entity-to-remove from memory (NBT).

 

Explanation:

If you would run totally new world - all the new EntityHorse (and others) are constructed and joining world for the first time. That means there is no NBT-loading for them and event will work (test it - it will work on new world).

Problem occurs if you would have world in which there was EntityHorse alredy spawned (at least once) and which woud try to actually load its NBT data when joinind the world. In that case game crashes.

 

I'll be damned, but for me it's at least bad, if not horrible.

I placed breakpoints and for me it crashed on

World.class

           if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityJoinWorldEvent(p_72838_1_, this)) && !flag) return false;

            this.getChunkFromChunkCoords(i, j).addEntity(p_72838_1_);
            this.loadedEntityList.add(p_72838_1_);
            this.onEntityAdded(p_72838_1_);
            return true;
        }
    }

    public void onEntityAdded(Entity p_72923_1_)
    {
        for (int i = 0; i < this.worldAccesses.size(); ++i)
        {
            ((IWorldAccess)this.worldAccesses.get(i)).onEntityAdded(p_72923_1_);  // crash occured here, on second loop (i = 1), when creeper was added to world, event was canceled and i spawned pig.
        }
    }

 

EDIT

Some of Forge pros - could you guys look into it?

 

EDIT 2

More directly:

Error doesn't occur when creeper is canceled, but when second replacement entity calls "event.world.spawnEntityInWorld(lol);" (using code from prev post).

 

It can obviously be my lack of knowledge about spawning code. How else would you spawn entity replacement if not like I proposed?

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

  • 2 weeks later...

So, I've been trying to work a way around this, perhaps with another event.  I decided to use the EnteringChunk event and replace then.  Doing this:

 

@SubscribeEvent
public void monitorChunk(EnteringChunk event){
	if(event.entity instanceof EntityHorse && !(event.entity instanceof EntityAdvancedHorse)){
		World theWorld = event.entity.getEntityWorld();
		theWorld.spawnEntityInWorld( new EntityAdvancedHorse( (EntityHorse)event.entity, theWorld) );
		theWorld.removeEntity(event.entity);
	}
}

 

The new horse is created (my constructor places it in the same place as the old one), however, I end up with a "ghost" horse as well that just stands there looking stupid and is not able to be interacted with/killed/collided with.  It eventually disappears when you leave the world and return again.

 

Any idea what I'm doing wrong?  I tried the same code with a cow, and ended up with an unusable cow?

Geek girl and professional code wrangler, but new to Forge.

Link to comment
Share on other sites

You can't use removeEntity - it removes entity, not kills it, therefore server removes it from world but client doesn't know it died - that is your ghost horse probably.

 

You could instead of passing whole oldHorse into newHorse constructor, try only coordinates. Idk really.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Sorry, I should have elaborated more on what I tried, my bad.

 

I did try setting entity.setDead() - same effect.

 

If I simply do setDead OR removeEntity, without trying to create a new one, the entity does just disappear.  So, I feel like I'm doing something wrong in my spawnInWorld, but no idea what.  Also the reason I tried using a cow, to rule out my class.

 

The constructor that takes old horse in, is just to ensure that the new horse gets set to the same type, age, variant, etc.  And position.  I did also try just using the vanilla constructor with no copy from horse - same deal.  I'm really stumped! :(

Geek girl and professional code wrangler, but new to Forge.

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.



×
×
  • Create New...

Important Information

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