Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.85 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using System;
  3. using Terraria;
  4. using Terraria.DataStructures;
  5. using Terraria.Enums;
  6. using Terraria.ID;
  7. using Terraria.Localization;
  8. using Terraria.ModLoader;
  9. using Terraria.ObjectData;
  10. using static Terraria.ModLoader.ModContent;
  11.  
  12. namespace EnderQuarry.Tiles
  13. {
  14.     public class TestQuarry : ModTile
  15.     {
  16.         private Rectangle PickupArea(int x, int y)
  17.         {
  18.             return new Rectangle(x*16, y*16, 32, 32);
  19.         }
  20.         public override void SetDefaults()
  21.         {
  22.             Main.tileSolidTop[Type] = true;
  23.             Main.tileFrameImportant[Type] = true;
  24.             Main.tileNoAttach[Type] = true;
  25.             Main.tileTable[Type] = true;
  26.             Main.tileContainer[Type] = true;
  27.             Main.tileLavaDeath[Type] = true;
  28.             TileID.Sets.HasOutlines[Type] = true;
  29.             TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2);
  30.             TileObjectData.newTile.Origin = new Point16(1, 1);
  31.             TileObjectData.newTile.CoordinateHeights = new[] { 16, 16 };
  32.             TileObjectData.newTile.HookCheck = new PlacementHook(new Func<int, int, int, int, int, int>(Chest.FindEmptyChest), -1, 0, true);
  33.             TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(new Func<int, int, int, int, int, int>(Chest.AfterPlacement_Hook), -1, 0, false);
  34.             TileObjectData.newTile.AnchorInvalidTiles = new[] { 127 };
  35.             TileObjectData.newTile.StyleHorizontal = true;
  36.             TileObjectData.newTile.LavaDeath = false;
  37.             TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop | AnchorType.SolidSide, TileObjectData.newTile.Width, 0);
  38.             TileObjectData.addTile(Type);
  39.             AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable);
  40.             ModTranslation name = CreateMapEntryName();
  41.             name.SetDefault("Test Quarry");
  42.             AddMapEntry(new Color(200, 200, 200), name);
  43.             disableSmartCursor = true;
  44.         }
  45.  
  46.         public override bool HasSmartInteract()
  47.         {
  48.             return true;
  49.         }
  50.  
  51.         public override void NumDust(int i, int j, bool fail, ref int num)
  52.         {
  53.             num = 1;
  54.         }
  55.  
  56.         public override void KillMultiTile(int i, int j, int frameX, int frameY)
  57.         {
  58.             Item.NewItem(i * 16, j * 16, 64, 32, ItemType<Items.TestQuarry>());
  59.         }
  60.  
  61.         public override bool NewRightClick(int i, int j)
  62.         {
  63.             Main.NewText("Block Right Click", Color.Aqua, false);
  64.  
  65.             int XCord = i;
  66.             int YCord = j;
  67.  
  68.             if(Main.tile[XCord, YCord].type == ModContent.TileType<Tiles.TestQuarry>())
  69.             {
  70.                 if (Main.tile[XCord + 1, YCord].type != ModContent.TileType<Tiles.TestQuarry>())
  71.                 {
  72.                     XCord -= 1;
  73.                 }
  74.                 if (Main.tile[XCord - 1, YCord].type != ModContent.TileType<Tiles.TestQuarry>())
  75.                 {
  76.                     XCord += 1;
  77.                 }
  78.                 if (Main.tile[XCord, YCord + 1].type != ModContent.TileType<Tiles.TestQuarry>())
  79.                 {
  80.                     YCord -= 1;
  81.                 }
  82.                 if (Main.tile[XCord, YCord - 1].type != ModContent.TileType<Tiles.TestQuarry>())
  83.                 {
  84.                     YCord += 1;
  85.                 }
  86.             }
  87.  
  88.             for (int block = 0; block < 25; block++)
  89.             {
  90.                 WorldGen.KillTile(XCord, YCord + 3 + block);
  91.                 for (int id = 0; id < Main.item.Length; id++)
  92.                 {
  93.                     if (Main.item[id].active && Main.item[id].noGrabDelay == 0)
  94.                     {
  95.                         Item item = Main.item[id];
  96.                         Main.NewText(Main.item[id].Name + " is on floor yikes.", Color.Aqua, false);
  97.  
  98.                         if (PickupArea(XCord, YCord + 3 + block).Intersects(item.getRect()))
  99.                         {
  100.  
  101.                             if (Main.tile[XCord - 2, YCord].type != TileID.Containers)
  102.                             {
  103.                                 Main.NewText(Main.item[id].Name + " should be picked up. Cords: " + Main.item[id].position, Color.Red, false);
  104.                                 Vector2 newPos = new Vector2(XCord * 16, YCord * 16);
  105.                                 Main.item[id].position = newPos;
  106.                                 Main.NewText(Main.item[id].Name + " picked up. At cords: " + Main.item[id].position, Color.Red, false);
  107.                             }
  108.                             else if (Main.tile[XCord - 2, YCord].type == TileID.Containers && item.maxStack > 1)
  109.                             {
  110.                                 Chest chest = Main.chest[Chest.FindChestByGuessing(XCord - 2, YCord)];
  111.  
  112.                                 for (int inventoryIndex = 0; inventoryIndex < 40; inventoryIndex++)
  113.                                 {
  114.                                     if (chest.item[inventoryIndex].IsTheSameAs(Main.item[id]) && chest.item[inventoryIndex].stack < chest.item[inventoryIndex].maxStack)
  115.                                     {
  116.                                         int spaceLeft = chest.item[inventoryIndex].maxStack - chest.item[inventoryIndex].stack;
  117.                                         if (spaceLeft >= item.stack)
  118.                                         {
  119.                                            
  120.                                             chest.item[inventoryIndex].stack += item.stack;
  121.                                             item.TurnToAir();
  122.                                         }
  123.                                         else
  124.                                         {
  125.                                             item.stack -= spaceLeft;
  126.                                             chest.item[inventoryIndex].stack = chest.item[inventoryIndex].maxStack;
  127.                                         }
  128.                                         Main.NewText(Main.item[id].Name + " changed.", Color.Red, false);
  129.                                         break;
  130.                                     }
  131.  
  132.                                     if (!chest.item[inventoryIndex].IsTheSameAs(Main.item[id])) //fix the adding to chest
  133.                                     {
  134.                                         Vector2 newPos = new Vector2(XCord - 2, YCord);
  135.                                         Main.NewText(newPos.Length() + " length.", Color.Red, false);
  136.                                         Chest.PutItemInNearbyChest(item, newPos);
  137.                                         item.TurnToAir();
  138.                                         break;
  139.                                     }
  140.                                 }
  141.                             }
  142.                         }
  143.                     }
  144.                 }
  145.             }
  146.  
  147.             return true;
  148.         }
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement