コード例 #1
0
        public static void TryInsertOutput(this MachineEntity entity, int outputSlotsStart, int outputSlotsEnd, int inputType, int inputStack)
        {
            //Find the first slot that the items can stack to.  If that stack isn't enough, overflow to the next slot
            for (int i = outputSlotsStart; i < outputSlotsEnd + 1; i++)
            {
                Item item = entity.RetrieveItem(i);
                if (item.IsAir)
                {
                    item.SetDefaults(inputType);
                    item.type  = inputType;
                    item.stack = inputStack;
                    break;
                }

                if (item.type == inputType && item.stack < item.maxStack)
                {
                    if (item.stack + inputStack <= item.maxStack)
                    {
                        item.stack += inputStack;
                        break;
                    }
                    else
                    {
                        inputStack -= item.maxStack - item.stack;
                        item.stack  = item.maxStack;
                    }
                }
            }
        }
コード例 #2
0
        public static void KillMachine(int i, int j, int type)
        {
            Tile    tile  = Main.tile[i, j];
            Machine mTile = ModContent.GetModTile(type) as Machine;

            mTile.GetDefaultParams(out _, out _, out _, out int itemType);

            int         itemIndex = Item.NewItem(i * 16, j * 16, 16, 16, itemType);
            MachineItem item      = Main.item[itemIndex].modItem as MachineItem;

            Point16 tePos = new Point16(i, j) - tile.TileCoord();

            if (TileEntity.ByPosition.ContainsKey(tePos))
            {
                MachineEntity tileEntity = TileEntity.ByPosition[tePos] as MachineEntity;
                //Drop any items the entity contains
                if (tileEntity.SlotsCount > 0)
                {
                    for (int slot = 0; slot < tileEntity.SlotsCount; slot++)
                    {
                        Item drop = tileEntity.RetrieveItem(slot);

                        //Drop the item and copy over any important data
                        if (drop.type > ItemID.None && drop.stack > 0)
                        {
                            int dropIndex = Item.NewItem(i * 16, j * 16, 16, 16, drop.type, drop.stack);
                            if (drop.modItem != null)
                            {
                                Main.item[dropIndex].modItem.Load(drop.modItem.Save());
                            }
                        }

                        tileEntity.ClearItem(slot);
                    }
                }

                item.entityData = tileEntity.Save();

                //Remove this machine from the wire networks if it's a powered machine
                if (tileEntity is PoweredMachineEntity pme)
                {
                    NetworkCollection.RemoveMachine(pme);
                }

                tileEntity.Kill(i, j);

                if (Main.netMode == NetmodeID.MultiplayerClient)
                {
                    NetMessage.SendData(MessageID.TileEntitySharing, remoteClient: -1, ignoreClient: Main.myPlayer, number: tileEntity.ID);
                }
            }
        }
コード例 #3
0
        public static void StopReactionIfOutputSlotsAreFull(this MachineEntity entity, int outputSlotsStart, int outputSlotsEnd)
        {
            //Check that all slots aren't full.  If they are, abort early
            bool allFull = true;

            for (int i = outputSlotsStart; i < outputSlotsEnd + 1; i++)
            {
                if (entity.RetrieveItem(i).IsAir)
                {
                    allFull = false;
                }
            }

            if (allFull)
            {
                entity.ReactionInProgress = false;
            }
        }
コード例 #4
0
 public static void ClearItem(this MachineEntity entity, int slot)
 => entity.RetrieveItem(slot).TurnToAir();