Posted September 3, 20205 yr I'm trying to make an entity burn in a certain light level, but I don't know how to get it. Any help would be appreciated.
September 4, 20205 yr If we take a look at a class like AbstractSkeletonEntity, this snippet determines if they should burn: public void livingTick() { boolean flag = this.isInDaylight(); if (flag) { ItemStack itemstack = this.getItemStackFromSlot(EquipmentSlotType.HEAD); if (!itemstack.isEmpty()) { if (itemstack.isDamageable()) { itemstack.setDamage(itemstack.getDamage() + this.rand.nextInt(2)); if (itemstack.getDamage() >= itemstack.getMaxDamage()) { this.sendBreakAnimation(EquipmentSlotType.HEAD); this.setItemStackToSlot(EquipmentSlotType.HEAD, ItemStack.EMPTY); } } flag = false; } if (flag) { this.setFire(8); } } super.livingTick(); } However this also requires we look at isInDaylight() in MobEntity: protected boolean isInDaylight() { if (this.world.isDaytime() && !this.world.isRemote) { float f = this.getBrightness(); BlockPos blockpos = this.getRidingEntity() instanceof BoatEntity ? (new BlockPos(this.getPosX(), (double)Math.round(this.getPosY()), this.getPosZ())).up() : new BlockPos(this.getPosX(), (double)Math.round(this.getPosY()), this.getPosZ()); if (f > 0.5F && this.rand.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && this.world.canSeeSky(blockpos)) { return true; } } return false; } And finally, isDaytime() in World: public boolean isDaytime() { return !this.func_230315_m_().func_241514_p_() && this.skylightSubtracted < 4; } And there's the light level. So altogether you'll need to add code like these three for your entity. Edited September 4, 20205 yr by urbanxx001
September 4, 20205 yr Author I have some code, but it doesn't seem to work: public void livingTick() { if (this.isAlive()) { boolean flag = (this.shouldBurnInDay() && this.isInDaylight()) || this.isInLightLevel(); if (flag) { this.setFire(4); } } super.livingTick(); } protected boolean isInLightLevel() { return world.getLightValue(this.getPosition()) >= 8; } Any help?
September 4, 20205 yr Author I made a LOGGER line, and it keeps reporting as 0, even though there is a torch right next to it.
September 4, 20205 yr Author Thanks, it works now, for the most part. There's still the fire animation in the night though, but it isn't actually taking damage.
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.