Posted June 7, 20196 yr I have an entity whose function ingame requires random textures that can be retraced to determine an item drop. (Eg: Has diamond ore texture, thus drops a diamond randomly). Everything seems to be working but sometimes the entity drops the wrong item. After some debugging, it turns out that the getEntityTexture function isn't returning the updated VARIANT variable, although the log clearly states that the VARIANT variable has changed. EntityStinky.class private BlockPos spawnPosition; private int CLOCK; public int VARIANT; private int DELAY; private int BURP_DELAY; private int FART_DELAY; public static Random rand = new Random(); public static final ResourceLocation[] TEXTURES = { new ResourceLocation("spawnore:textures/entity/stinky/stinky0.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky1.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky2.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky3.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky4.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky5.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky6.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky7.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky8.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky9.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky10.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky11.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky12.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky13.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky14.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky15.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky16.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky17.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky18.png") }; public static final ResourceLocation hurt = new ResourceLocation(SpawnOre.MODID + ":mob.stinky.hurt"); public static final SoundEvent HURT_SOUND = new SoundEvent(hurt); public static final ResourceLocation death = new ResourceLocation(SpawnOre.MODID + ":mob.stinky.death"); public static final ResourceLocation fart = new ResourceLocation(SpawnOre.MODID + ":mob.stinky.fart"); public static final SoundEvent FART = new SoundEvent(fart); public EntityStinky(World worldIn) { super(worldIn); setSize(0.7F, 1.35F); this.experienceValue = 5; this.isImmuneToFire = true; this.getAttackStrength(this); setVariant(); this.DELAY = rand.nextInt(2399)+1; this.BURP_DELAY = rand.nextInt(3599)+1; this.FART_DELAY = rand.nextInt(5999)+1; this.CLOCK = 0; } @Nullable @Override public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) { return super.onInitialSpawn(difficulty, livingdata); } public void setVariant() { this.VARIANT = rand.nextInt(18); System.out.println("VARIANT set to " + this.VARIANT); } public int getVariant() { return this.VARIANT; } @Override public void onEntityUpdate() { super.onEntityUpdate(); this.CLOCK++; if (this.CLOCK == this.BURP_DELAY) //Coal Burp { if (!this.world.isRemote) this.dropItem(Items.COAL, 1); //World MUST NOT be Client Side or Ghost Items spawn this.playSound(SoundEvents.ENTITY_PLAYER_BURP, 1.0F, 1.0F); this.BURP_DELAY = rand.nextInt(3599)+this.CLOCK; } if (this.CLOCK == this.FART_DELAY) { if (this.VARIANT == 0) { if (!this.world.isRemote) this.dropItem(xeno.spawnore.init.Items.ITEM_PEACH, 1); } else if (this.VARIANT == 1) { if (!this.world.isRemote) this.dropItem(Items.BLAZE_POWDER, 1); } else if (this.VARIANT == 2) { if (!this.world.isRemote) this.dropItem(Items.ROTTEN_FLESH, 1); } else if (this.VARIANT == 3) { if (!this.world.isRemote) this.dropItem(Items.MELON_SEEDS, 1); } else if (this.VARIANT == 4) { if (!this.world.isRemote) this.dropItem(xeno.spawnore.init.Items.ITEM_URANIUMNUGGET, 1); } else if(this.VARIANT == 5) { if (!this.world.isRemote) this.dropItem(Items.WHEAT, 1); } else if (this.VARIANT == 6) { if (!this.world.isRemote) this.dropItem(Items.BRICK, 1); } else if (this.VARIANT == 7) { if (!this.world.isRemote) this.dropItem(ItemBlock.getItemFromBlock(Blocks.TORCH), 1); } else if (this.VARIANT == 8) { if (!this.world.isRemote) this.dropItem(Items.EMERALD, 1); } else if (this.VARIANT == 9) { if (!this.world.isRemote) this.dropItem(Items.GOLD_INGOT, 1); } else if (this.VARIANT == 10) { if (!this.world.isRemote) this.dropItem(ItemBlock.getItemFromBlock(Blocks.LEAVES), 1); } else if (this.VARIANT == 11) { if (!this.world.isRemote) this.dropItem(xeno.spawnore.init.Items.ITEM_TITANIUMNUGGET, 1); } else if (this.VARIANT == 12) { if (!this.world.isRemote) this.dropItem(Items.APPLE, 1); //Apple Tree Seeds } else if (this.VARIANT == 13) { if (!this.world.isRemote) this.dropItem(Items.DIAMOND, 1); } else if (this.VARIANT == 14) { if (!this.world.isRemote) this.dropItem(ItemBlock.getItemFromBlock(Blocks.SAND), 1); } else if (this.VARIANT == 15) { if (!this.world.isRemote) this.dropItem(ItemBlock.getItemFromBlock(Blocks.COBBLESTONE), 1); } else if (this.VARIANT == 16) { if (!this.world.isRemote) this.dropItem(Items.BONE, 1); } else if (this.VARIANT == 17) { if (!this.world.isRemote) this.dropItem(Items.STRING, 1); } else { if (!this.world.isRemote) this.dropItem(xeno.spawnore.init.Items.ITEM_CHERRY, 1); } this.playSound(FART, 1.0F, 1.5F); this.FART_DELAY = rand.nextInt(5999)+this.CLOCK; } if (this.CLOCK == this.DELAY) //Skin Randomizer { setVariant(); this.DELAY = rand.nextInt(2399)+this.CLOCK; } } RenderStinky.class public static final Factory FACTORY = new Factory(); public RenderStinky(RenderManager rendermanagerIn) { super(rendermanagerIn, new ModelStinky(), 0.5f); } @Override public void doRender(EntityStinky entity, double x, double y, double z, float entityYaw, float partialTicks) { super.doRender(entity, x, y, z, entityYaw, partialTicks); } @Override protected ResourceLocation getEntityTexture(EntityStinky entity) { return TEXTURES[entity.VARIANT]; } public static class Factory implements IRenderFactory<EntityStinky> { @Override public Render<? super EntityStinky> createRenderFor(RenderManager manager) { return new RenderStinky(manager); } } I may or may not know a bit about Java. But if I do, it's probably because of my AP Computer Science textbook...
June 7, 20196 yr Author 40 minutes ago, diesieben07 said: Your entity exists on client and server, with your code both will choose their own random texture independently. You must store the variant in a DataParameter. Look at vanilla entities for examples. I applied a DataParameter and the textures are changing properly now. However, now the getVariant() function is returning the initial registered data value and not the one set by the texture change and as such is only dropping the item of the first texture applied to the entity. private BlockPos spawnPosition; private int CLOCK; private static final DataParameter<Integer> VARIANT = EntityDataManager.createKey(EntityStinky.class, DataSerializers.VARINT); private int DELAY; private int BURP_DELAY; private int FART_DELAY; public static Random rand = new Random(); public static final ResourceLocation[] TEXTURES = { new ResourceLocation("spawnore:textures/entity/stinky/stinky0.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky1.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky2.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky3.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky4.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky5.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky6.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky7.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky8.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky9.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky10.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky11.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky12.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky13.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky14.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky15.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky16.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky17.png"), new ResourceLocation("spawnore:textures/entity/stinky/stinky18.png") }; public static final ResourceLocation hurt = new ResourceLocation(SpawnOre.MODID + ":mob.stinky.hurt"); public static final SoundEvent HURT_SOUND = new SoundEvent(hurt); public static final ResourceLocation death = new ResourceLocation(SpawnOre.MODID + ":mob.stinky.death"); public static final ResourceLocation fart = new ResourceLocation(SpawnOre.MODID + ":mob.stinky.fart"); public static final SoundEvent FART = new SoundEvent(fart); public EntityStinky(World worldIn) { super(worldIn); setSize(0.7F, 1.35F); this.experienceValue = 5; this.isImmuneToFire = true; this.getAttackStrength(this); this.dataManager.register(VARIANT, Integer.valueOf(rand.nextInt(18))); this.DELAY = rand.nextInt(2399)+1; this.BURP_DELAY = rand.nextInt(3599)+1; this.FART_DELAY = rand.nextInt(599)+1; this.CLOCK = 0; } @Nullable @Override public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) { return super.onInitialSpawn(difficulty, livingdata); } public void setVariant() { int id = rand.nextInt(18); this.dataManager.set(VARIANT, id); System.out.println("VARIANT set to " + this.dataManager.get(VARIANT)); } public int getVariant() { return this.dataManager.get(VARIANT); } @Override public void onEntityUpdate() { super.onEntityUpdate(); this.CLOCK++; if (this.CLOCK == this.BURP_DELAY) //Coal Burp { if (!this.world.isRemote) this.dropItem(Items.COAL, 1); //World MUST NOT be Client Side or Ghost Items spawn this.playSound(SoundEvents.ENTITY_PLAYER_BURP, 1.0F, 1.0F); this.BURP_DELAY = rand.nextInt(3599)+this.CLOCK; } if (this.CLOCK == this.FART_DELAY) { if (this.getVariant() == 0) { if (!this.world.isRemote) this.dropItem(xeno.spawnore.init.Items.ITEM_PEACH, 1); } else if (this.getVariant() == 1) { if (!this.world.isRemote) this.dropItem(Items.BLAZE_POWDER, 1); } else if (this.getVariant() == 2) { if (!this.world.isRemote) this.dropItem(Items.ROTTEN_FLESH, 1); } else if (this.getVariant() == 3) { if (!this.world.isRemote) this.dropItem(Items.MELON_SEEDS, 1); } else if (this.getVariant() == 4) { if (!this.world.isRemote) this.dropItem(xeno.spawnore.init.Items.ITEM_URANIUMNUGGET, 1); } else if(this.getVariant() == 5) { if (!this.world.isRemote) this.dropItem(Items.WHEAT, 1); } else if (this.getVariant() == 6) { if (!this.world.isRemote) this.dropItem(Items.BRICK, 1); } else if (this.getVariant() == 7) { if (!this.world.isRemote) this.dropItem(ItemBlock.getItemFromBlock(Blocks.TORCH), 1); } else if (this.getVariant() == 8) { if (!this.world.isRemote) this.dropItem(Items.EMERALD, 1); } else if (this.getVariant() == 9) { if (!this.world.isRemote) this.dropItem(Items.GOLD_INGOT, 1); } else if (this.getVariant() == 10) { if (!this.world.isRemote) this.dropItem(ItemBlock.getItemFromBlock(Blocks.LEAVES), 1); } else if (this.getVariant() == 11) { if (!this.world.isRemote) this.dropItem(xeno.spawnore.init.Items.ITEM_TITANIUMNUGGET, 1); } else if (this.getVariant() == 12) { if (!this.world.isRemote) this.dropItem(Items.APPLE, 1); //Apple Tree Seeds } else if (this.getVariant() == 13) { if (!this.world.isRemote) this.dropItem(Items.DIAMOND, 1); } else if (this.getVariant() == 14) { if (!this.world.isRemote) this.dropItem(ItemBlock.getItemFromBlock(Blocks.SAND), 1); } else if (this.getVariant() == 15) { if (!this.world.isRemote) this.dropItem(ItemBlock.getItemFromBlock(Blocks.COBBLESTONE), 1); } else if (this.getVariant() == 16) { if (!this.world.isRemote) this.dropItem(Items.BONE, 1); } else if (this.getVariant() == 17) { if (!this.world.isRemote) this.dropItem(Items.STRING, 1); } else { if (!this.world.isRemote) this.dropItem(xeno.spawnore.init.Items.ITEM_CHERRY, 1); } this.playSound(FART, 1.0F, 1.5F); this.FART_DELAY = rand.nextInt(599)+this.CLOCK; } if (this.CLOCK == this.DELAY) //Skin Randomizer { setVariant(); this.DELAY = rand.nextInt(2399)+this.CLOCK; } } I may or may not know a bit about Java. But if I do, it's probably because of my AP Computer Science textbook...
June 7, 20196 yr Author Thanks for your help! I simply checked that the world isn't remote before changing the variant in my function and everything works properly! I may or may not know a bit about Java. But if I do, it's probably because of my AP Computer Science textbook...
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.