Posted December 8, 201311 yr 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; } }
December 8, 201311 yr Author You seriously need to go and learn the basics of java/OOP. Hm, why not point out what I did wrong?
December 8, 201311 yr Author 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.
December 8, 201311 yr 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.
December 10, 201311 yr Remove the getEntity() method. It is 100% useless. Use the entity instance that is given to you by the event.
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.