Beispiel #1
0
        public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak)
        {
            ModTileEntity up    = ExampleTEMod.GetTileEntity(i, j - 1);
            ModTileEntity down  = ExampleTEMod.GetTileEntity(i, j + 1);
            ModTileEntity left  = ExampleTEMod.GetTileEntity(i - 1, j);
            ModTileEntity right = ExampleTEMod.GetTileEntity(i + 1, j);

            int frameX = 0;
            int frameY = 0;

            if (WorldGen.InWorld(i - 1, j) && Main.tile[i - 1, j].active() && /*left is TileEntityEnergyHandler*/ Main.tile[i - 1, j].type == Type)
            {
                frameX += 18;
            }
            if (WorldGen.InWorld(i + 1, j) && Main.tile[i + 1, j].active() && /*right is TileEntityEnergyHandler*/ Main.tile[i + 1, j].type == Type)
            {
                frameX += 36;
            }
            if (WorldGen.InWorld(i, j - 1) && Main.tile[i, j - 1].active() && /*up is TileEntityEnergyHandler*/ Main.tile[i, j - 1].type == Type)
            {
                frameY += 18;
            }
            if (WorldGen.InWorld(i, j + 1) && Main.tile[i, j + 1].active() && /*down is TileEntityEnergyHandler*/ Main.tile[i, j + 1].type == Type)
            {
                frameY += 36;
            }
            Main.tile[i, j].frameX = (short)frameX;
            Main.tile[i, j].frameY = (short)frameY;
            return(false);
        }
Beispiel #2
0
        public override void Update()
        {
            ModTileEntity up    = ExampleTEMod.GetTileEntity(Position.X, Position.Y - 1);
            ModTileEntity down  = ExampleTEMod.GetTileEntity(Position.X, Position.Y + 1);
            ModTileEntity left  = ExampleTEMod.GetTileEntity(Position.X - 1, Position.Y);
            ModTileEntity right = ExampleTEMod.GetTileEntity(Position.X + 1, Position.Y);

            long usedEnergy = 0;

            ProcessSide(up, Side.up, Side.down, ref usedEnergy);
            ProcessSide(down, Side.down, Side.up, ref usedEnergy);
            ProcessSide(left, Side.left, Side.right, ref usedEnergy);
            ProcessSide(right, Side.right, Side.left, ref usedEnergy);

            storage.TransferEnergy(usedEnergy);

            storage.WriteTagCompound(tag);
            WriteDataToTagCompound();

            if (Main.netMode == NetmodeID.Server)
            {
                updateTimer--;
                if (updateTimer == 0)
                {
                    NetMessage.SendData(MessageID.TileEntitySharing, -1, -1, null, ID);
                    updateTimer = 3;
                }
            }
        }
Beispiel #3
0
        public override void PostDraw(int i, int j, SpriteBatch spriteBatch)
        {
            Texture2D             input  = mod.GetTexture("Tiles/ExampleWireConnectorInput");
            Texture2D             output = mod.GetTexture("Tiles/ExampleWireConnectorOutput");
            ModTileEntity         up     = ExampleTEMod.GetTileEntity(i, j - 1);
            ModTileEntity         down   = ExampleTEMod.GetTileEntity(i, j + 1);
            ModTileEntity         left   = ExampleTEMod.GetTileEntity(i - 1, j);
            ModTileEntity         right  = ExampleTEMod.GetTileEntity(i + 1, j);
            ExampleWireTileEntity itself = ExampleTEMod.GetTileEntity(i, j) as ExampleWireTileEntity;



            if (up is EnergyHandler handlerUp && !(up is ExampleWireTileEntity) && handlerUp.CanConnect(Side.down))
            {
                if (itself.IO[Side.up])
                {
                    spriteBatch.Draw(input, new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y), new Rectangle(0, 0, 16, 16), Color.White, 0f, new Vector2(0, 0), Vector2.One, SpriteEffects.None, 0f);
                }
                else
                {
                    spriteBatch.Draw(output, new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y), new Rectangle(0, 0, 16, 16), Color.White, 0f, new Vector2(0, 0), Vector2.One, SpriteEffects.None, 0f);
                }
            }
            if (down is EnergyHandler handlerDown && !(down is ExampleWireTileEntity) && handlerDown.CanConnect(Side.up))
            {
                if (itself.IO[Side.down])
                {
                    spriteBatch.Draw(input, new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y), new Rectangle(18, 0, 16, 16), Color.White, 0f, new Vector2(0, 0), Vector2.One, SpriteEffects.None, 0f);
                }
                else
                {
                    spriteBatch.Draw(output, new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y), new Rectangle(18, 0, 16, 16), Color.White, 0f, new Vector2(0, 0), Vector2.One, SpriteEffects.None, 0f);
                }
            }
            if (right is EnergyHandler handlerRight && !(right is ExampleWireTileEntity) && handlerRight.CanConnect(Side.left))
            {
                if (itself.IO[Side.right])
                {
                    spriteBatch.Draw(input, new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y), new Rectangle(36, 0, 16, 16), Color.White, 0f, new Vector2(0, 0), Vector2.One, SpriteEffects.None, 0f);
                }
                else
                {
                    spriteBatch.Draw(output, new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y), new Rectangle(36, 0, 16, 16), Color.White, 0f, new Vector2(0, 0), Vector2.One, SpriteEffects.None, 0f);
                }
            }
            if (left is EnergyHandler handlerLeft && !(left is ExampleWireTileEntity) && handlerLeft.CanConnect(Side.right))
            {
                if (itself.IO[Side.left])
                {
                    spriteBatch.Draw(input, new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y), new Rectangle(54, 0, 16, 16), Color.White, 0f, new Vector2(0, 0), Vector2.One, SpriteEffects.None, 0f);
                }
                else
                {
                    spriteBatch.Draw(output, new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y), new Rectangle(54, 0, 16, 16), Color.White, 0f, new Vector2(0, 0), Vector2.One, SpriteEffects.None, 0f);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Standard right click funtion, it get the top left corner of the tile and see if there is a generator tile entity.
        /// If there is one, it will show how much energy it has generated, otherwise it will return an error.
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        public override void RightClick(int i, int j)
        {
            GeneratorTileEntity tileEntity = ExampleTEMod.GetTileEntity(i, j) as GeneratorTileEntity;

            if (tileEntity != null)
            {
                Main.NewText(tileEntity.GetEnergyStored(null) + "/" + tileEntity.GetMaxEnergyStorage(null) + " TE");
            }
        }
