Пример #1
0
        public static void MultitileDefaults(ModTile tile, string mapName, int type, uint width, uint height)
        {
            Main.tileNoAttach[type]       = true;
            Main.tileFrameImportant[type] = true;

            TileObjectData.newTile.AnchorBottom       = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop, (int)width, 0);
            TileObjectData.newTile.CoordinateHeights  = MiscUtils.Create1DArray(16, height);
            TileObjectData.newTile.CoordinateWidth    = 16;
            TileObjectData.newTile.Height             = (int)height;
            TileObjectData.newTile.Width              = (int)width;
            TileObjectData.newTile.CoordinatePadding  = 2;
            TileObjectData.newTile.LavaDeath          = false;
            TileObjectData.newTile.WaterDeath         = false;
            TileObjectData.newTile.LavaPlacement      = LiquidPlacement.NotAllowed;
            TileObjectData.newTile.WaterPlacement     = LiquidPlacement.NotAllowed;
            TileObjectData.newTile.Origin             = new Point16((int)width / 2, (int)height - 1);
            TileObjectData.newTile.UsesCustomCanPlace = true;

            TileObjectData.addTile(type);

            ModTranslation name = tile.CreateMapEntryName();

            name.SetDefault(mapName);
            tile.AddMapEntry(new Color(0xd1, 0x89, 0x32), name);

            tile.mineResist = 3f;
            //Metal sound
            tile.soundType  = SoundID.Tink;
            tile.soundStyle = 1;
        }
        public static void QuickSetBar(this ModTile tile, int drop, int dustType, Color?mapColor = null, int soundType = SoundID.Tink)
        {
            Main.tileMergeDirt[tile.Type]      = false;
            Main.tileFrameImportant[tile.Type] = true;

            Main.tileSolid[tile.Type]    = true;
            Main.tileSolidTop[tile.Type] = true;
            Main.tileNoAttach[tile.Type] = true;

            TileObjectData.newTile.CopyFrom(TileObjectData.Style1x1);
            TileObjectData.newTile.LavaDeath    = false;
            TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop | AnchorType.SolidSide, TileObjectData.newTile.Width, 0);
            TileObjectData.addTile(tile.Type);

            ModTranslation name = tile.CreateMapEntryName();

            name.SetDefault("Metal Bar"); //all bars are called metal bar in vanilla
            if (mapColor != null)
            {
                tile.AddMapEntry(mapColor ?? Color.Transparent, name);
            }

            tile.dustType  = dustType;
            tile.soundType = soundType;
            tile.drop      = drop;
        }
Пример #3
0
        private TileCollection()
        {
            tilePickaxeMin = new ushort[TileLoader.TileCount];

            // Assign vanilla tiles to 2 (Sand-like is 0, Dirt-like is 1)
            int i;

            for (i = 0; i < TileID.Count; i++)
            {
                tilePickaxeMin[i] = 2;
            }

            tilePickaxeMin.AssignValueToKeys <ushort>(0, TileID.Sand, TileID.Slush, TileID.Silt);
            tilePickaxeMin.AssignValueToKeys <ushort>(1,
                                                      TileID.Dirt, TileID.Mud, TileID.ClayBlock, TileID.SnowBlock,
                                                      TileID.Grass, TileID.CorruptGrass, TileID.FleshGrass, TileID.HallowedGrass, TileID.JungleGrass, TileID.MushroomGrass
                                                      );
            tilePickaxeMin.AssignValueToKeys <ushort>(50, TileID.Meteorite);
            tilePickaxeMin.AssignValueToKeys <ushort>(55, TileID.Demonite, TileID.Crimtane);
            tilePickaxeMin.AssignValueToKeys <ushort>(65,
                                                      TileID.Ebonstone, TileID.Crimstone, TileID.Pearlstone, TileID.Hellstone, TileID.Obsidian, TileID.DesertFossil,
                                                      TileID.BlueDungeonBrick, TileID.GreenDungeonBrick, TileID.PinkDungeonBrick
                                                      );
            tilePickaxeMin.AssignValueToKeys <ushort>(100, TileID.Cobalt, TileID.Palladium);
            tilePickaxeMin.AssignValueToKeys <ushort>(110, TileID.Mythril, TileID.Orichalcum);
            tilePickaxeMin.AssignValueToKeys <ushort>(150, TileID.Adamantite, TileID.Titanium);
            tilePickaxeMin.AssignValueToKeys <ushort>(200, TileID.Chlorophyte);
            tilePickaxeMin.AssignValueToKeys <ushort>(210, TileID.LihzahrdBrick, TileID.LihzahrdAltar);

            for (i = TileID.Count; i < TileLoader.TileCount; i++)
            {
                ModTile modTile = TileLoader.GetTile(i);
                tilePickaxeMin[i] = (ushort)modTile.minPick;
            }
        }
