Posted November 25, 20177 yr Hello, Trying to work on getting my Deer model to have a specific texture upon spawn. I've worked out how to add into the DataManager, and how to render those multiple textures. However, I am having an issue trying to find out "where" the entity is going to spawn before it spawns. Any direction would be helpful. I've tried getting the Entity's position inside the Entity class, however that always turns out 0. The only time I am able to get the entity's position would be outside entityclass code, meaning the entity had already spawned, and at that point I can't register a DataParamater int to the entity I don't believe. As I said, any help/direction would be appreciated thanks,
November 25, 20177 yr What do you mean by trying to get position "inside Entity class" and "outside Entity class"? The entity has posX, posY and posZ fields which should be accurate. However, they may not be set yet inside the constructor. I think the spawning code first constructs and then sets the position afterwards. Perhaps the easiest way is to handle the EntityJoinWorld event. I'm fairly certain most calls to that set location and angles for the entity before the event is fired. Edited November 25, 20177 yr by jabelar Check out my tutorials here: http://jabelarminecraft.blogspot.com/
November 26, 20177 yr Author 1 hour ago, jabelar said: What do you mean by trying to get position "inside Entity class" and "outside Entity class"? The entity has posX, posY and posZ fields which should be accurate. However, they may not be set yet inside the constructor. I think the spawning code first constructs and then sets the position afterwards. Perhaps the easiest way is to handle the EntityJoinWorld event. I'm fairly certain most calls to that set location and angles for the entity before the event is fired. I'll post a bit of code to explain what's going on. Essentially, inside the Entity class I am attempting to use the DataManager to set it's type based on the Biome in which it spawns in. So: public class EntityDeer extends EntityMob { private static final DataParameter<Integer> int_Type = EntityDataManager.createKey(EntityDeer.class, DataSerializers.VARINT); public EntityDeer(World worldIn) { super(worldIn); this.setSize(1F, 1F); // DataManager // if (this.world.getBiome(getPosition()).equals(Biomes.FOREST)) { // System.out.println("FOREST!"); // System.out.println(getPosition()); // this.getDataManager().register(int_Type, 1); // } Upon setting that information based on which Biome it spawns in, I create a function to pull that data out so the Render can see which is set. public int getType() { if (int_Type != null) { return this.dataManager.get(int_Type); } return 1; } And finally rendering the actual deer. public final ResourceLocation WhiteTail = new ResourceLocation("deerly:animals/deer/deer_whitetail.png"); public final ResourceLocation Elk = new ResourceLocation("deerly:animals/deer/deer_elk.png"); public final ResourceLocation Reindeer = new ResourceLocation("deerly:animals/deer/deer_reindeer.png"); public RenderDeer(RenderManager renderManager) throws IOException { super(renderManager, new TabulaModel(new ModelManager().getContainer("assets/deerly/animals/Deer/Deer.tbl"), new AnimatorDeer()), 1.5F); } @Override protected ResourceLocation getEntityTexture(EntityDeer entity) { EntityDeer deer = (EntityDeer) entity; switch (deer.getType()) { case 1: return WhiteTail; case 2: return Elk; case 3: return Reindeer; } return WhiteTail; } My issue: How can I set the DataParameter inside the Entity class for that spawned entity BEFORE it spawns, whilst knowing the biome it is going to be spawning in. Or, Am I going about this the wrong way, and is there something similar I could be doing?
November 26, 20177 yr If you look at EntityHorse, you'll see that it registers its DataParameters with their default values in its override of Entity#entityInit (called when the entity is constructed, before its position has been set) and then sets their actual values in its override of EntityLiving#onInitialSpawn (called when the entity is first spawned, after its position has been set). You need to do the same thing. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
November 26, 20177 yr Author 3 hours ago, Choonster said: If you look at EntityHorse, you'll see that it registers its DataParameters with their default values in its override of Entity#entityInit (called when the entity is constructed, before its position has been set) and then sets their actual values in its override of EntityLiving#onInitialSpawn (called when the entity is first spawned, after its position has been set). You need to do the same thing. Thank you! I didn't even think of looking at the horses location. I've got it working now. For future reference of those who want to see working code, enjoy: @Override protected void entityInit() { super.entityInit(); this.dataManager.register(int_Type, Integer.valueOf(0)); } @Override public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata) { livingdata = super.onInitialSpawn(difficulty, livingdata); BlockPos pos = this.getPosition(); if (this.world.getBiome(pos).equals(Biomes.FOREST)) { System.out.println("Forest!"); setType(1); } if (this.world.getBiome(pos).equals(Biomes.SWAMPLAND)) { System.out.println("Swampland!"); setType(2); } if (this.world.getBiome(pos).equals(Biomes.TAIGA)) { System.out.println("Taiga!"); setType(3); } else { setType(1); } return livingdata; } public int getType() { return this.dataManager.get(int_Type).intValue(); } public void setType(int variant) { this.dataManager.set(int_Type, variant); }
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.