public void LightHighlight(BlockPos pos = null) { try { if (!config.LightLevels) { ClearLightLevelHighlights(); return; } Reset(); pos = pos ?? capi.World.Player.Entity.SidedPos.AsBlockPos.UpCopy(); int rad = config.LightRadius; start.Set(pos.X - rad, pos.Y - rad, pos.Z - rad); end.Set(pos.X + rad, pos.Y + rad, pos.Z + rad); capi.World.BlockAccessor.WalkBlocks(start, end, (block, iPos) => { if (block == null || iPos == null || block.Id == 0) { return; } dPos.Set(pos.X - iPos.X, pos.Y - iPos.Y, pos.Z - iPos.Z); if (!rad.InsideRadius(dPos.X, dPos.Y, dPos.Z)) { return; } BlockEntityFarmland blockEntityFarmland = capi.World.BlockAccessor.GetBlockEntity(iPos) as BlockEntityFarmland; bool abv = blockEntityFarmland == null && config.LUShowAbove; cPos.Set(iPos.X, abv ? iPos.Y + 1 : iPos.Y, iPos.Z); uPos.Set(iPos.X, iPos.Y + 1, iPos.Z); int level = capi.World.BlockAccessor.GetLightLevel(cPos, config.LightLevelType); bool rep = !config.LUSpawning || blockEntityFarmland != null || capi.World.BlockAccessor.GetBlock(uPos).IsReplacableBy(block); bool opq = !config.LUOpaque || blockEntityFarmland != null || block.AllSidesOpaque; if (rep && opq) { 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: tempColor = ColorUtil.ToRgba(alpha, 0, 0, scale); break; case 1: tempColor = ColorUtil.ToRgba(alpha, 0, scale, 0); break; case 2: tempColor = ColorUtil.ToRgba(alpha, scale, 0, 0); break; default: break; } } else { tempColor = level > config.LightLevelRed ? ColorUtil.ToRgba(alpha, 0, (int)(fLevel * 255), 0) : ColorUtil.ToRgba(alpha, 0, 0, (int)(Math.Max(fLevel, 0.2) * 255)); } PushColor(iPos.Copy(), tempColor); } }); if (tempColors.Count < 1) { ClearLightLevelHighlights(); return; } capi.Event.EnqueueMainThreadTask(() => capi.World.HighlightBlocks(capi.World.Player, config.MinLLID, tempPositions.ToList(), tempColors.ToList(), EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Arbitrary), "addLU"); } catch (Exception) { } }
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) { } }