Beispiel #5
0
        public override void RightClick(int i, int j)
        {
            ModTileEntity tileEntity = ExampleTEMod.GetTileEntity(i, j);

            if (tileEntity is ExampleWireTileEntity wire)
            {
                Side side = ExampleTEMod.GetBlockSide(i, j);
                if (side != Side.none)
                {
                    wire.IO[side] = !wire.IO[side];
                }
                Main.NewText(wire.storage.GetCurrentEnergy() + "/" + wire.storage.MaxEnergy + " TE");
            }
        }
        public override void Update()
        {
            ModTileEntity up    = ExampleTEMod.GetTileEntity(Position.X, Position.Y - 1);
            ModTileEntity down  = ExampleTEMod.GetTileEntity(Position.X, Position.Y + 1);
            ModTileEntity left  = ExampleTEMod.GetTileEntity(Position.X - 1, Position.Y);
            ModTileEntity right = ExampleTEMod.GetTileEntity(Position.X + 1, Position.Y);


            if (Main.netMode == NetmodeID.Server)
            {
                updateTimer--;
                if (updateTimer == 0)
                {
                    NetMessage.SendData(MessageID.TileEntitySharing, -1, -1, null, ID);
                    updateTimer = 3;
                }
            }
            EnergyContainer.WriteTagCompound(tag);
        }
Beispiel #7
0
        /// <summary>
        /// Generate energy as long the generator is not full.
        /// If it's on server the timer will go on and sync the data every time it reach 0
        /// </summary>
        public override void Update()
        {
            try
            {
                if (storage.GetCurrentEnergy() != storage.MaxEnergy)
                {
                    storage.ModifyEnergy(4);
                }

                ModTileEntity up    = ExampleTEMod.GetTileEntity(Position.X, Position.Y - 1);
                ModTileEntity down  = ExampleTEMod.GetTileEntity(Position.X, Position.Y + 1);
                ModTileEntity left  = ExampleTEMod.GetTileEntity(Position.X - 1, Position.Y);
                ModTileEntity right = ExampleTEMod.GetTileEntity(Position.X + 1, Position.Y);

                long usedEnergy = 0;

                ProcessSide(up, Side.up, Side.down, ref usedEnergy);
                ProcessSide(down, Side.down, Side.up, ref usedEnergy);
                ProcessSide(left, Side.left, Side.right, ref usedEnergy);
                ProcessSide(right, Side.right, Side.left, ref usedEnergy);

                storage.TransferEnergy(usedEnergy);

                if (Main.netMode == NetmodeID.Server)
                {
                    updateTimer--;

                    if (updateTimer <= 0)
                    {
                        NetMessage.SendData(MessageID.TileEntitySharing, -1, -1, null, ID);
                        updateTimer = 3;
                    }
                }
                storage.WriteTagCompound(tag);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }