Skip to content

Commit

Permalink
Add IScriptEntity.getCombinedLight()
Browse files Browse the repository at this point in the history
  • Loading branch information
mchorse committed Sep 8, 2022
1 parent 8adb224 commit cee2a8c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.WorldServer;

public class ScriptEntity <T extends Entity> implements IScriptEntity
Expand Down Expand Up @@ -360,6 +362,21 @@ public int getTicks()
return this.entity.ticksExisted;
}

@Override
public int getCombinedLight()
{
BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(MathHelper.floor(this.entity.posX), 0, MathHelper.floor(this.entity.posZ));

if (this.entity.world.isBlockLoaded(pos))
{
pos.setY(MathHelper.floor(this.entity.posY + this.entity.getEyeHeight()));

return this.entity.world.getCombinedLight(pos, 0);
}

return 0;
}

@Override
public String getName()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@ public ScriptVector(BlockPos pos)
this.y = pos.getY();
this.z = pos.getZ();
}

@Override
public String toString()
{
return "ScriptVector(" + this.x + ", " + this.y + ", " + this.z + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,21 @@ public interface IScriptEntity
*/
public int getTicks();

/**
* Get combined light value of where the entity is currently standing.
* In order to get torch and sky light values separately, see the example below
* to "unpack" the combined value.
*
* <pre>{@code
* var light = c.getPlayer().getCombinedLight();
* var skyLight = light / 65536 / 15;
* var torchLight = light % 65536 / 15;
*
* // Do something with skyLight and torchLight
* }</pre>
*/
public int getCombinedLight();

/**
* Get entity name.
*/
Expand Down

0 comments on commit cee2a8c

Please sign in to comment.