private void HandleMouse(MouseButtons button, Vector3 position)
        {
            switch (button)
            {
            case MouseButtons.Left:
                PlaceBlock(cellX, cellZ, Palette.BlockToPlace(Reactor.BlockAt(position)));
                break;

            case MouseButtons.Right:
                PlaceBlock(cellX, cellZ, new Block("Air", BlockTypes.Air, Palette.Textures["Air"], position));
                break;

            case MouseButtons.Middle:
                PlaceBlock(cellX, cellZ, new FuelCell((FuelCell)Palette.BlockPalette["FuelCell"], position));
                break;

            case MouseButtons.XButton1:
            case MouseButtons.XButton2:
            case MouseButtons.None:
            default:
                return;
            }
            Graphics g = CreateGraphics();

            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            RedrawCell(cellX, cellZ, g, true);
        }
        public void RedrawCell(int x, int z, Graphics g, bool noChecking = false, bool forExport = false)
        {
            int   bs = PlannerUI.blockSize;
            int   ds = (int)Reactor.UI.DrawingScale;
            Point location;

            location = new Point(bs * (x - 1), (forExport ? 0 : menu.Height) + bs * (z - 1));
            Rectangle cellRect = new Rectangle(location, new Size(bs, bs));

            Block block = Reactor.BlockAt(new Vector3(x, Y, z));

            g.DrawImage(block.Texture, cellRect);

            if (noChecking)
            {
                return;
            }
            if (block is Moderator moderator && moderator.Active)
            {
                using (Pen activeCoolerPen = new Pen(Brushes.Green, 2))
                    g.DrawRectangle(activeCoolerPen, location.X + 2 * ds, location.Y + 2 * ds, bs - 4 * ds, bs - 4 * ds);
            }
            if (!block.Valid)
            {
                g.DrawRectangle(PlannerUI.ErrorPen, location.X + ds, location.Y + ds, bs - 2 * ds, bs - 2 * ds);
            }
            if (block.BlockType == BlockTypes.Cooler && ((Cooler)block).Active)
            {
                using (Pen activeCoolerPen = new Pen(Brushes.LightGreen, 3))
                    g.DrawRectangle(activeCoolerPen, location.X + 2 * ds, location.Y + 2 * ds, bs - 4 * ds, bs - 4 * ds);
            }
        }
Пример #3
0
        public int FindAdjacentCells()
        {
            int adjCells = 0;

            foreach (Vector3 o in Reactor.sixAdjOffsets)
            {
                if (Reactor.BlockAt(Position + o) is FuelCell)
                {
                    adjCells++;
                }
            }
            return(adjCells);
        }
        public static NbtCompound ExportAsStructure()
        {
            NbtCompound   reactor          = new NbtCompound("ReactorStructure");
            int           volume           = (int)(Reactor.interiorDims.X * Reactor.interiorDims.Y * Reactor.interiorDims.Z);
            List <string> listPalette      = new List <string>();
            NbtList       palette          = new NbtList("palette", NbtTagType.Compound);
            NbtList       blocks           = new NbtList("blocks", NbtTagType.Compound);
            NbtString     author           = new NbtString("author", "Hellrage");
            NbtCompound   forgeDataVersion = new NbtCompound("ForgeDataVersion", new List <NbtInt> {
                new NbtInt("minecraft", 1343)
            });
            NbtInt dataVersion = new NbtInt("DataVersion", 1342);

            for (int y = 1; y <= Reactor.interiorDims.Y; y++)
            {
                for (int z = 1; z <= Reactor.interiorDims.Z; z++)
                {
                    for (int x = 1; x <= Reactor.interiorDims.X; x++)
                    {
                        Block       block      = Reactor.BlockAt(new Point3D(x, y, z));
                        NbtCompound palettenbt = GetNbtCompound(block);
                        if (!listPalette.Contains(block.DisplayName))
                        {
                            listPalette.Add(block.DisplayName);
                            palette.Add(palettenbt);
                        }
                        NbtCompound blocknbt = new NbtCompound();
                        if (block.DisplayName.Contains("Active"))
                        {
                            blocknbt.Add(CreateActiveCooler(x - 1, y - 1, z - 1));
                        }
                        blocknbt.Add(new NbtList("pos", new List <NbtInt> {
                            new NbtInt(x - 1), new NbtInt(y - 1), new NbtInt(z - 1)
                        }));
                        blocknbt.Add(new NbtInt("state", listPalette.IndexOf(block.DisplayName)));
                        blocks.Add(blocknbt);
                    }
                }
            }

            reactor.Add(new NbtList("size", new List <NbtInt> {
                new NbtInt((int)Reactor.interiorDims.X), new NbtInt((int)Reactor.interiorDims.Y), new NbtInt((int)Reactor.interiorDims.Z)
            }));
            reactor.Add(new NbtList("entities", new List <NbtInt>(), NbtTagType.Compound));
            reactor.Add(blocks);
            reactor.Add(author);
            reactor.Add(palette);
            reactor.Add(forgeDataVersion);
            reactor.Add(dataVersion);
            return(reactor);
        }
