Exemplo n.º 1
0
        public static void Received(ushort id, byte[] data, ulong sender, bool isArrivedFromServer)
        {
            AddBlockPacket temp = MyAPIGateway.Utilities.SerializeFromBinary <AddBlockPacket>(data);

            if (temp != null)
            {
                MyObjectBuilder_PistonTop newTop = temp.newTop;
                IMyCubeGrid grid = MyAPIGateway.Entities.GetEntityById(temp.gridId) as IMyCubeGrid;
                if (newTop != null && grid != null)
                {
                    grid.AddBlock(newTop, false);
                }
            }
        }
Exemplo n.º 2
0
        private static bool TrySetDir(IMyPistonTop top, IMyPistonBase piston, out IMyPistonTop result)
        {
            result = top;
            if (((MyCubeGrid)top.CubeGrid).BlocksCount == 1)
            {
                // Top is the only block on the grid, the piston can safely set its orientation.
                return(true);
            }

            // Get directions that the top should have.
            Matrix m = WorldToLocal(piston.WorldMatrix, top.CubeGrid.WorldMatrix);

            Base6Directions.Direction forward = Base6Directions.GetClosestDirection(m.Forward);
            Base6Directions.Direction up      = Base6Directions.GetClosestDirection(m.Up);

            if (top.Orientation.Up != up)
            {
                // Top must be facing up.
                result = null;
                return(false);
            }

            if (top.Orientation.Forward == forward)
            {
                // Top is already in the correct orientation.
                return(true);
            }

            // Replace the top with one that is in the correct orientation.
            MyObjectBuilder_PistonTop ob = (MyObjectBuilder_PistonTop)top.GetObjectBuilderCubeBlock(true);

            ob.BlockOrientation = new SerializableBlockOrientation(forward, up);
            top.CubeGrid.RemoveBlock(top.SlimBlock);
            ((MyCubeGrid)top.CubeGrid).SendRemovedBlocks();
            ob.EntityId = 0;
            result      = top.CubeGrid.AddBlock(ob, false)?.FatBlock as IMyPistonTop;
            if (result != null)
            {
                ob.EntityId = result.EntityId;
                new AddBlockPacket(top.CubeGrid, ob).SendToOthers();
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
 public AddBlockPacket(IMyCubeGrid cubeGrid, MyObjectBuilder_PistonTop newTop)
 {
     gridId      = cubeGrid.EntityId;
     this.newTop = newTop;
 }