Skip to content

Commit

Permalink
Added an Item that enables Infinite Placement
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirtle committed Jun 10, 2020
1 parent 45f58cb commit 535d730
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 5 deletions.
19 changes: 19 additions & 0 deletions Buffs/InfinitePlacementBuff.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Terraria;
using Terraria.ModLoader;

namespace BuilderEssentials.Buffs
{
class InfinitePlacementBuff : ModBuff
{
public override void SetDefaults()
{
DisplayName.SetDefault("Infinite Placement");
Description.SetDefault("Where are all these materials coming from?");
Main.debuff[Type] = true;
Main.buffNoSave[Type] = true;
Main.buffNoTimeDisplay[Type] = true;
Main.buffAlpha[Type] = 0;
canBeCleared = false;
}
}
}
Binary file added Buffs/InfinitePlacementBuff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 122 additions & 0 deletions Items/InfinitePlacement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@

using Microsoft.Xna.Framework;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace BuilderEssentials.Items
{
class InfinitePlacement : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("Allows infinite placement");
}

public override void SetDefaults()
{
item.accessory = true;
item.vanity = false;
item.width = 48;
item.height = 48;
item.value = Item.sellPrice(0, 10, 0, 0);
item.rare = ItemRarityID.Red;
}

protected (int index, Item accessory) FindDifferentEquippedExclusiveAccessory()
{
int maxAccessoryIndex = 5 + Main.LocalPlayer.extraAccessorySlots;
for (int i = 3; i < 3 + maxAccessoryIndex; i++)
{
Item otherAccessory = Main.LocalPlayer.armor[i];
if (!otherAccessory.IsAir &&
!item.IsTheSameAs(otherAccessory) &&
otherAccessory.modItem is InfinitePlacement)
{
return (i, otherAccessory);
}
}
return (-1, null);
}

public override bool CanEquipAccessory(Player player, int slot)
{
if (slot < 10)
{
int index = FindDifferentEquippedExclusiveAccessory().index;
if (index != -1)
return slot == index;
}
return base.CanEquipAccessory(player, slot);
}

public override bool CanRightClick()
{
int maxAccessoryIndex = 5 + Main.LocalPlayer.extraAccessorySlots;
for (int i = 13; i < 13 + maxAccessoryIndex; i++)
{
if (Main.LocalPlayer.armor[i].type == item.type)
return false;
}

if (FindDifferentEquippedExclusiveAccessory().accessory != null)
return true;

return base.CanRightClick();
}

public override void RightClick(Player player)
{
var (index, accessory) = FindDifferentEquippedExclusiveAccessory();
if (accessory != null)
{
Main.LocalPlayer.QuickSpawnClonedItem(accessory);
Main.LocalPlayer.armor[index] = item.Clone();
}
}

public override void UpdateAccessory(Player player, bool hideVisual)
{
player.AddBuff(mod.BuffType("InfinitePlacementBuff"), 1);
}

public override void AddRecipes()
{
//Not really worried about balancing at this point
ModRecipe modRecipe = new ModRecipe(mod);
modRecipe.AddIngredient(ItemID.LunarBar, 40);
modRecipe.AddIngredient(ItemID.FragmentNebula, 20);
modRecipe.AddIngredient(ItemID.FragmentSolar, 20);
modRecipe.AddIngredient(ItemID.FragmentStardust, 20);
modRecipe.AddIngredient(ItemID.FragmentVortex, 20);
modRecipe.AddTile(TileID.LunarCraftingStation);
modRecipe.SetResult(this);
modRecipe.AddRecipe();
}
}

public partial class InfinitePlacementTile : GlobalTile
{
public override void PlaceInWorld(int i, int j, Item item)
{
if (Main.LocalPlayer.HasBuff(mod.BuffType("InfinitePlacementBuff"))) {
item.stack += 1;
base.PlaceInWorld(i, j, item);
}
}
}

public partial class InfinitePlacementWall : GlobalWall
{
public override void PlaceInWorld(int i, int j, int type, Item item)
{
if (Main.LocalPlayer.HasBuff(mod.BuffType("InfinitePlacementBuff")))
{
item.stack += 1;
base.PlaceInWorld(i, j, type, item);
}
}
}
}
Binary file added Items/InfinitePlacement.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Items/InfinitePlacement2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions UI/BasePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Terraria.UI;
using Terraria.GameContent.UI.Elements;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace BuilderEssentials.UI
{
Expand All @@ -21,6 +22,8 @@ public override void OnInitialize()
Append(button);
}

//TODO: PREVENT ITEM SWINGS WHEN CLICKING ON THE UIIMAGEBUTTON

public void ChangeAccessories_OnClick(UIMouseEvent evt, UIElement listeningElement)
{
modPlayer = Main.LocalPlayer.GetModPlayer<BuilderPlayer>();
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
displayName = Builder Essentials
author = Kirtle
version = 0.1.2
version = 0.1.3
buildIgnore = *.csproj, *.user, obj\*, bin\*, .vs\*
7 changes: 3 additions & 4 deletions description.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
Builder Essentials is a mod designed to help and improve building in survival.

It features a toggleable secondary accessories system so you can always have your building accessories ready to be used, without filling your inventory!
It features a toggleable secondary accessories system so you can always have your building accessories ready to be used (requires you to add your own accessories), without filling your inventory!

In the future, I hope to implement more helpful features to complement this mod.

Happy Building! Kirtle

Changelog:
- Added Vanity Accessories and Clothes to the "Build Mode"
- Added Multiplayer support
Latest Changelog:
- Added an Infinite Placement Accessory (Post MoonLord)

0 comments on commit 535d730

Please sign in to comment.