Пример #4
0
        public static bool DrawStorageGUI()
        {
            Player        player        = Main.player[Main.myPlayer];
            StoragePlayer modPlayer     = player.GetModPlayer <StoragePlayer>();
            Point16       storageAccess = modPlayer.ViewingStorage();

            if (!Main.playerInventory || storageAccess.X < 0 || storageAccess.Y < 0)
            {
                return(true);
            }
            ModTile modTile = TileLoader.GetTile(Main.tile[storageAccess.X, storageAccess.Y].type);

            if (modTile == null || !(modTile is StorageAccess))
            {
                return(true);
            }
            TEStorageHeart heart = ((StorageAccess)modTile).GetHeart(storageAccess.X, storageAccess.Y);

            if (heart == null)
            {
                return(true);
            }
            if (modTile is CraftingAccess)
            {
                CraftingGUI.Draw(heart);
            }
            else
            {
                StorageGUI.Draw(heart);
            }
            return(true);
        }
Пример #5
0
        public static bool canActuate(int x, int y)
        {
            if (!WorldGen.InWorld(x, y, 1) || !canPlaceActuator(Main.tile[x, y].type))
            {
                return(false);
            }
            if (!WorldGen.InWorld(x, y - 1, 1) || !Main.tile[x, y - 1].active())
            {
                return(true);
            }
            int topType = Main.tile[x, y - 1].type;

            if (topType == TileID.Trees || topType == TileID.PalmTree || topType == TileID.MushroomTrees ||
                TileID.Sets.BasicChest[topType] || topType == TileID.Dressers || topType == TileID.DemonAltar || topType == TileID.Hellforge)
            {
                return(false);
            }
            ModTile tt = TileLoader.GetTile(topType);

            if (tt != null && (tt.adjTiles.Contains(TileID.Dressers) || tt.adjTiles.Contains(TileID.Containers) || tt.adjTiles.Contains(TileID.Containers2)))
            {
                return(false);
            }
            return(true);
        }
Пример #6
0
        // In this example we used Initialize and Unload_Inner in conjunction with Load and Unload to avoid TypeInitializationException, but we could also just check Enabled before calling MagicStorageIntegration.Unload(); and assign MagicStorage and check Enabled before calling MagicStorageIntegration.Load();
        // I opted to keep the MagicStorage integration logic in the MagicStorageIntegration class to keep MagicStorage related code as sparse and unobtrusive as possible within the remaining codebase for this mod.
        // That said, in ItemChecklistPlayer, we see this:
        //	if (ItemChecklistUI.collectChestItems && MagicStorageIntegration.Enabled)
        //		MagicStorageIntegration.FindItemsInStorage();
        // I could have changed this to always call FindItemsInStorage and have FindItemsInStorage check Enabled, but that would require a FindItemsInStorage_Inner type class once again to prevent errors.
        // Whatever approach you do, be aware of what you are doing and be careful.

        // StoragePlayer and TEStorageHeart are classes in MagicStorage.
        // Make sure to extract the .dll from the .tmod and then add them to your .csproj as references.
        // As a convention, I rename the .dll file ModName_v1.2.3.4.dll and place them in Mod Sources/Mods/lib.
        // I do this for organization and so the .csproj loads properly for others using the GitHub repository.
        // Remind contributors to download the referenced mod itself if they wish to build the mod.
        internal static void FindItemsInStorage()
        {
            var     storagePlayer = Main.LocalPlayer.GetModPlayer <StoragePlayer>();
            Point16 storageAccess = storagePlayer.ViewingStorage();

            if (storageAccess == previousStorageAccess)
            {
                return;
            }
            previousStorageAccess = storageAccess;
            if (!Main.playerInventory || storageAccess.X < 0 || storageAccess.Y < 0)
            {
                return;
            }
            ModTile modTile = TileLoader.GetTile(Main.tile[storageAccess.X, storageAccess.Y].type);

            if (modTile == null || !(modTile is StorageAccess))
            {
                return;
            }
            TEStorageHeart heart = ((StorageAccess)modTile).GetHeart(storageAccess.X, storageAccess.Y);

            if (heart == null)
            {
                return;
            }
            var items = heart.GetStoredItems();

            // Will 1000 items crash the chat?
            foreach (var item in items)
            {
                ItemChecklist.instance.GetGlobalItem <ItemChecklistGlobalItem>().ItemReceived(item);
            }
        }
