public void LightHighlight(BlockPos pos = null) { try { if (!config.LightLevels) { ClearLightLevelHighlights(); return; } colors.Clear(); pos = pos ?? capi.World.Player.Entity.SidedPos.AsBlockPos.UpCopy(); int rad = config.LightRadius; capi.World.BlockAccessor.WalkBlocks(pos.AddCopy(-rad), pos.AddCopy(rad), (block, iPos) => { if (block == null || iPos == null) { return; } BlockPos dPos = pos.SubCopy(iPos); BlockEntityFarmland blockEntityFarmland = capi.World.BlockAccessor.GetBlockEntity(iPos) as BlockEntityFarmland; BlockPos cPos = blockEntityFarmland == null && config.LUShowAbove ? iPos.UpCopy() : iPos; int level = capi.World.BlockAccessor.GetLightLevel(cPos, config.LightLevelType); bool rep = config.LUSpawning ? blockEntityFarmland != null || capi.World.BlockAccessor.GetBlock(iPos.UpCopy()).IsReplacableBy(block) : true; bool opq = config.LUOpaque ? blockEntityFarmland != null || block.AllSidesOpaque : true; if (block.BlockId != 0 && rep && opq && rad.InsideRadius(dPos.X, dPos.Y, dPos.Z)) { int c = 0; float fLevel = level / 32.0f; int alpha = (int)Math.Round(config.LightLevelAlpha * 255); if (config.Nutrients && blockEntityFarmland != null) { int I = config.MXNutrients ? blockEntityFarmland.Nutrients.IndexOf(blockEntityFarmland.Nutrients.Max()) : blockEntityFarmland.Nutrients.IndexOf(blockEntityFarmland.Nutrients.Min()); var nuti = blockEntityFarmland.Nutrients[I]; int scale = (int)((nuti / 50.0f) * 255.0f); switch (I) { case 0: c = ColorUtil.ToRgba(alpha, 0, 0, scale); break; case 1: c = ColorUtil.ToRgba(alpha, 0, scale, 0); break; case 2: c = ColorUtil.ToRgba(alpha, scale, 0, 0); break; default: break; } } else { c = level > config.LightLevelRed ? ColorUtil.ToRgba(alpha, 0, (int)(fLevel * 255), 0) : ColorUtil.ToRgba(alpha, 0, 0, (int)(Math.Max(fLevel, 0.2) * 255)); } colors[iPos.Copy()] = c; } }); if (colors.Count < 1) { ClearLightLevelHighlights(); return; } capi.Event.EnqueueMainThreadTask(() => capi.World.HighlightBlocks(capi.World.Player, config.MinLLID, colors.Keys.ToList(), colors.Values.ToList(), EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary), "addLU"); } catch (Exception) { } }
public static BlockPos RelativeToSpawn(this BlockPos pos, IWorldAccessor world) { return(pos.SubCopy(world.DefaultSpawnPosition.AsBlockPos)); }
/// <summary> /// Gets the position relative to spawn, given an absolute position within the game world. /// </summary> /// <param name="pos">The absolute position of the block being queried.</param> /// <param name="world">The API to use for game world information.</param> public static BlockPos RelativeToSpawn(this BlockPos pos, IWorldAccessor world) { var blockPos = pos.SubCopy(world.DefaultSpawnPosition.XYZ.AsBlockPos); return(new BlockPos(blockPos.X, pos.Y, blockPos.Z)); }