Ejemplo n.º 1
0
 internal void Read(NetIncomingMessage Message)
 {
     if (!Guid.TryParse(Message.ReadString(), out TextureID)) {
         throw new Exception("Failed to parse Guid in FSTextureReference");
     }
     Location = (BlockSide)Message.ReadInt32();
 }
Ejemplo n.º 2
0
        public static Color GetColor(this BlockType type, BlockSide side = BlockSide.None)
        {
            /*if (side != BlockSide.None)
            {
                if (type == BlockType.Grass)
                {
                    if (side != BlockSide.Top) {
                }
            }*/

            return COLORS[(int)type];
        }
Ejemplo n.º 3
0
 public Texture GetTexture(BlockSide Side)
 {
     FSTextureReference Candidate = null;
     do {
         Candidate = Texture.Find(delegate(FSTextureReference obj) { return obj.Location == Side; });
         if (Candidate != null) {
             return Candidate.Texture.Texture;
         } else {
             if (Side == BlockSide.All) {
                 return Textures.ErrorTexture;
             } else if (Side == BlockSide.Side || Side == BlockSide.Top || Side == BlockSide.Bottom) {
                 Side = BlockSide.All;
             } else {
                 Side = BlockSide.Side;
             }
         }
     } while (Candidate != null);
     return Textures.ErrorTexture;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Save the current block state of the given loc.
 /// </summary>
 public void SetLocState(IRailwayState railwayState, ILocState loc, IBlockState currentBlock, BlockSide currentBlockEnterSide, LocDirection currentDirection)
 {
     // Write assignment
     using (var key = Registry.CurrentUser.CreateSubKey(GetKey(loc)))
     {
         key.SetValue(CurrentBlock, (currentBlock != null) ? currentBlock.EntityId : string.Empty);
         key.SetValue(CurrentBlockEnterSide, (currentBlockEnterSide == BlockSide.Back) ? 0 : 1);
         key.SetValue(CurrentDirection, (currentDirection == LocDirection.Forward) ? 0 : 1);
     }
 }
Ejemplo n.º 5
0
 public Color GetColor(BlockSide side = BlockSide.None)
 {
     return Type.GetColor(side);
 }
Ejemplo n.º 6
0
    //funkcja tworzy pojedyncze sciany kostki



    //fukcja generuje wartosci dla mesha
    void GenerateBlockSide(BlockSide side)
    {
        switch (side)
        {
        case BlockSide.FRONT:
            foreach (Vector3 vertex in frontVerticies)
            {
                chunkParent.vertices.Add((blockPosition + vertex));
            }
            break;

        case BlockSide.BACK:
            foreach (Vector3 vertex in backVerticies)
            {
                chunkParent.vertices.Add((blockPosition + vertex));
            }
            break;

        case BlockSide.LEFT:
            foreach (Vector3 vertex in leftVerticies)
            {
                chunkParent.vertices.Add((blockPosition + vertex));
            }
            break;

        case BlockSide.RIGHT:
            foreach (Vector3 vertex in rightVerticies)
            {
                chunkParent.vertices.Add((blockPosition + vertex));
            }
            break;

        case BlockSide.TOP:
            foreach (Vector3 vertex in topVerticies)
            {
                chunkParent.vertices.Add((blockPosition + vertex));
            }
            break;

        case BlockSide.BOTTOM:
            foreach (Vector3 vertex in bottomVerticies)
            {
                chunkParent.vertices.Add((blockPosition + vertex));
            }
            break;
        }

        foreach (Vector2 blockUV in blockType.GetBlockUVs(side))
        {
            chunkParent.uvs.Add(blockUV);
        }

        foreach (int triangle in triangles)
        {
            if (this.blockType.isLiquid())
            {
                chunkParent.waterTriangles.Add(chunkParent.VertexIndex + triangle);
            }

            else if (this.blockType.isTransparent || this.blockType.isTransluent)
            {
                chunkParent.transparentTriangles.Add(chunkParent.VertexIndex + triangle);
            }
            else
            {
                chunkParent.triangles.Add(chunkParent.VertexIndex + triangle);
            }
        }



        chunkParent.VertexIndex += 4;
    }
 /// <summary>
 /// Default ctor
 /// </summary>
 public BlockAndSide(IRouteState route)
 {
     block     = route.To;
     enterSide = route.ToBlockSide;
 }
Ejemplo n.º 8
0
 /// <summary>
 ///     This method is called on blocks next to a position that was changed.
 /// </summary>
 /// <param name="world">The containing world.</param>
 /// <param name="position">The block position.</param>
 /// <param name="data">The data of the block next to the changed position.</param>
 /// <param name="side">The side of the block where the change happened.</param>
 public virtual void BlockUpdate(World world, Vector3i position, uint data, BlockSide side) {}
Ejemplo n.º 9
0
        public override string GetTextureForSide(BlockSide side, byte metadata)
        {
            int i = BitHelper.Help(metadata, 5, 3);

            switch (i)
            {
                case 0:
                    return "planks_oak";
                case 1:
                    return "planks_spruce";
                case 2:
                    return "planks_birch";
                case 3:
                    return "planks_jungle";
            }

            return "stone";
        }
Ejemplo n.º 10
0
        public override List<CustomBlockData> GenerateSide(BlockSide side, byte metadata, BlockData me, BlockData Xpos, BlockData Xneg, BlockData Ypos, BlockData Yneg, BlockData Zpos, BlockData Zneg)
        {
            List<CustomBlockData> s = new List<CustomBlockData>();

            float level = CalculateLevel(me);

            if (side == BlockSide.Ypos)
            {
                s.Add(new CustomBlockData()
                {
                    Vertex1 = new Vector3(0, level, 0),
                    Vertex2 = new Vector3(1, level, 0),
                    Vertex3 = new Vector3(1, level, 1),
                    Vertex4 = new Vector3(0, level, 1),

                    Normal = new Vector3(0, 1, 0),

                    Texture = _tex
                }.CreateUVs());
            }
            if (side == BlockSide.Yneg)
            {
                s.Add(new CustomBlockData()
                {
                    Vertex1 = new Vector3(0, 0, 0),
                    Vertex2 = new Vector3(1, 0, 0),
                    Vertex3 = new Vector3(1, 0, 1),
                    Vertex4 = new Vector3(0, 0, 1),

                    TriFlip = true,

                    Normal = new Vector3(0, 1, 0),

                    Texture = _tex
                }.CreateUVs());
            }

            if (side == BlockSide.Xpos)
            {
                float xpl = level;
                if (Xpos.ID == 8 || Xpos.ID == 9)
                {
                    xpl = CalculateLevel(Xpos);

                    s.Add(new CustomBlockData()
                    {
                        Vertex1 = new Vector3(1, level, 1),
                        Vertex2 = new Vector3(1, level, 0),
                        Vertex3 = new Vector3(1, xpl, 0),
                        Vertex4 = new Vector3(1, xpl, 1),

                        UV1 = new Vector2(0, xpl),
                        UV2 = new Vector2(1, xpl),
                        UV3 = new Vector2(1, level),
                        UV4 = new Vector2(0, level),

                        Normal = new Vector3(1, 0, 0),

                        Texture = _tex
                    });
                }
                else
                {
                    s.Add(new CustomBlockData()
                    {
                        Vertex1 = new Vector3(1, xpl, 1),
                        Vertex2 = new Vector3(1, xpl, 0),
                        Vertex3 = new Vector3(1, 0, 0),
                        Vertex4 = new Vector3(1, 0, 1),

                        UV1 = new Vector2(0, xpl),
                        UV2 = new Vector2(1, xpl),
                        UV3 = new Vector2(1, 0),
                        UV4 = new Vector2(0, 0),

                        Normal = new Vector3(1, 0, 0),

                        Texture = _tex
                    });
                }
            }

            if (side == BlockSide.Xneg)
            {
                float xpl = level;
                if (Xneg.ID == 8 || Xneg.ID == 9)
                {
                    xpl = CalculateLevel(Xneg);

                    s.Add(new CustomBlockData()
                    {
                        Vertex1 = new Vector3(0, level, 1),
                        Vertex2 = new Vector3(0, level, 0),
                        Vertex3 = new Vector3(0, xpl, 0),
                        Vertex4 = new Vector3(0, xpl, 1),

                        UV1 = new Vector2(0, xpl),
                        UV2 = new Vector2(1, xpl),
                        UV3 = new Vector2(1, level),
                        UV4 = new Vector2(0, level),

                        Normal = new Vector3(-1, 0, 0),

                        Texture = _tex
                    });
                }
                else
                {
                    s.Add(new CustomBlockData()
                    {
                        Vertex1 = new Vector3(0, xpl, 1),
                        Vertex2 = new Vector3(0, xpl, 0),
                        Vertex3 = new Vector3(0, 0, 0),
                        Vertex4 = new Vector3(0, 0, 1),

                        UV1 = new Vector2(0, xpl),
                        UV2 = new Vector2(1, xpl),
                        UV3 = new Vector2(1, 0),
                        UV4 = new Vector2(0, 0),

                        Normal = new Vector3(-1, 0, 0),

                        Texture = _tex
                    });
                }
            }

            if (side == BlockSide.Zpos)
            {
                float xpl = level;
                if (Zpos.ID == 8 || Zpos.ID == 9)
                {
                    xpl = CalculateLevel(Zpos);

                    s.Add(new CustomBlockData()
                    {
                        Vertex1 = new Vector3(1, level, 1),
                        Vertex2 = new Vector3(0, level, 1),
                        Vertex3 = new Vector3(0, xpl, 1),
                        Vertex4 = new Vector3(1, xpl, 1),

                        UV1 = new Vector2(0, xpl),
                        UV2 = new Vector2(1, xpl),
                        UV3 = new Vector2(1, level),
                        UV4 = new Vector2(0, level),

                        Normal = new Vector3(0, 0, 1),

                        Texture = _tex
                    });
                }
                else
                {
                    s.Add(new CustomBlockData()
                    {
                        Vertex1 = new Vector3(1, xpl, 1),
                        Vertex2 = new Vector3(0, xpl, 1),
                        Vertex3 = new Vector3(0, 0, 1),
                        Vertex4 = new Vector3(1, 0, 1),

                        UV1 = new Vector2(0, xpl),
                        UV2 = new Vector2(1, xpl),
                        UV3 = new Vector2(1, 0),
                        UV4 = new Vector2(0, 0),

                        Normal = new Vector3(0, 0, 1),

                        Texture = _tex
                    });
                }
            }

            if (side == BlockSide.Zneg)
            {
                float xpl = level;
                if (Zneg.ID == 8 || Zneg.ID == 9)
                {
                    xpl = CalculateLevel(Zneg);

                    s.Add(new CustomBlockData()
                    {
                        Vertex1 = new Vector3(1, level, 0),
                        Vertex2 = new Vector3(0, level, 0),
                        Vertex3 = new Vector3(0, xpl, 0),
                        Vertex4 = new Vector3(1, xpl, 0),

                        UV1 = new Vector2(0, xpl),
                        UV2 = new Vector2(1, xpl),
                        UV3 = new Vector2(1, level),
                        UV4 = new Vector2(0, level),

                        Normal = new Vector3(0, 0, -1),

                        Texture = _tex
                    });
                }
                else
                {
                    s.Add(new CustomBlockData()
                    {
                        Vertex1 = new Vector3(1, xpl, 0),
                        Vertex2 = new Vector3(0, xpl, 0),
                        Vertex3 = new Vector3(0, 0, 0),
                        Vertex4 = new Vector3(1, 0, 0),

                        UV1 = new Vector2(0, xpl),
                        UV2 = new Vector2(1, xpl),
                        UV3 = new Vector2(1, 0),
                        UV4 = new Vector2(0, 0),

                        Normal = new Vector3(0, 0, -1),

                        Texture = _tex
                    });
                }
            }

            return s;
        }
Ejemplo n.º 11
0
 /// <inheritdoc />
 public bool AllowInflow(World world, Vector3i position, BlockSide side, Liquid liquid)
 {
     return(liquid.Viscosity < 100);
 }
Ejemplo n.º 12
0
        private static bool CastVoxel(Ray ray, out Vector3i hit, out BlockSide side,
                                      Func <Ray, Vector3i, bool> rayIntersectionCheck)
        {
            /*
             * Voxel Traversal Algorithm
             * Adapted from code by francisengelmann (https://github.com/francisengelmann/fast_voxel_traversal)
             * See: J. Amanatides and A. Woo, A Fast Voxel Traversal Algorithm for Ray Tracing, Eurographics, 1987.
             */

            // Calculate the direction of the ray with length
            Vector3 direction = ray.Direction;

            // Get the origin position in world coordinates.
            var x = (int)Math.Floor(ray.Origin.X);
            var y = (int)Math.Floor(ray.Origin.Y);
            var z = (int)Math.Floor(ray.Origin.Z);

            // Get the end position in world coordinates.
            var endX = (int)Math.Floor(ray.EndPoint.X);
            var endY = (int)Math.Floor(ray.EndPoint.Y);
            var endZ = (int)Math.Floor(ray.EndPoint.Z);

            // Get the direction in which the components are incremented.
            int stepX = Math.Sign(direction.X);
            int stepY = Math.Sign(direction.Y);
            int stepZ = Math.Sign(direction.Z);

            // Calculate the distance to the next voxel border from the current position.
            double nextVoxelBoundaryX = stepX > 0 ? x + stepX : x;
            double nextVoxelBoundaryY = stepY > 0 ? y + stepY : y;
            double nextVoxelBoundaryZ = stepZ > 0 ? z + stepZ : z;

            // Calculate the distance to the next voxel border.
            double tMaxX = direction.X != 0 ? (nextVoxelBoundaryX - ray.Origin.X) / direction.X : double.MaxValue;
            double tMaxY = direction.Y != 0 ? (nextVoxelBoundaryY - ray.Origin.Y) / direction.Y : double.MaxValue;
            double tMaxZ = direction.Z != 0 ? (nextVoxelBoundaryZ - ray.Origin.Z) / direction.Z : double.MaxValue;

            // Calculate distance so component equals voxel border.
            double tDeltaX = direction.X != 0 ? stepX / direction.X : double.MaxValue;
            double tDeltaY = direction.Y != 0 ? stepY / direction.Y : double.MaxValue;
            double tDeltaZ = direction.Z != 0 ? stepZ / direction.Z : double.MaxValue;

            // Check if the ray intersects the bounding box of the voxel.
            if (rayIntersectionCheck(ray, (x, y, z)))
            {
                hit = (x, y, z);

                // As the ray starts in this voxel, no side is selected.
                side = BlockSide.All;

                return(true);
            }

            while (!(x == endX && y == endY && z == endZ))
            {
                if (tMaxX < tMaxY)
                {
                    if (tMaxX < tMaxZ)
                    {
                        x     += stepX;
                        tMaxX += tDeltaX;

                        side = stepX > 0 ? BlockSide.Left : BlockSide.Right;
                    }
                    else
                    {
                        z     += stepZ;
                        tMaxZ += tDeltaZ;

                        side = stepZ > 0 ? BlockSide.Back : BlockSide.Front;
                    }
                }
                else
                {
                    if (tMaxY < tMaxZ)
                    {
                        y     += stepY;
                        tMaxY += tDeltaY;

                        side = stepY > 0 ? BlockSide.Bottom : BlockSide.Top;
                    }
                    else
                    {
                        z     += stepZ;
                        tMaxZ += tDeltaZ;

                        side = stepZ > 0 ? BlockSide.Back : BlockSide.Front;
                    }
                }

                // Check if the ray intersects the bounding box of the block
                if (rayIntersectionCheck(ray, (x, y, z)))
                {
                    hit = (x, y, z);

                    return(true);
                }
            }

            hit  = (-1, -1, -1);
            side = BlockSide.All;

            return(false);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Find all route sequences that lead from the given side of the given "from" block to the given "to" block.
        /// </summary>
        public static IEnumerable <IRouteSequence> FindRouteSequences(IBlockState fromBlock, BlockSide fromBlockEnterSide, IBlockState toBlock)
        {
            var railway            = fromBlock.RailwayState;
            var fromBlockLeaveSide = fromBlockEnterSide.Invert();
            var startRoutes        = railway.RouteStates.Where(x => (x.From == fromBlock) && (x.FromBlockSide == fromBlockLeaveSide)).ToList();
            var initialSequences   = startRoutes.Select(x => new RouteSequence(x));

            return(FindRouteSequences(initialSequences, railway, toBlock, railway.RouteStates.Count));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Select one of the given possible routes.
        /// Returns null if no route should be taken.
        /// </summary>
        /// <param name="possibleRoutes">A list of routes to choose from</param>
        /// <param name="loc">The loc to choose for</param>
        /// <param name="fromBlock">The block from which the next route will leave</param>
        /// <param name="locDirection">The direction the loc is facing in the <see cref="fromBlock"/>.</param>
        public IRouteState SelectRoute(IList <IRouteState> possibleRoutes, ILocState loc, IBlockState fromBlock, BlockSide locDirection)
        {
            // Look for a direct match
            var directRoutes = possibleRoutes.Where(x => x.To == targetBlock).ToList();

            if (directRoutes.Any())
            {
                return(new DefaultRouteSelector().SelectRoute(directRoutes, loc, fromBlock, locDirection));
            }

            // Look for routes that get us closer to the target block.
            var sequences = FindRouteSequences(fromBlock, locDirection.Invert(), targetBlock).ToList();

            // Filter sequences to start with possible routes
            var possibleSequences = sequences.Where(x => possibleRoutes.Contains(x.First)).OrderBy(x => x.Length).ToList();

            // Any sequences left?
            if (possibleSequences.Count == 0)
            {
                return(null);
            }

            // Take the first possible sequence.
            return(possibleSequences[0].First);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Try to assign the given loc to the given block.
 /// Assigning is only possible when the loc is not controlled automatically and
 /// the block can be assigned by the given loc.
 /// If the loc is already assigned to another block, this assignment is removed
 /// and the block on that block is unlocked.
 /// </summary>
 /// <param name="block">The new block to assign to. If null, the loc will only be unassigned from the current block.</param>
 /// <param name="currentBlockEnterSide">The site to which the block is entered (invert of facing)</param>
 /// <returns>True on success, false otherwise</returns>
 public bool AssignTo(IBlockState block, BlockSide currentBlockEnterSide)
 {
     return(RailwayState.Dispatcher.PostActionAndWait(() => OnAssignTo(block, currentBlockEnterSide)));
 }
Ejemplo n.º 16
0
        public override List<CustomBlockData> GenerateSide(BlockSide side, byte metadata, BlockData me, BlockData Xpos, BlockData Xneg, BlockData Ypos, BlockData Yneg, BlockData Zpos, BlockData Zneg)
        {
            List<CustomBlockData> bd = new List<CustomBlockData>();

            switch (side)
            {
                case BlockSide.Xneg:
                    bd.Add(new CustomBlockData()
                    {
                        Vertex1 = new Vector3(0, 0, 0),
                        Vertex2 = new Vector3(0, _height, 0),
                        Vertex3 = new Vector3(0, _height, 1),
                        Vertex4 = new Vector3(0, 0, 1),

                        Normal = new Vector3(-1, 0, 0),
                        Texture = "dirt",

                        TriFlip = true
                    }.CreateUVs(0, 0, 1, _height));
                    break;
                case BlockSide.Xpos:
                    bd.Add(new CustomBlockData()
                    {
                        Vertex1 = new Vector3(1, 0, 0),
                        Vertex2 = new Vector3(1, _height, 0),
                        Vertex3 = new Vector3(1, _height, 1),
                        Vertex4 = new Vector3(1, 0, 1),

                        Normal = new Vector3(1, 0, 0),
                        Texture = "dirt",

                        TriFlip = true
                    }.CreateUVs(0, 0, 1, _height));
                    break;

                case BlockSide.Zneg:
                    bd.Add(new CustomBlockData()
                    {
                        Vertex1 = new Vector3(0, 0, 0),
                        Vertex2 = new Vector3(0, _height, 0),
                        Vertex3 = new Vector3(1, _height, 0),
                        Vertex4 = new Vector3(1, 0, 0),

                        Normal = new Vector3(0, 0, -1),
                        Texture = "dirt",

                        TriFlip = true
                    }.CreateUVs(0, 0, 1, _height));
                    break;
                case BlockSide.Zpos:
                    bd.Add(new CustomBlockData()
                    {
                        Vertex1 = new Vector3(0, 0, 1),
                        Vertex2 = new Vector3(0, _height, 1),
                        Vertex3 = new Vector3(1, _height, 1),
                        Vertex4 = new Vector3(1, 0, 1),

                        Normal = new Vector3(0, 0, 1),
                        Texture = "dirt",

                        TriFlip = true
                    }.CreateUVs(0, 0, 1, _height));
                    break;

                case BlockSide.Ypos:
                    bd.Add(new CustomBlockData()
                    {
                        Vertex1 = new Vector3(0, _height, 0),
                        Vertex2 = new Vector3(1, _height, 0),
                        Vertex3 = new Vector3(1, _height, 1),
                        Vertex4 = new Vector3(0, _height, 1),

                        Normal = new Vector3(0, 1, 0),
                        Texture = GetTextureForSide(BlockSide.Ypos, metadata),
                    }.CreateUVs(0, 0, 1, _height));
                    break;
            }

            return bd;
        }
Ejemplo n.º 17
0
 public override bool IsFullSide(BlockSide side)
 {
     return false;
 }
Ejemplo n.º 18
0
 public override string GetTextureForSide(BlockSide side, byte metadata)
 {
     byte type = GetId(metadata);
     return _tex.GetTexturesForMetadata(type)[Block.GetSideInt(side)];
 }
Ejemplo n.º 19
0
        public override string GetTextureForSide(BlockSide side, byte metadata)
        {
            if (side == BlockSide.Yneg || side == BlockSide.Ypos)
                return _textureY;

            return _texture;
        }
Ejemplo n.º 20
0
 /// <summary>
 ///     Create a new <see cref="MeshFaceHolder" />
 /// </summary>
 /// <param name="side">The block side to target.</param>
 protected MeshFaceHolder(BlockSide side)
 {
     this.side = side;
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Can the given route be taken by the given loc?
        /// </summary>
        /// <param name="route">The route being investigated</param>
        /// <param name="loc">The loc a route should be choosen for</param>
        /// <param name="locDirection">The direction the loc is facing in the From block of the given <see cref="route"/>.</param>
        /// <param name="avoidDirectionChanges">If true, the route is considered not available if a direction change is needed.</param>
        /// <param name="generationDelta">If larger than 0, look this number of generation less far in the future.</param>
        /// <returns>True if the route can be locked and no sensor in the route is active (outside current route).</returns>
        public virtual IRouteOption IsAvailableFor(IRouteState route, ILocState loc, BlockSide locDirection, bool avoidDirectionChanges, int generationDelta)
        {
            ILocState lockedBy;

            if (!CanLock(route, loc, out lockedBy))
            {
                // Cannot lock
                return(new RouteOption(route, RouteImpossibleReason.Locked, (lockedBy != null) ? lockedBy.Description : "?"));
            }

            // Route closed?
            if (route.Closed)
            {
                // Route closed
                return(new RouteOption(route, RouteImpossibleReason.Closed));
            }

            // Target blocked closed?
            if (route.To.Closed.Actual || route.To.Closed.Requested)
            {
                // Destination closed.
                return(new RouteOption(route, RouteImpossibleReason.DestinationClosed));
            }

            // Check opposite traffic
            IBlockState blockContainingTraffic;
            var         maxSteps = Math.Max(1, railwayState.BlockStates.Count - generationDelta);

            if (HasTrafficInOppositeDirection(route, loc, maxSteps, out blockContainingTraffic))
            {
                // Traffic in opposite direction found
                return(new RouteOption(route, RouteImpossibleReason.OpposingTraffic, blockContainingTraffic.Description));
            }

            // Check critical section of route
            if (!IsCriticalSectionFree(route, loc))
            {
                // Some route in critical section not free
                return(new RouteOption(route, RouteImpossibleReason.CriticalSectionOccupied));
            }

            // Check direction
            if (route.IsDirectionChangeNeeded(locDirection))
            {
                if (avoidDirectionChanges)
                {
                    // Do not take this route because a direction change would be needed.
                    return(new RouteOption(route, RouteImpossibleReason.DirectionChangeNeeded));
                }
                if (loc.ChangeDirection != ChangeDirection.Allow)
                {
                    // Loc does not allow direction changes
                    if (!route.From.IsDeadEnd)
                    {
                        return(new RouteOption(route, RouteImpossibleReason.DirectionChangeNeeded));
                    }
                    // Loc will reverse out of a dead end
                }
                if (route.From.ChangeDirection != ChangeDirection.Allow)
                {
                    // From block does not allowed direction changes
                    return(new RouteOption(route, RouteImpossibleReason.DirectionChangeNeeded));
                }
            }

            // Check permissions
            if (!route.Permissions.Evaluate(loc))
            {
                // Loc not allowed by permissions
                return(new RouteOption(route, RouteImpossibleReason.NoPermission));
            }

            // Check sensor states
            if (IsAnySensorActive(route, loc))
            {
                // Route is not available
                return(new RouteOption(route, RouteImpossibleReason.SensorActive));
            }

            // Route is available
            return(new RouteOption(route, true, RouteImpossibleReason.None));
        }
Ejemplo n.º 22
0
    //Funkcja generuje wartości Mesha na podstawie strony ściany kostki
    Mesh GenerateBlockSide(Mesh mesh, BlockSide side)
    {
        switch (side)
        {
        case BlockSide.FRONT:
            mesh.vertices = new Vector3[] { vertices[4], vertices[5], vertices[1], vertices[0] };

            mesh.normals = new Vector3[] { Vector3.forward, Vector3.forward, Vector3.forward, Vector3.forward };

            mesh.uv = new Vector2[] { uv[3], uv[2], uv[0], uv[1] };

            mesh.triangles = new int[] { 3, 1, 0, 3, 2, 1 };
            break;

        case BlockSide.BACK:
            mesh.vertices = new Vector3[] { vertices[6], vertices[7], vertices[3], vertices[2] };

            mesh.normals = new Vector3[] { Vector3.back, Vector3.back, Vector3.back, Vector3.back };

            mesh.uv = new Vector2[] { uv[3], uv[2], uv[0], uv[1] };

            mesh.triangles = new int[] { 3, 1, 0, 3, 2, 1 };
            break;

        case BlockSide.LEFT:
            mesh.vertices = new Vector3[] { vertices[7], vertices[4], vertices[0], vertices[3] };

            mesh.normals = new Vector3[] { Vector3.left, Vector3.left, Vector3.left, Vector3.left };

            mesh.uv = new Vector2[] { uv[3], uv[2], uv[0], uv[1] };

            mesh.triangles = new int[] { 3, 1, 0, 3, 2, 1 };
            break;

        case BlockSide.RIGHT:
            mesh.vertices = new Vector3[] { vertices[5], vertices[6], vertices[2], vertices[1] };

            mesh.normals = new Vector3[] { Vector3.right, Vector3.right, Vector3.right, Vector3.right };

            mesh.uv = new Vector2[] { uv[3], uv[2], uv[0], uv[1] };

            mesh.triangles = new int[] { 3, 1, 0, 3, 2, 1 };
            break;

        case BlockSide.TOP:
            mesh.vertices = new Vector3[] { vertices[7], vertices[6], vertices[5], vertices[4] };

            mesh.normals = new Vector3[] { Vector3.up, Vector3.up, Vector3.up, Vector3.up };

            mesh.uv = new Vector2[] { uv[3], uv[2], uv[0], uv[1] };

            mesh.triangles = new int[] { 3, 1, 0, 3, 2, 1 };
            break;

        case BlockSide.BOTTOM:
            mesh.vertices = new Vector3[] { vertices[0], vertices[1], vertices[2], vertices[3] };

            mesh.normals = new Vector3[] { Vector3.down, Vector3.down, Vector3.down, Vector3.down };

            mesh.uv = new Vector2[] { uv[3], uv[2], uv[0], uv[1] };

            mesh.triangles = new int[] { 3, 1, 0, 3, 2, 1 };
            break;
        }
        return(mesh);
    }
 /// <summary>
 /// Are there any routes leading to the given block that enter the to block
 /// at the given to side?
 /// </summary>
 private bool AnyRoutesTo(IBlockState toBlock, BlockSide toSide)
 {
     return(railway.RouteStates.Any(x => (x.To == toBlock) && (x.ToBlockSide == toSide)));
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 public LocState(IBlockState currentBlock, BlockSide currentBlockEnterSide)
 {
     this.currentBlock          = currentBlock;
     this.currentBlockEnterSide = currentBlockEnterSide;
 }
 /// <summary>
 /// Create a list of blocks reachable from the given block.
 /// </summary>
 private List <BlockAndSide> GetNextBlocks(IBlockState fromBlock, BlockSide fromSide)
 {
     return(railway.RouteStates.Where(x => (x.From == fromBlock) && (x.FromBlockSide == fromSide)).Select(x => new BlockAndSide(x)).ToList());
 }
 /// <summary>
 /// Copy ctor
 /// </summary>
 public LocState(LocState source)
 {
     currentBlock          = source.currentBlock;
     currentBlockEnterSide = source.currentBlockEnterSide;
 }
Ejemplo n.º 27
0
    //funkcja sprawdza czy sasiednia kosta jest przesroczysta
    bool HasTransparentNeighbour(BlockSide blockSide)
    {
        Vector3 neighbourPosition = new Vector3(0, 0, 0);

        if (blockSide == BlockSide.FRONT)
        {
            neighbourPosition = new Vector3(blockPosition.x, blockPosition.y, blockPosition.z + 1);
        }
        else if (blockSide == BlockSide.BACK)
        {
            neighbourPosition = new Vector3(blockPosition.x, blockPosition.y, blockPosition.z - 1);
        }
        else if (blockSide == BlockSide.TOP)
        {
            neighbourPosition = new Vector3(blockPosition.x, blockPosition.y + 1, blockPosition.z);
        }
        else if (blockSide == BlockSide.BOTTOM)
        {
            neighbourPosition = new Vector3(blockPosition.x, blockPosition.y - 1, blockPosition.z);
        }
        else if (blockSide == BlockSide.RIGHT)
        {
            neighbourPosition = new Vector3(blockPosition.x + 1, blockPosition.y, blockPosition.z);
        }
        else if (blockSide == BlockSide.LEFT)
        {
            neighbourPosition = new Vector3(blockPosition.x - 1, blockPosition.y, blockPosition.z);
        }

        Block[,,] chunkBlocks = chunkParent.chunkBlocks;

        if (neighbourPosition.x < 0 || neighbourPosition.x >= World.chunkSize ||
            neighbourPosition.y < 0 || neighbourPosition.y >= World.chunkSize ||
            neighbourPosition.z < 0 || neighbourPosition.z >= World.chunkSize)
        {
            Vector3 neighbourChunkPosition = this.chunkParent.chunkObject.transform.position;
            neighbourChunkPosition.x += (neighbourPosition.x - blockPosition.x) * World.chunkSize;
            neighbourChunkPosition.y += (neighbourPosition.y - blockPosition.y) * World.chunkSize;
            neighbourChunkPosition.z += (neighbourPosition.z - blockPosition.z) * World.chunkSize;

            string neighbourChunkName = World.GenerateChunkName(neighbourChunkPosition);

            Chunk neighbourChunk;

            if (World.chunks.TryGetValue(neighbourChunkName, out neighbourChunk))
            {
                chunkBlocks = neighbourChunk.chunkBlocks;
            }
            else
            {
                return(true);
            }
        }

        if (neighbourPosition.x < 0)
        {
            neighbourPosition.x = World.chunkSize - 1;
        }
        if (neighbourPosition.y < 0)
        {
            neighbourPosition.y = World.chunkSize - 1;
        }
        if (neighbourPosition.z < 0)
        {
            neighbourPosition.z = World.chunkSize - 1;
        }
        if (neighbourPosition.x >= World.chunkSize)
        {
            neighbourPosition.x = 0;
        }
        if (neighbourPosition.y >= World.chunkSize)
        {
            neighbourPosition.y = 0;
        }
        if (neighbourPosition.z >= World.chunkSize)
        {
            neighbourPosition.z = 0;
        }

        var neighbourBlockType = chunkBlocks[(int)neighbourPosition.x, (int)neighbourPosition.y, (int)neighbourPosition.z].blockType;

        if (this.blockType.isTransluent && neighbourBlockType.isTransluent && !neighbourBlockType.isTransparent)
        {
            return(false);
        }

        return(neighbourBlockType.isTransparent || neighbourBlockType.isTransluent);
    }
 public void ChangeTo(IBlockState currentBlock, BlockSide currentBlockEnterSide)
 {
     this.currentBlock          = currentBlock;
     this.currentBlockEnterSide = currentBlockEnterSide;
 }
Ejemplo n.º 29
0
        /// <summary>
        ///     Provides an enumerable that contains all actual blocks sides, meaning not the side <c>All</c>.
        /// </summary>
        /// <param name="side">Must be the block side <c>All</c>.</param>
        /// <returns>The block side enumerable.</returns>
        public static IEnumerable <BlockSide> Sides(this BlockSide side)
        {
            Debug.Assert(side == BlockSide.All);

            return(sides);
        }
Ejemplo n.º 30
0
        public override string GetTextureForSide(BlockSide side, byte metadata)
        {
            int i = BitHelper.Help(metadata, 5, 3);

            //bool top = BitHelper.IsBitSet(metadata, 4);

            if (i == 0 && (side == BlockSide.Ypos || side == BlockSide.Yneg))
                return "stone_slab_top";
            if (i == 1 && (side == BlockSide.Ypos || side == BlockSide.Yneg))
                return "sandstone_top";

            switch (i)
            {
                case 0:
                    return "stone_slab_side";
                case 1:
                    return "sandstone_normal";
                case 2:
                    return "planks_oak";
                case 3:
                    return "cobblestone";
                case 4:
                    return "brick";
                case 5:
                    return "stonebrick";
                case 6:
                    return "nether_brick";
                case 7:
                    return "quartz_block_side";
            }

            return "stone";
        }
Ejemplo n.º 31
0
        public override string GetTextureForSide(BlockSide side, byte metadata)
        {
            if (side == BlockSide.Ypos)
                return (metadata == 7 ? "farmland_wet" : "farmland_dry");

            return "dirt";
        }
Ejemplo n.º 32
0
 public virtual bool CanGenerateSide(BlockSide side, byte metadata)
 {
     return true;
 }
Ejemplo n.º 33
0
 public override string GetTextureForSide(BlockSide side, byte metadata)
 {
     return _tex;
 }
Ejemplo n.º 34
0
 public virtual List<CustomBlockData> GenerateSide(BlockSide side, byte metadata, BlockData me, BlockData Xpos, BlockData Xneg, BlockData Ypos, BlockData Yneg, BlockData Zpos, BlockData Zneg)
 {
     return new List<CustomBlockData>();
 }
Ejemplo n.º 35
0
        public override bool CanGenerateSide(BlockSide side, byte metadata)
        {
            bool[] bits = BitHelper.GetBits(metadata);

            return base.CanGenerateSide(side, metadata);
        }
Ejemplo n.º 36
0
 public virtual string GetTextureForSide(BlockSide side, byte metadata)
 {
     return texture[GetSideInt(side)];
 }
Ejemplo n.º 37
0
 public override string GetTextureForSide(BlockSide side, byte metadata)
 {
     return "fire_layer_0";
 }
Ejemplo n.º 38
0
 public virtual bool IsFullSide(BlockSide side)
 {
     return true;
 }
Ejemplo n.º 39
0
        public override string GetTextureForSide(BlockSide side, byte metadata)
        {
            bool[] bits = BitHelper.GetBits(metadata);
            bool on = bits[0];

            if (ID == 27)
                return "rail_golden" + (on ? "_powered" : "");
            if(ID == 28)
                return "rail_detector" + (on ? "_powered" : "");
            if (ID == 157)
                return "rail_activator" + (on ? "_powered" : "");

            if (metadata == 6 || metadata == 7 || metadata == 8 || metadata == 9)
                return "rail_normal_turned";

            return "rail_normal";
        }
Ejemplo n.º 40
0
        public static int GetSideInt(BlockSide side)
        {
            string s = side.ToString().ToLower();

            int i = 0;

            if (s.StartsWith("x"))
            {
                if (s.EndsWith("pos"))
                    return 0;
                if (s.EndsWith("neg"))
                    return 1;
            }
            if (s.StartsWith("y"))
            {
                if (s.EndsWith("pos"))
                    return 2;
                if (s.EndsWith("neg"))
                    return 3;
            }
            if (s.StartsWith("z"))
            {
                if (s.EndsWith("pos"))
                    return 4;
                if (s.EndsWith("neg"))
                    return 5;
            }

            return i;
        }
Ejemplo n.º 41
0
 public override string GetTextureForSide(BlockSide side, byte metadata)
 {
     return Textures.GetTexturesForMetadata(metadata)[GetSideInt(side)];
 }
Ejemplo n.º 42
0
        public static UnityEngine.Vector3 GetVector(this BlockSide blockSide)
        {
            var vectorValues = blockSide.GetAttribute <BlockSideVectorValuesAttribute>();

            return(new UnityEngine.Vector3(vectorValues.X, vectorValues.Y, vectorValues.Z));
        }