Пример #7
0
        /// <summary>
        /// Make <paramref name="tilesToMergeWith"></paramref> null to not merge with any specific tile(s).
        /// </summary>
        public static void SimpleFramedTile(this ModTile tile, int drop, int soundType, int dustType, Color mapColor, int minPick,
                                            string mapName = "", bool mergeDirt = false, bool stone = false, params int[] tilesToMergeWith)
        {
            Main.tileBlockLight[tile.Type] = true;
            Main.tileLighted[tile.Type]    = true;
            Main.tileSolid[tile.Type]      = true;

            Main.tileMergeDirt[tile.Type] = mergeDirt;
            Main.tileStone[tile.Type]     = stone;

            ModTranslation name = tile.CreateMapEntryName();

            name.SetDefault(mapName);
            tile.AddMapEntry(mapColor, name);

            if (tilesToMergeWith != null)
            {
                foreach (int i in tilesToMergeWith)
                {
                    Main.tileMerge[tile.Type][i] = true;
                }
            }

            tile.drop      = drop;
            tile.soundType = soundType;
            tile.dustType  = dustType;
            tile.minPick   = minPick;
        }
Пример #8
0
        public static void QuickSetFurniture(this ModTile tile, int width, int height, int dustType, int soundType, bool tallBottom, Color mapColor, bool solidTop = false, bool solid = false, string mapName = "")
        {
            Main.tileLavaDeath[tile.Type]      = false;
            Main.tileFrameImportant[tile.Type] = true;
            Main.tileSolidTop[tile.Type]       = solidTop;
            Main.tileSolid[tile.Type]          = solid;

            TileObjectData.newTile.Width             = width;
            TileObjectData.newTile.Height            = height;
            TileObjectData.newTile.CoordinateHeights = new int[height];

            for (int k = 0; k < height; k++)
            {
                TileObjectData.newTile.CoordinateHeights[k] = 16;
            }

            if (tallBottom)
            {
                TileObjectData.newTile.CoordinateHeights[height - 1] = 18;
            }
            TileObjectData.newTile.UsesCustomCanPlace = true;
            TileObjectData.newTile.CoordinateWidth    = 16;
            TileObjectData.newTile.CoordinatePadding  = 2;
            TileObjectData.newTile.Origin             = new Point16(0, 0);

            TileObjectData.addTile(tile.Type);

            ModTranslation name = tile.CreateMapEntryName();

            name.SetDefault(mapName);
            tile.AddMapEntry(mapColor, name);
            tile.dustType           = dustType;
            tile.soundType          = soundType;
            tile.disableSmartCursor = true;
        }
Пример #9
0
 public void Read(BinaryReader reader)
 {
     tile   = reader.ReadBoolean();
     modded = reader.ReadBoolean();
     if (modded)
     {
         type       = 9999;
         modAndName = reader.ReadString();
         string[] args = modAndName.Split('#');
         Mod      mod  = ModLoader.GetMod(args[0]);
         if (mod != null)
         {
             if (tile)
             {
                 ModTile mtile = mod.GetTile(args[1]);
                 if (mtile != null)
                 {
                     type = mtile.Type;
                 }
             }
             else
             {
                 ModWall mwall = mod.GetWall(args[1]);
                 if (mwall != null)
                 {
                     type = mwall.Type;
                 }
             }
         }
     }
     else
     {
         type = reader.ReadUInt16();
     }
 }
Пример #10
0
 public override bool UseItem(Player player)
 {
     for (int i = 0; i < Main.maxTilesX; i++)
     {
         for (int j = 0; j < Main.maxTilesY; j++)
         {
             Tile    tile  = Framing.GetTileSafely(i, j);
             ModTile mTile = ModContent.GetModTile(tile.type);
             if (mTile != null)
             {
                 if (mTile.mod.Name == "Azercadmium")
                 {
                     if (mTile.Name == "Plants")
                     {
                         tile.type   = (ushort)ModContent.TileType <HellPlants>();
                         tile.frameY = 0;
                         tile.frameX = (short)MathHelper.Clamp(tile.frameX, 0, 198);
                     }
                     if (mTile.Name == "Stems")
                     {
                         tile.type = (ushort)ModContent.TileType <CinderCedarTree>();
                         if (tile.frameX > 264)
                         {
                             tile.frameX -= 264;
                         }
                     }
                 }
             }
         }
     }
     return(true);
 }
Пример #11
0
        public override bool UseItem(Player player)
        {
            Terraria.Audio.LegacySoundStyle hitSound = SoundID.Item1;
            Vector2 position = GetLightPosition(player);

            //Vector2 location = hitbox.Location.ToVector2();
            Point   tileLocation = position.ToTileCoordinates();
            ModTile tile         = TileLoader.GetTile(Main.tile[tileLocation.X, tileLocation.Y].type);

            if (tile == null)
            {
                return(false);
            }
            switch (tile.soundType & 3)
            {
            case 0:
                hitSound = SoundID.Item11; break;

            case 1:
                hitSound = SoundID.Item12; break;

            case 2:
                hitSound = SoundID.Item13; break;

            case 3:
                hitSound = SoundID.Item14; break;
            }
            Main.PlaySound(hitSound, position);
            return(true);
        }
Пример #12
0
        public static void AddMapEntry(this ModTile tile, Color color, string name)
        {
            ModTranslation translation = tile.CreateMapEntryName();

            translation.SetDefault(name);
            tile.AddMapEntry(color, translation);
        }
Пример #13
0
        public static TEStorageHeart GetStorageHeart()
        {
            var player = Get;

            if (player.StorageAccess.X < 0 || player.StorageAccess.Y < 0)
            {
                return(null);
            }

            Tile tile = Main.tile[player.StorageAccess.X, player.StorageAccess.Y];

            if (tile == null)
            {
                return(null);
            }

            int     tileType = tile.type;
            ModTile modTile  = TileLoader.GetTile(tileType);

            if (modTile == null || !(modTile is StorageAccess))
            {
                return(null);
            }
            return(((StorageAccess)modTile).GetHeart(player.StorageAccess.X, player.StorageAccess.Y));
        }
Пример #14
0
        public void DropTheGoods(int i, int j, int type)
        {
            ModTile modTile = TileLoader.GetTile(type);

            if (modTile == null)
            {
                //Vanilla
                if (TileID.Sets.Ore[type] && DoubleOreDrop.oreTileToItem.TryGetValue(type, out int item))
                {
                    Item.NewItem(i * 16, j * 16, 16, 16, item, 1, false, -1, false, false);
                }
            }
            else
            {
                //Modded
                //modTile.Name.Contains("Ore") is a bad way to detect if it's a modded ore. If the modder is smart he should have added his tile to TileID.Sets.Ore properly
                //If not, let the modder know of the ore that doesn't work
                if (TileID.Sets.Ore[type])
                {
                    int drop = modTile.drop;
                    if (drop > 0)
                    {
                        Item.NewItem(i * 16, j * 16, 16, 16, drop, 1, false, -1, false, false);
                    }
                }
            }
        }
Пример #15
0
 public static Texture2D GetEffectTexture(this ModTile multitile, string effect)
 {
     try{
         return(ModContent.GetTexture($"TerraScience/Content/Tiles/Multitiles/Overlays/Effect_{multitile.Name}_{effect}"));
     }catch {
         throw new ContentLoadException($"Could not find overlay texture \"{effect}\" for machine \"{multitile.Name}\"");
     }
 }
Пример #16
0
        // TODO: Change the way so map entry color can be set correctly.
        public static void AddTileNameTranslation(ModTile tile, string tileNameTranslation, GameCulture culture)
        {
            var translation = tile.mod.CreateTranslation(string.Format("MapObject.{0}", tile.Name));

            translation.AddTranslation(culture, tileNameTranslation);

            new LocalizeTile().AddMapEntryTranslation(tile, translation);
        }
Пример #17
0
        public static void TryImportGases <T>(this T entity, Point16 pipePos, int indexToExtract) where T : MachineEntity, IGasMachine
        {
            if (indexToExtract < 0 || indexToExtract >= entity.GasEntries.Length)
            {
                return;
            }

            var entry = entity.GasEntries[indexToExtract];

            if (!NetworkCollection.HasFluidPipeAt(pipePos, out FluidNetwork net) ||
                net.liquidType != MachineLiquidID.None ||
                net.gasType == MachineGasID.None ||
                !entry.isInput ||
                (entry.id != MachineGasID.None && entry.id != net.gasType) ||
                (entry.validTypes?.Length > 0 && Array.FindIndex(entry.validTypes, id => id == net.gasType) == -1))
            {
                return;
            }

            Tile    tile    = Framing.GetTileSafely(pipePos);
            ModTile modTile = ModContent.GetModTile(tile.type);

            float rate = modTile is FluidTransportTile transport
                                ? transport.ExportRate
                                : (modTile is FluidPumpTile
                                        ? ModContent.GetInstance <FluidTransportTile>().ExportRate
                                        : -1);

            if (rate <= 0)
            {
                return;
            }

            float exported = Math.Min(rate, net.Capacity);

            if (exported + entry.current > entry.max)
            {
                exported = entry.max - entry.current;
            }

            if (exported <= 0)
            {
                return;
            }

            if (entry.id == MachineGasID.None)
            {
                entry.id = net.gasType;
            }

            entry.current   += exported;
            net.StoredFluid -= exported;

            if (net.StoredFluid <= 0)
            {
                net.gasType = MachineGasID.None;
            }
        }
Пример #18
0
 public override void SetDefaults()
 {
     if (Main.worldName == SpookyTerrariaUtils.slenderWorldName)
     {
         ModTile n = new ModTile {
             mineResist = float.MaxValue, minPick = int.MaxValue
         };
     }
 }
Пример #19
0
        public static void QuickSetFurniture(this ModTile tile, int width, int height, int dustType, int soundType, bool tallBottom, Color mapColor, bool solidTop = false, bool solid = false, string mapName = "", AnchorData bottomAnchor = default, AnchorData topAnchor = default, int[] anchorTiles = null, Point16 Origin = default)
        {
            Main.tileLavaDeath[tile.Type]      = false;
            Main.tileFrameImportant[tile.Type] = true;
            Main.tileSolidTop[tile.Type]       = solidTop;
            Main.tileSolid[tile.Type]          = solid;

            TileObjectData.newTile.Width  = width;
            TileObjectData.newTile.Height = height;


            TileObjectData.newTile.CoordinateHeights = new int[height];

            for (int k = 0; k < height; k++)
            {
                TileObjectData.newTile.CoordinateHeights[k] = 16;
            }

            if (tallBottom) //this breaks for some tiles: the two leads are multitiles and tiles with random styles
            {
                TileObjectData.newTile.CoordinateHeights[height - 1] = 18;
            }

            TileObjectData.newTile.UsesCustomCanPlace = true;
            TileObjectData.newTile.CoordinateWidth    = 16;
            TileObjectData.newTile.CoordinatePadding  = 2;
            TileObjectData.newTile.Origin             = Origin == default(Point16) ? new Point16(width / 2, height - 1) : Origin;

            if (bottomAnchor != default)
            {
                TileObjectData.newTile.AnchorBottom = bottomAnchor;
            }

            /*else
             *  TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidSide, TileObjectData.newTile.Width, 0);*/

            if (topAnchor != default)
            {
                TileObjectData.newTile.AnchorTop = topAnchor;
            }

            if (anchorTiles != null)
            {
                TileObjectData.newTile.AnchorAlternateTiles = anchorTiles;
            }


            TileObjectData.addTile(tile.Type);

            ModTranslation name = tile.CreateMapEntryName();

            name.SetDefault(mapName);
            tile.AddMapEntry(mapColor, name);
            tile.dustType           = dustType;
            tile.soundType          = soundType;
            tile.disableSmartCursor = true;
        }
Пример #20
0
        public static void QuickSetBreakableVase(this ModTile tile, int dustType, Color mapColor, int randomVariants, int width = 2, int height = 2, int soundType = SoundID.Shatter, string mapName = "Pot", bool tileCut = true, bool tallBottom = false, int paddingX = 2, AnchorData bottomAnchor = default, AnchorData topAnchor = default, int[] anchorTiles = null)
        {
            Main.tileCut[tile.Type] = tileCut;

            TileObjectData.newTile.CopyFrom(TileObjectData.Style2x2);
            TileObjectData.newTile.StyleHorizontal   = true;
            TileObjectData.newTile.RandomStyleRange  = randomVariants;
            TileObjectData.newTile.CoordinatePadding = paddingX;
            tile.QuickSetFurniture(width, height, dustType, soundType, tallBottom, mapColor, false, false, mapName, bottomAnchor, topAnchor, anchorTiles);
        }
Пример #21
0
        private void RefreshRates()
        {
            if (!needsRateRefresh)
            {
                return;
            }

            needsRateRefresh = false;

            TerraFlux import = new TerraFlux(0f);
            TerraFlux export = new TerraFlux(0f);

            int count = 0;

            var inst = ModContent.GetInstance <TFWireTile>();

            foreach (var wire in Hash)
            {
                ModTile tile = ModContent.GetModTile(Framing.GetTileSafely(wire.Position).type);

                if (tile is null)
                {
                    continue;
                }

                if (tile is TransportJunction)
                {
                    import += inst.ImportRate;
                    export += inst.ExportRate;
                }
                else if (tile is TFWireTile wireTile)
                {
                    import += wireTile.ImportRate;
                    export += wireTile.ExportRate;
                }
                else
                {
                    continue;
                }

                count++;
            }

            if (count == 0)
            {
                ImportRate = new TerraFlux(0f);
                ExportRate = new TerraFlux(0f);
            }
            else
            {
                ImportRate = import / count;
                ExportRate = export / count;
            }
        }
Пример #22
0
 public static void SetupConnectors()
 {
     for (ushort i = 0; i < TileLoader.TileCount; i++)
     {
         ModTile mt = TileLoader.GetTile(i);
         if (mt is TStorageComponent || mt is TStorageConnector)
         {
             tilesToConnect.Add(i);
         }
     }
 }
Пример #23
0
        public override void SetDefaults()
        {
            bool slenderWorld = Main.worldName == SpookyTerrariaUtils.slenderWorldName;

            if (slenderWorld)
            {
                ModTile n = new ModTile();
                n.mineResist = float.MaxValue;
                n.minPick    = int.MaxValue;
            }
        }
