Exemplo n.º 1
0
        private BlockState Check(IBlockAccess world, BlockCoordinates position, BlockCoordinates updatedBlock, BlockState current)
        {
            var neighbor = world.GetBlockState(updatedBlock);

            var facePos = updatedBlock - position;
            var fp      = new Vector3(facePos.X, facePos.Y, facePos.Z);

            fp.Normalize();

            var face       = new Vector3(fp.X, fp.Y, fp.Z).GetBlockFace();
            var faceString = face.ToString().ToLower();

            current.TryGetValue(faceString, out var currentValue);

            if (CanAttach(face, neighbor.Block))
            {
                if (currentValue != "true")
                {
                    return(current.WithProperty(faceString, "true"));
                    //world.SetBlockState(position, state);
                }
            }
            else
            {
                if (currentValue != "false")
                {
                    return(current.WithProperty(faceString, "false"));
                    //world.SetBlockState(position, state);
                }
            }

            return(current);
        }
Exemplo n.º 2
0
        private bool Check(IBlockAccess world, BlockCoordinates position, BlockFace face, out int yOffset)
        {
            yOffset = 0;
            if (world.GetBlockState(position + face.GetBlockCoordinates()).Block is Rail)
            {
                return(true);
            }

            if (world.GetBlockState(position + BlockCoordinates.Up + face.GetBlockCoordinates()).Block is Rail)
            {
                yOffset = 1;
                return(true);
            }

            if (world.GetBlockState(position + BlockCoordinates.Down + face.GetBlockCoordinates()).Block is Rail)
            {
                yOffset = -1;
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        protected virtual bool ShouldRenderFace(IBlockAccess world, BlockFace face, BlockCoordinates position, Block me)
        {
            if (world == null)
            {
                return(true);
            }

            if (position.Y >= 256)
            {
                return(true);
            }

            if (face == BlockFace.None)
            {
                return(true);
            }

            var pos = position + face.GetBlockCoordinates();

            var cX = (int)pos.X & 0xf;
            var cZ = (int)pos.Z & 0xf;

            if (cX < 0 || cX > 16)
            {
                return(false);
            }

            if (cZ < 0 || cZ > 16)
            {
                return(false);
            }

            //if (!world.HasBlock(pos.X, pos.Y, pos.Z))
            //	return false;

            var theBlock = world.GetBlockState(pos).Block;

            if (!theBlock.Renderable)
            {
                return(true);
            }

            return(me.ShouldRenderFace(face, theBlock));
        }
Exemplo n.º 4
0
        private BlockState Update(IBlockAccess world, BlockState blockState, BlockCoordinates coordinates, BlockCoordinates updated)
        {
            var updatedBlock = world.GetBlockState(updated);

            if (!(updatedBlock.Block is Door))
            {
                return(blockState);
            }

            bool isUpper = false;

            if (blockState.TryGetValue("half", out string half))
            {
                isUpper = half.Equals("upper", StringComparison.InvariantCultureIgnoreCase);
            }

            if (updated == coordinates + BlockCoordinates.Up && !isUpper)
            {
                if (updatedBlock.TryGetValue("hinge", out var hingeValue))
                {
                    blockState = blockState.WithProperty("hinge", hingeValue, false, "half", "open", "facing");
                }
            }
            else if (updated == coordinates + BlockCoordinates.Down && isUpper)
            {
                if (updatedBlock.TryGetValue("open", out string open))
                {
                    blockState = blockState.WithProperty("open", open, false, "half", "hinge");
                }

                if (updatedBlock.TryGetValue("facing", out var facing))
                {
                    blockState = blockState.WithProperty("facing",
                                                         facing, false, "half", "hinge", "open");
                }
            }

            return(blockState);
        }
Exemplo n.º 5
0
        protected void GetLight(IBlockAccess world, Vector3 facePosition, out byte blockLight, out byte skyLight, bool smooth = false)
        {
            var faceBlock = world.GetBlockState(facePosition).Block;

            skyLight   = world.GetSkyLight(facePosition);
            blockLight = world.GetBlockLight(facePosition);

            //if (skyLight == 15 || blockLight == 15)
            //	return;

            if (!smooth && !faceBlock.Transparent && !(skyLight > 0 || blockLight > 0))
            {
                return;                // (byte)Math.Min(blockLight + skyLight, 15);
            }


            Vector3 lightOffset = Vector3.Zero;

            byte highestBlocklight = blockLight;
            byte highestSkylight   = skyLight;
            bool lightFound        = false;

            for (int i = 0; i < 6; i++)
            {
                switch (i)
                {
                case 0:
                    lightOffset = Vector3.Up;
                    break;

                case 1:
                    lightOffset = Vector3.Down;
                    break;

                case 2:
                    lightOffset = Vector3.Forward;
                    break;

                case 3:
                    lightOffset = Vector3.Backward;
                    break;

                case 4:
                    lightOffset = Vector3.Left;
                    break;

                case 5:
                    lightOffset = Vector3.Right;
                    break;
                }

                skyLight   = world.GetSkyLight(facePosition + lightOffset);
                blockLight = world.GetBlockLight(facePosition + lightOffset);

                if (skyLight > 0 || blockLight > 0)
                {
                    if (skyLight > 0)
                    {
                        lightFound = true;
                        break;
                    }
                    else if (blockLight > highestBlocklight)
                    {
                        highestBlocklight = blockLight;
                        highestSkylight   = skyLight;
                    }
                }
            }

            if (!lightFound)
            {
                skyLight = highestSkylight;
                if (highestBlocklight > 0)
                {
                    blockLight = (byte)(highestBlocklight - 1);
                }
                else
                {
                    blockLight = 0;
                }
            }

            //(byte)Math.Min(Math.Max(0, blockLight + skyLight), 15);
        }
Exemplo n.º 6
0
        private bool UpdateState(IBlockAccess world,
                                 BlockState state,
                                 BlockCoordinates position,
                                 BlockCoordinates updatedBlock,
                                 out BlockState result, bool checkCorners)
        {
            result = state;
            var block = world.GetBlockState(updatedBlock).Block;

            if (!(block is Stairs))
            {
                return(false);
            }

            var myHalf = GetHalf(state);

            var blockState = block.BlockState;

            if (myHalf != GetHalf(blockState))
            {
                return(false);
            }

            var facing         = GetFacing(state);
            var neighborFacing = GetFacing(blockState);

            if (checkCorners)
            {
                BlockCoordinates offset1 = facing.GetVector3();

                if (neighborFacing != facing && neighborFacing != facing.Opposite() &&
                    updatedBlock == position + offset1)
                {
                    if (neighborFacing == BlockModel.RotateDirection(
                            facing, 1, BlockModel.FACE_ROTATION, BlockModel.INVALID_FACE_ROTATION))
                    {
                        if (facing == BlockFace.North || facing == BlockFace.South)
                        {
                            result = state.WithProperty("shape", "outer_right");
                        }
                        else
                        {
                            result = state.WithProperty("shape", "outer_right");
                        }

                        return(true);
                    }

                    if (facing == BlockFace.North || facing == BlockFace.South)
                    {
                        result = state.WithProperty("shape", "outer_left");
                    }
                    else
                    {
                        result = state.WithProperty("shape", "outer_left");
                    }

                    return(true);
                }

                BlockCoordinates offset2 = facing.Opposite().GetVector3();

                if (neighborFacing != facing && neighborFacing != facing.Opposite() &&
                    updatedBlock == position + offset2)
                {
                    if (neighborFacing == BlockModel.RotateDirection(
                            facing, 1, BlockModel.FACE_ROTATION, BlockModel.INVALID_FACE_ROTATION))
                    {
                        if (facing == BlockFace.North || facing == BlockFace.South)
                        {
                            result = state.WithProperty("shape", "inner_right");
                        }
                        else
                        {
                            result = state.WithProperty("shape", "inner_right");
                        }

                        return(true);
                    }

                    if (facing == BlockFace.North || facing == BlockFace.South)
                    {
                        result = state.WithProperty("shape", "inner_left");
                    }
                    else
                    {
                        result = state.WithProperty("shape", "inner_left");
                    }

                    return(true);
                }
            }
            else
            {
                if (facing == neighborFacing)
                {
                    result = state.WithProperty("shape", "straight");

                    return(true);
                }
            }


            return(false);
        }
        private static bool Passes(IBlockAccess world, Vector3 position, BlockState baseblockState, string rule,
                                   string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return(true);
            }

            bool      isDirection = true;
            BlockFace face        = BlockFace.None;

            switch (rule)
            {
            case "north":
                face = BlockFace.South;
                break;

            case "east":
                face = BlockFace.East;
                break;

            case "south":
                face = BlockFace.North;
                break;

            case "west":
                face = BlockFace.West;
                break;

            case "up":
                face = BlockFace.Up;
                break;

            case "down":
                face = BlockFace.Down;
                break;

            default:
                isDirection = false;

                break;
            }

            var direction = face.GetVector3();

            if (isDirection && (value == "true" || value == "false" || value == "none"))
            {
                var newPos     = new BlockCoordinates(position + direction);
                var blockState = world.GetBlockState(newPos);
                var block      = blockState.Block;

                if (face == BlockFace.Up && !(block is Air))
                {
                    return(true);
                }
                //if (face == BlockFace.Up && !(block is Air))
                //	return true;

                var canAttach = baseblockState.Block.CanAttach(face, block);

                if (value == "true")
                {
                    return(canAttach);
                }
                else if (value == "false")
                {
                    return(!canAttach);
                }
                else if (value == "none")
                {
                    return(block.BlockMaterial == Material.Air);
                }

                return(false);
            }


            if (baseblockState.TryGetValue(rule, out string val))
            {
                return(val.Equals(value, StringComparison.InvariantCultureIgnoreCase));
            }

            return(false);
        }
Exemplo n.º 8
0
        private bool CheckFlowing(IBlockAccess world, BlockCoordinates position)
        {
            var forward = world.GetBlockState(position + BlockCoordinates.Forwards);

            if (forward.Model is LiquidBlockModel)
            {
                if (GetLevel(forward) < 7)
                {
                    return(true);
                }

                if (GetAverageLiquidLevels(world, position + BlockCoordinates.Forwards, out var _, out var _) < 7)
                {
                    return(true);
                }
            }

            var backward = world.GetBlockState(position + BlockCoordinates.Backwards);

            if (backward.Model is LiquidBlockModel)
            {
                if (GetLevel(backward) < 7)
                {
                    return(true);
                }

                if (GetAverageLiquidLevels(world, position + BlockCoordinates.Backwards, out var _, out var _) < 7)
                {
                    return(true);
                }
            }

            var left = world.GetBlockState(position + BlockCoordinates.Left);

            if (left.Model is LiquidBlockModel)
            {
                if (GetLevel(left) < 7)
                {
                    return(true);
                }

                if (GetAverageLiquidLevels(world, position + BlockCoordinates.Left, out var _, out var _) < 7)
                {
                    return(true);
                }
            }

            var right = world.GetBlockState(position + BlockCoordinates.Right);

            if (right.Model is LiquidBlockModel)
            {
                if (GetLevel(right) < 7)
                {
                    return(true);
                }

                if (GetAverageLiquidLevels(world, position + BlockCoordinates.Right, out var _, out var _) < 7)
                {
                    return(true);
                }
            }

            //if (GetAverageLiquidLevels(world, position - BlockCoordinates.Up, out var _, out var _) < 8)
            //	return true;
            //!Solid

            //return (!(forward.Block.Solid && backward.Block.Solid && left.Block.Solid && right.Block.Solid) && (forward.Block.IsReplacible || backward.Block.IsReplacible || left.Block.IsReplacible || right.Block.IsReplacible));

            return(false);
        }
Exemplo n.º 9
0
Arquivo: Stairs.cs Projeto: K4mey/Alex
        private bool UpdateState(IBlockAccess world, BlockState state, BlockCoordinates position, BlockCoordinates updatedBlock, out BlockState result)
        {
            result = state;
            var block = world.GetBlockState(updatedBlock).Block;

            if (!(block is Stairs))
            {
                return(false);
            }

            var myHalf = GetHalf(state);

            var blockState = block.BlockState;

            if (myHalf != GetHalf(blockState))
            {
                return(false);
            }

            var facing   = GetFacing(state);
            var neighbor = GetFacing(blockState);

            var myShape       = GetShape(state);
            var neighborShape = GetShape(blockState);

            // int offset = (myHalf == "top") ? -1 : 1;

            //  var innerRight = ""
            if (myHalf == "top")
            {
            }

            //if ()
            {
                // if (neighbor == BlockModel.RotateDirection(facing, 1, BlockModel.FACE_ROTATION,
                //         BlockModel.INVALID_FACE_ROTATION) && neighbor != facing && GetHalf(state) == GetHalf(blockState))
                //if (facing == BlockFace.East && updatedBlock == (position + facing.Opposite().GetBlockCoordinates()))

                BlockCoordinates offset1 = facing.GetVector3();

                if (neighbor != facing && neighbor != facing.Opposite() && updatedBlock == position + offset1)
                {
                    if (neighbor == BlockModel.RotateDirection(facing, 1, BlockModel.FACE_ROTATION,
                                                               BlockModel.INVALID_FACE_ROTATION))
                    {
                        if (facing == BlockFace.North || facing == BlockFace.South)
                        {
                            result = state.WithProperty("shape", "inner_right");
                        }
                        else
                        {
                            result = state.WithProperty("shape", "outer_right");
                        }
                        return(true);
                    }

                    if (facing == BlockFace.North || facing == BlockFace.South)
                    {
                        result = state.WithProperty("shape", "inner_left");
                    }
                    else
                    {
                        result = state.WithProperty("shape", "outer_left");
                    }

                    return(true);
                }

                BlockCoordinates offset2 = facing.Opposite().GetVector3();

                if (neighbor != facing && neighbor != facing.Opposite() && updatedBlock == position + offset2)
                {
                    if (neighbor == BlockModel.RotateDirection(facing, 1, BlockModel.FACE_ROTATION,
                                                               BlockModel.INVALID_FACE_ROTATION))
                    {
                        if (facing == BlockFace.North || facing == BlockFace.South)
                        {
                            result = state.WithProperty("shape", "outer_right");
                        }
                        else
                        {
                            result = state.WithProperty("shape", "inner_right");
                        }
                        return(true);
                    }

                    if (facing == BlockFace.North || facing == BlockFace.South)
                    {
                        result = state.WithProperty("shape", "outer_left");
                    }
                    else
                    {
                        result = state.WithProperty("shape", "inner_left");
                    }
                    return(true);
                }

                /* if (updatedBlock == (position + facing.Opposite().GetBlockCoordinates()))
                 * {
                 *  return state.WithProperty("shape", "outer_left");
                 * }*/
            }

            return(false);
        }
Exemplo n.º 10
0
        private static bool Passes(IBlockAccess world, Vector3 position, BlockState baseblockState, string rule,
                                   string value)
        {
            if (baseblockState.Block is IMultipartCheck multipartChecker)
            {
                return(multipartChecker.Passes(world, position, rule, value));
            }

            if (string.IsNullOrWhiteSpace(value))
            {
                return(true);
            }

            bool isDirection = true;

            BlockFace face = BlockFace.None;

            if (!TryGetBlockface(rule, out face))
            {
                isDirection = false;
            }

            var direction = face.GetVector3();

            if (isDirection && (value == "true" || value == "false" || value == "none"))
            {
                var newPos     = new BlockCoordinates(position + direction);
                var blockState = world.GetBlockState(newPos);
                var block      = blockState.Block;

                if (face == BlockFace.Up && !(block is Air))
                {
                    return(true);
                }
                //if (face == BlockFace.Up && !(block is Air))
                //	return true;

                var canAttach = baseblockState.Block.CanAttach(face, block);

                if (value == "true")
                {
                    return(canAttach);
                }
                else if (value == "false")
                {
                    return(!canAttach);
                }
                else if (value == "none")
                {
                    return(block.BlockMaterial == Material.Air);
                }

                return(false);
            }


            if (baseblockState.TryGetValue(rule, out string val))
            {
                return(val.Equals(value, StringComparison.InvariantCultureIgnoreCase));
            }

            return(false);
        }
Exemplo n.º 11
0
        private bool IsRedstoneWire(IBlockAccess world, Vector3 position)
        {
            var block = world.GetBlockState(position).Block;

            return(block is RedstoneWire);
        }