Skip to content

Commit

Permalink
Added CanBeSloped to mod/global tiles (tModLoader#2444)
Browse files Browse the repository at this point in the history
* Added CanBeSloped to mod/global tiles

* Summary changes

* Changed CanBeSloped to ModifySloping with ref parameter, added ExampleSlopedTile

* Changed back to CanBeSloped

* Implement via TileID.Sets instead of hook

* Missed file

Co-authored-by: Chicken-Bones <[email protected]>
  • Loading branch information
Ved-s and Chicken-Bones authored Jun 20, 2022
1 parent 0a47a19 commit 41ab2b7
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
36 changes: 36 additions & 0 deletions ExampleMod/Content/Items/Placeable/ExampleSlopedTile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria.ID;
using Terraria.ModLoader;

namespace ExampleMod.Content.Items.Placeable
{
public class ExampleSlopedTile : ModItem
{
public override void SetStaticDefaults() {
Tooltip.SetDefault("Example tile that can be sloped but is not solid");
}

public override void SetDefaults() {
Item.width = 12;
Item.height = 12;
Item.maxStack = 999;
Item.useTurn = true;
Item.autoReuse = true;
Item.useAnimation = 15;
Item.useTime = 10;
Item.useStyle = ItemUseStyleID.Swing;
Item.consumable = true;
Item.createTile = ModContent.TileType<Tiles.ExampleSlopeTile>();
}

public override void AddRecipes() {
CreateRecipe(1)
.AddIngredient(ModContent.ItemType<ExampleBlock>(), 1)
.Register();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions ExampleMod/Content/Tiles/ExampleSlopeTile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;

namespace ExampleMod.Content.Tiles
{
public class ExampleSlopeTile : ModTile
{
public override void SetStaticDefaults() {
Main.tileFrameImportant[Type] = true;
TileID.Sets.CanBeSloped[Type] = true; // allow this tile to be sloped, because it isn't solid

ItemDrop = ModContent.ItemType<Items.Placeable.ExampleSlopedTile>();
}

public override bool Slope(int i, int j) {
Tile tile = Framing.GetTileSafely(i, j);
tile.TileFrameX = (short)((tile.TileFrameX + 18) % 72);
SoundEngine.PlaySound(SoundID.MenuTick);
return false;
}

public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak) {
return false;
}
}
}
Binary file added ExampleMod/Content/Tiles/ExampleSlopeTile.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 patches/tModLoader/Terraria/ID/TileID.TML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ partial class Sets
public static bool[] Grass = Factory.CreateBoolSet(2, 23, 109, 199, 477, 492);
public static bool[] CanBeClearedDuringOreRunner = Factory.CreateBoolSet(0, 1, 23, 25, 40, 53, 57, 59, 60, 70, 109, 112, 116, 117, 147, 161, 163, 164, 199, 200, 203, 234);

/// <summary> Allows non-solid tiles to be sloped (solid tiles can always be sloped, regardless of this set). </summary>
public static bool[] CanBeSloped = Factory.CreateBoolSet();

/// <summary>
/// Whether or not the tile will be ignored for automatic step up regarding town NPC collision.
/// <br>Only checked when <see cref="Collision.StepUp"/> with specialChecksMode set to 1 is called</br>
Expand Down
22 changes: 22 additions & 0 deletions patches/tModLoader/Terraria/Player.cs.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4505,6 +4505,15 @@
if (sItem.type == 1450 && Main.rand.Next(3) == 0) {
int num3 = -1;
float x = itemRectangle.X + Main.rand.Next(itemRectangle.Width);
@@ -32078,7 +_,7 @@

if (toolTime == 0 && itemAnimation > 0 && controlUseItem) {
Tile tile = Main.tile[tileTargetX, tileTargetY];
- if (!tile.active() || IsTilePoundable(tile))
+ if (!tile.active() || IsTilePoundable(tile) && !TileID.Sets.CanBeSloped[tile.type])
poundRelease = false;
}

@@ -32127,7 +_,7 @@
if (Main.tileHammer[tile.type]) {
canHitWalls = false;
Expand All @@ -4526,6 +4535,19 @@
if (sItem.axe > 0) {
AchievementsHelper.CurrentlyMining = true;
if (!WorldGen.CanKillTile(x, y))
@@ -32310,7 +_,11 @@

private void ItemCheck_UseMiningTools_TryPoundingTile(Item sItem, int tileHitId, ref bool hitWall, int x, int y) {
Tile tile = Main.tile[x, y];
- if (sItem.hammer > 0 && tile.active() && (Main.tileSolid[tile.type] || tile.type == 314 || tile.type == 351 || tile.type == 424 || tile.type == 442) && poundRelease) {
+
+ bool canTrySloping = sItem.hammer > 0 && tile.active() && poundRelease;
+ bool vanillaSloping = Main.tileSolid[tile.type] || tile.type == 314 || tile.type == 351 || tile.type == 424 || tile.type == 442;
+
+ if (canTrySloping && (vanillaSloping || TileID.Sets.CanBeSloped[tile.type])) {
hitWall = false;
ApplyItemTime(sItem);
int damageAmount = 100;
@@ -32322,7 +_,10 @@
if (!poundRelease)
return;
Expand Down

0 comments on commit 41ab2b7

Please sign in to comment.