Пример #24
0
 public static ushort FindTileIDInArray(string whatItNeedToEndWith, string whatItDoesntNeedToContain, IList <int> tile)
 {
     foreach (var tileID in tile)
     {
         ModTile modTile = TileLoader.GetTile(tileID);
         if (modTile != null && modTile.Name.EndsWith(whatItNeedToEndWith) && !modTile.Name.Contains(whatItDoesntNeedToContain))
         {
             return(modTile.Type);
         }
     }
     return(0);
 }
Пример #25
0
        public override void PreUpdate()
        {
            if (!Main.mapFullscreen)
            {
                int myX = Player.tileTargetX;
                int myY = Player.tileTargetY;
                if (player.position.X / 16f - Player.tileRangeX <= myX && (player.position.X + player.width) / 16f + Player.tileRangeX - 1f >= myX && player.position.Y / 16f - Player.tileRangeY <= myY && (player.position.Y + player.height) / 16f + Player.tileRangeY - 2f >= myY)
                {
                    if (Main.mouseLeft && Main.mouseLeftRelease)
                    {
                        if (Main.tile[myX, myY] == null)
                        {
                            Main.tile[myX, myY] = new Tile();
                        }
                        if (Main.tile[myX, myY].active())
                        {
                            int     type = Main.tile[myX, myY].type;
                            ModTile tile = TileLoader.GetTile(type);
                            (tile as BaseTile)?.LeftClick(myX, myY);
                        }
                    }

                    if (Main.mouseRight)
                    {
                        if (Main.tile[myX, myY] == null)
                        {
                            Main.tile[myX, myY] = new Tile();
                        }
                        if (Main.tile[myX, myY].active())
                        {
                            int     type = Main.tile[myX, myY].type;
                            ModTile tile = TileLoader.GetTile(type);
                            (tile as BaseTile)?.RightClickCont(myX, myY);
                        }
                    }

                    if (Main.mouseLeft)
                    {
                        if (Main.tile[myX, myY] == null)
                        {
                            Main.tile[myX, myY] = new Tile();
                        }
                        if (Main.tile[myX, myY].active())
                        {
                            int     type = Main.tile[myX, myY].type;
                            ModTile tile = TileLoader.GetTile(type);
                            (tile as BaseTile)?.LeftClickCont(myX, myY);
                        }
                    }
                }
            }
        }
Пример #26
0
        public override bool UseItem(Player player)
        {
            Vector2 position     = GetLightPosition(player);
            Point   tileLocation = position.ToTileCoordinates();
            ModTile tile         = TileLoader.GetTile(Main.tile[tileLocation.X, tileLocation.Y].type);

            if (tile is IInstrument instrument)
            {
                instrument.PitchOffset(tileLocation.X, tileLocation.Y);
                return(true);
            }
            return(false);
        }
Пример #27
0
        public static void QuickSetFurniture(this ModTile tile, int width, int height, int dustType, int soundType, Color mapColor, int bottomHeight = 16, bool solidTop = false, bool solid = false, string mapName = "", AnchorData bottomAnchor = default, AnchorData topAnchor = default, int[] anchorTiles = null)
        {
            Main.tileLavaDeath[tile.Type]      = false;
            Main.tileFrameImportant[tile.Type] = true;
            Main.tileSolidTop[tile.Type]       = solidTop;
            Main.tileSolid[tile.Type]          = solid;

            TileObjectData.newTile.Width  = width;
            TileObjectData.newTile.Height = height;


            TileObjectData.newTile.CoordinateHeights = new int[height];

            for (int k = 0; k < height; k++)
            {
                TileObjectData.newTile.CoordinateHeights[k] = 16;
            }

            TileObjectData.newTile.CoordinateHeights[height - 1] = bottomHeight;

            TileObjectData.newTile.UsesCustomCanPlace = true;
            TileObjectData.newTile.CoordinateWidth    = 16;
            TileObjectData.newTile.CoordinatePadding  = 2;
            TileObjectData.newTile.Origin             = new Point16(width / 2, height / 2);

            if (bottomAnchor != default)
            {
                TileObjectData.newTile.AnchorBottom = bottomAnchor;
            }

            if (topAnchor != default)
            {
                TileObjectData.newTile.AnchorTop = topAnchor;
            }

            if (anchorTiles != null)
            {
                TileObjectData.newTile.AnchorAlternateTiles = anchorTiles;
            }


            TileObjectData.addTile(tile.Type);

            ModTranslation name = tile.CreateMapEntryName();

            name.SetDefault(mapName);
            tile.AddMapEntry(mapColor, name);
            tile.dustType           = dustType;
            tile.soundType          = soundType;
            tile.disableSmartCursor = true;
        }
