コード例 #1
0
 public Block(BlockPrototype prototype, Point location)
 {
     this.prototype         = prototype;
     this.location          = location;
     this.emittedLightLevel = prototype.emittedLightLevel;
     if (prototype.emittedLightLevel > 0)   //We emit light!
     {
         LightingEngine.fullLightingUpdateEventDispatcher.registerHandler(this);
     }
     MainForm.getInstance().Load += new EventHandler(Block_Load);
     MainForm.getInstance().PhysicsTimer.Tick += new EventHandler(GameTimer_Tick);
 }
コード例 #2
0
ファイル: BlockPrototype.cs プロジェクト: ethan2-0/Terraria
        public virtual void use(ItemInInventory item)
        {
            if (!(item.item is BlockPrototype))
            {
                throw new ArgumentException("The provided item is not a BlockPrototype.");
            }
            BlockPrototype b = (BlockPrototype)item.item;

            /*Point p = MainForm.getInstance().getCursorBlockLocation();
             * if (MainForm.getInstance().world.blocks[p.X][p.Y].prototype == BlockPrototype.air) {
             *  Point pos = MainForm.getInstance().getTotalCursorPos();
             *  MainForm.getInstance().world.blocks[p.X][p.Y] = Block.createNewBlock(this, pos);
             *  item.useUp(1);
             * }*/
            Player   player      = MainForm.getInstance().player;
            MainForm mainform    = MainForm.getInstance();
            World    w           = mainform.world;
            Point    cursorBlock = mainform.getCursorBlockLocation();//new Point(mainform.player.blockX, mainform.player.blockY);//getCursorBlockLocation();
            Block    block       = w.getBlockAt(cursorBlock.X, cursorBlock.Y);

            if (block == null)
            {
                return;
            }
            if (Util.distanceBetween(block.location, mainform.player.location) > 200)
            {
                return;
            }
            if (block.prototype.id == "OpenTerraria:Air")
            {
                w.blocks[cursorBlock.X][cursorBlock.Y].prepareForRemoval();
                w.blocks[cursorBlock.X][cursorBlock.Y] = Block.createNewBlock(this, new Point(cursorBlock.X * 20, cursorBlock.Y * 20));
                w.updateSkyLightForColumn(cursorBlock.X);
            }
            Inventory inventory = MainForm.getInstance().getParentInventory(item);

            inventory.removeAmount(this, 1);
            LightingEngine.doFullLightingUpdate(false);
        }
コード例 #3
0
 public static Block createNewBlock(BlockPrototype prototype, Point location)
 {
     return(prototype.createNew(location));
 }