Пример #5
0
        public int FindAdjacentModerators()
        {
            int adjModerators = 0;

            foreach (Vector3 o in Reactor.sixAdjOffsets)
            {
                if (Reactor.BlockAt(Position + o) is Moderator moderator)
                {
                    adjModerators++;
                    moderator.Validate();
                    moderator.Active = true;
                }
            }
            return(adjModerators);
        }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            Tuple <int, int> cellCoords = ConvertCellCoordinates(e);

            cellX = cellCoords.Item1;
            cellZ = cellCoords.Item2;

            Reactor.UpdateStats();
            Reactor.UI.RefreshStats();
            Vector3 position = new Vector3(cellX, Y, cellZ);

            PlannerUI.gridToolTip.Show(Reactor.BlockAt(position).GetToolTip(), this, cellX * PlannerUI.blockSize + 16, menu.Height + cellZ * PlannerUI.blockSize + 16);
            Reactor.Redraw();
            base.OnMouseUp(e);
        }
Пример #7
0
        public int FindModeratorThenAdjacentCell(Vector3 offset)
        {
            Vector3 pos;

            for (int i = 1; i <= Configuration.Fission.NeutronReach; i++)
            {
                pos = Position + offset * i;
                if ((Reactor.interiorDims.X >= pos.X & Reactor.interiorDims.Y >= pos.Y & Reactor.interiorDims.Z >= pos.Z)
                    & (pos.X > 0 & pos.Y > 0 & pos.Z > 0))
                {
                    if (!(Reactor.BlockAt(pos) is Moderator))
                    {
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }
                pos = Position + offset * (i + 1);
                if ((Reactor.interiorDims.X >= pos.X & Reactor.interiorDims.Y >= pos.Y & Reactor.interiorDims.Z >= pos.Z)
                    & (pos.X > 0 & pos.Y > 0 & pos.Z > 0))
                {
                    if ((Reactor.BlockAt(pos) is FuelCell))
                    {
                        for (int r = i; r > 0; r--)
                        {
                            pos = Position + offset * r;
                            ((Moderator)Reactor.BlockAt(pos)).Validate();
                        }
                        return(1);
                    }
                }
                else
                {
                    return(0);
                }
            }
            return(0);
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            Tuple <int, int> cellCoords = ConvertCellCoordinates(e);
            int newCellX = cellCoords.Item1;
            int newCellZ = cellCoords.Item2;


            if (cellX != newCellX | cellZ != newCellZ)
            {
                cellX = newCellX;
                cellZ = newCellZ;

                if (cellX > X || cellZ > Z || cellX < 1 || cellZ < 1)
                {
                    return;
                }
                Vector3 position = new Vector3(cellX, Y, cellZ);
                HandleMouse(e.Button, position);
                PlannerUI.gridToolTip.Show(Reactor.BlockAt(position).GetToolTip(), this, cellX * PlannerUI.blockSize + 16, menu.Height + cellZ * PlannerUI.blockSize + 16);
            }
            base.OnMouseMove(e);
        }
        public static NbtCompound ExportReactor()
        {
            NbtCompound reactor        = new NbtCompound("Schematic");
            bool        coolerIsActive = false;
            int         volume         = (int)(Reactor.interiorDims.X * Reactor.interiorDims.Y * Reactor.interiorDims.Z);

            byte[] blocks = new byte[volume];
            byte[] data   = new byte[volume];
            bool   extra  = false;

            byte[]  extraBlocks                 = new byte[volume];
            byte[]  extraBlocksNibble           = new byte[(int)Math.Ceiling(volume / 2.0)];
            NbtList tileEntities                = new NbtList("TileEntities", NbtTagType.Compound);
            Dictionary <string, short> mappings = new Dictionary <string, short>();

            for (int y = 1; y <= Reactor.interiorDims.Y; y++)
            {
                for (int z = 1; z <= Reactor.interiorDims.Z; z++)
                {
                    for (int x = 1; x <= Reactor.interiorDims.X; x++)
                    {
                        coolerIsActive = false;
                        Block block = Reactor.BlockAt(new Point3D(x, y, z));
                        int   index = (int)((x - 1) + ((y - 1) * Reactor.interiorDims.Z + (z - 1)) * Reactor.interiorDims.X);
                        blocks[index] = (byte)BlockIDLookup[block.BlockType];
                        if (block.BlockType == BlockTypes.FuelCell | block.BlockType == BlockTypes.Air)
                        {
                            data[index] = 0;
                        }
                        else if (block is Cooler cooler)
                        {
                            if (cooler.Active)
                            {
                                coolerIsActive = true;
                                blocks[index]  = 340 - 256;
                                data[index]    = 0;
                                tileEntities.Add(CreateActiveCooler(x - 1, y - 1, z - 1));
                            }
                            else
                            {
                                data[index] = (byte)BlockMetaLookup[cooler.CoolerType.ToString()];
                            }
                        }
                        else if (block.BlockType == BlockTypes.Moderator)
                        {
                            data[index] = (byte)BlockMetaLookup[((Moderator)block).ModeratorType.ToString()];
                        }

                        if (coolerIsActive)
                        {
                            extraBlocks[index] = (byte)(340 >> 8);
                            extra = true;
                        }
                        else
                        if ((extraBlocks[index] = (byte)(BlockIDLookup[block.BlockType] >> 8)) > 0)
                        {
                            if (block.BlockType == BlockTypes.Air)
                            {
                                continue;
                            }
                        }
                        if (coolerIsActive)
                        {
                            if (!mappings.ContainsKey("nuclearcraft:active_cooler"))
                            {
                                mappings.Add("nuclearcraft:active_cooler", 340);
                            }
                            else
                            if (!mappings.ContainsKey(SchematicaMappingLookup[block.BlockType]))
                            {
                                mappings.Add(SchematicaMappingLookup[block.BlockType], (short)BlockIDLookup[block.BlockType]);
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < extraBlocksNibble.Length; i++)
            {
                if (i * 2 + 1 < extraBlocks.Length)
                {
                    extraBlocksNibble[i] = (byte)((extraBlocks[i * 2 + 0] << 4) | extraBlocks[i * 2 + 1]);
                }
                else
                {
                    extraBlocksNibble[i] = (byte)(extraBlocks[i * 2 + 0] << 4);
                }
            }

            reactor.Add(new NbtByteArray("Blocks", blocks));
            reactor.Add(new NbtShort("Length", (short)Reactor.interiorDims.Z));
            reactor.Add(new NbtString("Materials", "Alpha"));
            reactor.Add(new NbtShort("Height", (short)Reactor.interiorDims.Y));
            reactor.Add(new NbtByteArray("Data", data));
            reactor.Add(SetIcon());
            NbtCompound mappingsC = new NbtCompound("SchematicaMapping");

            foreach (KeyValuePair <string, short> kvp in mappings)
            {
                mappingsC.Add(new NbtShort(kvp.Key, kvp.Value));
            }
            reactor.Add(mappingsC);
            reactor.Add(new NbtShort("Width", (short)Reactor.interiorDims.X));
            if (extra)
            {
                reactor.Add(new NbtByteArray("AddBlocks", extraBlocksNibble));
            }
            reactor.Add(tileEntities);
            reactor.Add(new NbtList("Entities", NbtTagType.Compound));



            return(reactor);
        }