Пример #28
0
        internal static bool WriteModMap(BinaryWriter writer)
        {
            ISet <ushort> types = new HashSet <ushort>();

            for (int i = 0; i < Main.maxTilesX; i++)
            {
                for (int j = 0; j < Main.maxTilesY; j++)
                {
                    ushort type = Main.Map[i, j].Type;
                    if (type >= MapHelper.modPosition)
                    {
                        types.Add(type);
                    }
                }
            }
            if (types.Count == 0)
            {
                return(false);
            }
            writer.Write((ushort)types.Count);
            foreach (ushort type in types)
            {
                writer.Write(type);
                if (MapLoader.entryToTile.ContainsKey(type))
                {
                    ModTile tile = TileLoader.GetTile(MapLoader.entryToTile[type]);
                    writer.Write(true);
                    writer.Write(tile.Mod.Name);
                    writer.Write(tile.Name);
                    writer.Write((ushort)(type - MapHelper.tileLookup[tile.Type]));
                }
                else if (MapLoader.entryToWall.ContainsKey(type))
                {
                    ModWall wall = WallLoader.GetWall(MapLoader.entryToWall[type]);
                    writer.Write(false);
                    writer.Write(wall.Mod.Name);
                    writer.Write(wall.Name);
                    writer.Write((ushort)(type - MapHelper.wallLookup[wall.Type]));
                }
                else
                {
                    writer.Write(true);
                    writer.Write("");
                    writer.Write("");
                    writer.Write((ushort)0);
                }
            }
            WriteMapData(writer);
            return(true);
        }
        public static string GetUniqueKey(int type)
        {
            if (type < 0 || type >= TileLoader.TileCount)
            {
                throw new ArgumentOutOfRangeException("Invalid type: " + type);
            }
            if (type < TileID.Count)
            {
                return("Terraria " + TileIdentityHelpers.TileIdSearch.GetName(type));
            }

            ModTile modTile = TileLoader.GetTile(type);

            return($"{modTile.mod.Name} {modTile.Name}");
        }
        /// <summary>
        /// Called on Mod.Load
        /// </summary>
        public void Load()
        {
            if (!Main.dedServ)
            {
                interfaces = new Dictionary <string, UserInterface>();
                states     = new Dictionary <string, MachineUI>();

                var types = TechMod.types;
                foreach (var type in types)
                {
                    //Ignore abstract classes
                    if (type.IsAbstract)
                    {
                        continue;
                    }

                    if (typeof(MachineUI).IsAssignableFrom(type))
                    {
                        //Not abstract and doesn't have a parameterless ctor?  Throw an exception
                        if (type.GetConstructor(Type.EmptyTypes) is null)
                        {
                            throw new TypeLoadException($"Machine UI type \"{type.FullName}\" does not have a parameterless constructor.");
                        }

                        //Machine UI type.  Try to link the UI to the machine
                        MachineUI state   = Activator.CreateInstance(type) as MachineUI;
                        ModTile   machine = ModContent.GetModTile(state.TileType);

                        if (machine is null)
                        {
                            throw new TypeLoadException($"Machine UI type \"{type.FullName}\" had an invalid return value for its \"TileType\" getter property.");
                        }

                        //Register the UI
                        string name = machine.GetType().Name;
                        state.MachineName = name;
                        interfaces.Add(name, new UserInterface());
                        states.Add(name, state);
                    }
                }

                // Activate calls Initialize() on the UIState if not initialized, then calls OnActivate and then calls Activate on every child element
                foreach (var state in states.Values)
                {
                    state.Activate();
                }
            }
        }