Jump to content

Recommended Posts

Posted

Hi,

 

I'm creating a single entity but it each spawn of it will be different,  texture, drop etc. Im going to be doing all based on the 'type' of it. Which is just a string. To give each entity a type on spawn, I decided to use the on entity constructing event and then gave the string 'spiderType' a random index of an array I have. Anyway, I get a NPE

EntityOreSpider.getEntity().spiderType = EntityOreSpider.getEntity().spiderTypes[rand.nextInt(EntityOreSpider.getEntity().spiderTypes.length)];

 

And heres the full code.

 

Event Class:

package mcub.helpers;

import java.util.Random;

import mcub.entities.EntityOreSpider;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;

public class ForgeEvents 
{

private Random rand = new Random();

@ForgeSubscribe
public void oreSpiderConstruct(EntityConstructing event)
{
	if(event.entity instanceof EntityOreSpider)
	{
		EntityOreSpider.getEntity().spiderType = EntityOreSpider.getEntity().spiderTypes[rand.nextInt(EntityOreSpider.getEntity().spiderTypes.length)];
		if(EntityOreSpider.getEntity().spiderType == "diamond")
		{
			System.out.println("diamnd");
		}
		else if(EntityOreSpider.getEntity().spiderType == "gold")
		{
			System.out.println("gold");
		}
		else
		{
			System.out.println("null");
		}
	}
}
}

 

Entity Class:

package mcub.entities;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.world.World;

public class EntityOreSpider extends EntitySpider
{

private static EntityOreSpider spider;
public String[] spiderTypes = {"diamond", "gold"};
public String spiderType;
public EntityOreSpider(World world) 
{
	super(world);

}

public static EntityOreSpider getEntity()
{
	return spider;
}

}

Posted

Hm, why not point out what I did wrong?

What is EntityOreSpider.getEntity() supposed to ever return other than null?

Why are the spiderTypes non-static?

Advice taken.

Posted

if(event.entity instanceof EntityOreSpider)
{
    EntityOreSpider entity = event.entity;
   if (entity.getEntity().spiderType() == "diamond")
   {

and so on...

May be wrong since i cant figure out what your getEntity() method does.

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

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.