Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework;
- using System;
- using Terraria;
- using Terraria.DataStructures;
- using Terraria.Enums;
- using Terraria.ID;
- using Terraria.Localization;
- using Terraria.ModLoader;
- using Terraria.ObjectData;
- using static Terraria.ModLoader.ModContent;
- namespace EnderQuarry.Tiles
- {
- public class TestQuarry : ModTile
- {
- private Rectangle PickupArea(int x, int y)
- {
- return new Rectangle(x*16, y*16, 32, 32);
- }
- public override void SetDefaults()
- {
- Main.tileSolidTop[Type] = true;
- Main.tileFrameImportant[Type] = true;
- Main.tileNoAttach[Type] = true;
- Main.tileTable[Type] = true;
- Main.tileContainer[Type] = true;
- Main.tileLavaDeath[Type] = true;
- TileID.Sets.HasOutlines[Type] = true;
- TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2);
- TileObjectData.newTile.Origin = new Point16(1, 1);
- TileObjectData.newTile.CoordinateHeights = new[] { 16, 16 };
- TileObjectData.newTile.HookCheck = new PlacementHook(new Func<int, int, int, int, int, int>(Chest.FindEmptyChest), -1, 0, true);
- TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(new Func<int, int, int, int, int, int>(Chest.AfterPlacement_Hook), -1, 0, false);
- TileObjectData.newTile.AnchorInvalidTiles = new[] { 127 };
- TileObjectData.newTile.StyleHorizontal = true;
- TileObjectData.newTile.LavaDeath = false;
- TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop | AnchorType.SolidSide, TileObjectData.newTile.Width, 0);
- TileObjectData.addTile(Type);
- AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable);
- ModTranslation name = CreateMapEntryName();
- name.SetDefault("Test Quarry");
- AddMapEntry(new Color(200, 200, 200), name);
- disableSmartCursor = true;
- }
- public override bool HasSmartInteract()
- {
- return true;
- }
- public override void NumDust(int i, int j, bool fail, ref int num)
- {
- num = 1;
- }
- public override void KillMultiTile(int i, int j, int frameX, int frameY)
- {
- Item.NewItem(i * 16, j * 16, 64, 32, ItemType<Items.TestQuarry>());
- }
- public override bool NewRightClick(int i, int j)
- {
- Main.NewText("Block Right Click", Color.Aqua, false);
- int XCord = i;
- int YCord = j;
- if(Main.tile[XCord, YCord].type == ModContent.TileType<Tiles.TestQuarry>())
- {
- if (Main.tile[XCord + 1, YCord].type != ModContent.TileType<Tiles.TestQuarry>())
- {
- XCord -= 1;
- }
- if (Main.tile[XCord - 1, YCord].type != ModContent.TileType<Tiles.TestQuarry>())
- {
- XCord += 1;
- }
- if (Main.tile[XCord, YCord + 1].type != ModContent.TileType<Tiles.TestQuarry>())
- {
- YCord -= 1;
- }
- if (Main.tile[XCord, YCord - 1].type != ModContent.TileType<Tiles.TestQuarry>())
- {
- YCord += 1;
- }
- }
- for (int block = 0; block < 25; block++)
- {
- WorldGen.KillTile(XCord, YCord + 3 + block);
- for (int id = 0; id < Main.item.Length; id++)
- {
- if (Main.item[id].active && Main.item[id].noGrabDelay == 0)
- {
- Item item = Main.item[id];
- Main.NewText(Main.item[id].Name + " is on floor yikes.", Color.Aqua, false);
- if (PickupArea(XCord, YCord + 3 + block).Intersects(item.getRect()))
- {
- if (Main.tile[XCord - 2, YCord].type != TileID.Containers)
- {
- Main.NewText(Main.item[id].Name + " should be picked up. Cords: " + Main.item[id].position, Color.Red, false);
- Vector2 newPos = new Vector2(XCord * 16, YCord * 16);
- Main.item[id].position = newPos;
- Main.NewText(Main.item[id].Name + " picked up. At cords: " + Main.item[id].position, Color.Red, false);
- }
- else if (Main.tile[XCord - 2, YCord].type == TileID.Containers && item.maxStack > 1)
- {
- Chest chest = Main.chest[Chest.FindChestByGuessing(XCord - 2, YCord)];
- for (int inventoryIndex = 0; inventoryIndex < 40; inventoryIndex++)
- {
- if (chest.item[inventoryIndex].IsTheSameAs(Main.item[id]) && chest.item[inventoryIndex].stack < chest.item[inventoryIndex].maxStack)
- {
- int spaceLeft = chest.item[inventoryIndex].maxStack - chest.item[inventoryIndex].stack;
- if (spaceLeft >= item.stack)
- {
- chest.item[inventoryIndex].stack += item.stack;
- item.TurnToAir();
- }
- else
- {
- item.stack -= spaceLeft;
- chest.item[inventoryIndex].stack = chest.item[inventoryIndex].maxStack;
- }
- Main.NewText(Main.item[id].Name + " changed.", Color.Red, false);
- break;
- }
- if (!chest.item[inventoryIndex].IsTheSameAs(Main.item[id])) //fix the adding to chest
- {
- Vector2 newPos = new Vector2(XCord - 2, YCord);
- Main.NewText(newPos.Length() + " length.", Color.Red, false);
- Chest.PutItemInNearbyChest(item, newPos);
- item.TurnToAir();
- break;
- }
- }
- }
- }
- }
- }
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement