Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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. 

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 by urbanxx001

  • 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?

  • Author

I made a LOGGER line, and it keeps reporting as 0, even though there is a torch right next to it. 

  • 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.

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.