public object Raycast(Ray3 ray, RaycastMode mode, bool raycastTerrain = true, bool raycastBodies = true, bool raycastMovingBlocks = true) { float reach = (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative) ? SettingsManager.CreativeReach : 5f; Vector3 creaturePosition = ComponentCreature.ComponentCreatureModel.EyePosition; Vector3 start = ray.Position; Vector3 direction = Vector3.Normalize(ray.Direction); Vector3 end = ray.Position + direction * 15f; Point3 startCell = Terrain.ToCell(start); BodyRaycastResult? bodyRaycastResult = m_subsystemBodies.Raycast(start, end, 0.35f, (ComponentBody body, float distance) => (Vector3.DistanceSquared(start + distance * direction, creaturePosition) <= reach * reach && body.Entity != base.Entity && !body.IsChildOfBody(ComponentCreature.ComponentBody) && !ComponentCreature.ComponentBody.IsChildOfBody(body) && Vector3.Dot(Vector3.Normalize(body.BoundingBox.Center() - start), direction) > 0.7f) ? true : false); MovingBlocksRaycastResult?movingBlocksRaycastResult = m_subsystemMovingBlocks.Raycast(start, end, extendToFillCells: true); TerrainRaycastResult? terrainRaycastResult = m_subsystemTerrain.Raycast(start, end, useInteractionBoxes : true, skipAirBlocks : true, delegate(int value, float distance) { if (Vector3.DistanceSquared(start + distance * direction, creaturePosition) <= reach * reach) { Block block = BlocksManager.Blocks[Terrain.ExtractContents(value)]; if (distance == 0f && block is CrossBlock && Vector3.Dot(direction, new Vector3(startCell) + new Vector3(0.5f) - start) < 0f) { return(false); } if (mode == RaycastMode.Digging) { return(!block.IsDiggingTransparent); } if (mode == RaycastMode.Interaction) { if (block.IsPlacementTransparent) { return(block.IsInteractive(m_subsystemTerrain, value)); } return(true); } if (mode == RaycastMode.Gathering) { return(block.IsGatherable); } } return(false); }); float num = bodyRaycastResult.HasValue ? bodyRaycastResult.Value.Distance : float.PositiveInfinity; float num2 = movingBlocksRaycastResult.HasValue ? movingBlocksRaycastResult.Value.Distance : float.PositiveInfinity; float num3 = terrainRaycastResult.HasValue ? terrainRaycastResult.Value.Distance : float.PositiveInfinity; if (num < num2 && num < num3) { return(bodyRaycastResult.Value); } if (num2 < num && num2 < num3) { return(movingBlocksRaycastResult.Value); } if (num3 < num && num3 < num2) { return(terrainRaycastResult.Value); } return(new Ray3(start, direction)); }
public override void MeasureOverride(Vector2 parentAvailableSize) { if (m_inventory != null) { bool flag = m_inventory is ComponentCreativeInventory || m_inventory is ComponentFurnitureInventory; int num = m_inventory.GetSlotCount(m_slotIndex); if (!flag && m_dragMode.HasValue) { num = ((m_dragMode.Value != 0) ? MathUtils.Max(num - 1, 0) : 0); } m_rectangleWidget.IsVisible = true; if (num > 0) { int slotValue = m_inventory.GetSlotValue(m_slotIndex); int num2 = Terrain.ExtractContents(slotValue); Block block = BlocksManager.Blocks[num2]; bool flag2 = block.GetRotPeriod(slotValue) > 0 && block.GetDamage(slotValue) > 0; m_blockIconWidget.Value = Terrain.ReplaceLight(slotValue, 15); m_blockIconWidget.IsVisible = !HideBlockIcon; if (num != m_lastCount) { m_countWidget.Text = num.ToString(); m_lastCount = num; } m_countWidget.IsVisible = (num > 1 && !flag); m_editOverlayWidget.IsVisible = (!HideEditOverlay && block.IsEditable); m_interactiveOverlayWidget.IsVisible = (!HideInteractiveOverlay && ((m_subsystemTerrain != null) ? block.IsInteractive(m_subsystemTerrain, slotValue) : block.DefaultIsInteractive)); m_foodOverlayWidget.IsVisible = (!HideFoodOverlay && block.GetRotPeriod(slotValue) > 0); m_foodOverlayWidget.FillColor = (flag2 ? new Color(128, 64, 0) : new Color(160, 160, 160)); if (!flag && !HideHealthBar && block.Durability >= 0) { int damage = block.GetDamage(slotValue); m_healthBarWidget.IsVisible = true; m_healthBarWidget.Value = (float)(block.Durability - damage) / (float)block.Durability; } else { m_healthBarWidget.IsVisible = false; } } else { m_blockIconWidget.IsVisible = false; m_countWidget.IsVisible = false; m_healthBarWidget.IsVisible = false; m_editOverlayWidget.IsVisible = false; m_interactiveOverlayWidget.IsVisible = false; m_foodOverlayWidget.IsVisible = false; } m_highlightWidget.IsVisible = !HideHighlightRectangle; m_highlightWidget.OutlineColor = Color.Transparent; m_highlightWidget.FillColor = Color.Transparent; m_splitLabelWidget.IsVisible = false; if (m_slotIndex == m_inventory.ActiveSlotIndex) { m_highlightWidget.OutlineColor = new Color(0, 0, 0); m_highlightWidget.FillColor = new Color(0, 0, 0, 80); } if (IsSplitMode()) { m_highlightWidget.OutlineColor = new Color(255, 64, 0); m_splitLabelWidget.IsVisible = true; } } else { m_rectangleWidget.IsVisible = false; m_highlightWidget.IsVisible = false; m_blockIconWidget.IsVisible = false; m_countWidget.IsVisible = false; m_healthBarWidget.IsVisible = false; m_editOverlayWidget.IsVisible = false; m_interactiveOverlayWidget.IsVisible = false; m_foodOverlayWidget.IsVisible = false; m_splitLabelWidget.IsVisible = false; } base.IsDrawRequired = (m_inventoryDragData != null); base.MeasureOverride(parentAvailableSize); }