Skip to content

Commit 9120ca0

Browse files
Merge pull request #64 from THEXN/master
Update BridgeBuilder 支持竖直放置图格
2 parents 7583bb6 + 8fcca29 commit 9120ca0

File tree

2 files changed

+54
-41
lines changed

2 files changed

+54
-41
lines changed

BridgeBuilder/BridgeBuilder.cs

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace BridgeBuilder
1010
public class BridgeBuilder : TerrariaPlugin
1111
{
1212
public override string Name => "BridgeBuilder";
13-
public override Version Version => new Version(1, 0, 5);
13+
public override Version Version => new Version(1, 0, 6);
1414
public override string Author => "Soofa,肝帝熙恩汉化1449";
1515
public override string Description => "铺桥!";
1616
public static Configuration Config;
@@ -46,10 +46,23 @@ private async void BridgeCmd(CommandArgs args)
4646
await Task.Run(() =>
4747
{
4848
TSPlayer plr = args.Player;
49-
int direction = plr.TPlayer.direction;
50-
int startX = direction == -1 ? plr.TileX - 1 : plr.TileX + 2;
49+
int directionX = plr.TPlayer.direction;
50+
int directionY = 0;
51+
52+
if (args.Parameters.Count > 0)
53+
{
54+
string direction = args.Parameters[0].ToLower();
55+
if (direction == "up" || direction == "down")
56+
{
57+
directionY = direction == "up" ? -1 : 1; // 确保正确的垂直方向
58+
directionX = 0; // 在垂直建造时,水平方向不移动
59+
}
60+
}
61+
62+
int startX = directionX == 0 ? plr.TileX : (directionX == -1 ? plr.TileX - 1 : plr.TileX + 2);
5163
int i = 0;
52-
int j = plr.TileY + 3;
64+
int j = plr.TileY + (directionY == -1 ? -1 : (directionY == 1 ? 3 : 3));
65+
5366
Item selectedItem = plr.SelectedItem;
5467

5568
if (selectedItem.createTile < 0 && selectedItem.createWall < 0)
@@ -61,72 +74,68 @@ await Task.Run(() =>
6174
bool isTile = selectedItem.createTile >= 0;
6275
int styleId = selectedItem.placeStyle;
6376

64-
if (j > Main.maxTilesY || j < 0)
77+
if (j < 0 || j >= Main.maxTilesY)
6578
{
6679
plr.SendErrorMessage("无法在这里建造桥梁。");
6780
return;
6881
}
6982

70-
if (isTile)
83+
int placedCount = 0;
84+
85+
while (CheckTileAvailability(startX + i * directionX, j, plr) && selectedItem.stack > 0)
7186
{
72-
if (!Config.AllowedTileIDs.Contains(selectedItem.createTile))
87+
if (isTile)
88+
{
89+
WorldGen.PlaceTile(startX + i * directionX, j, selectedItem.createTile, false, true, -1, styleId);
90+
}
91+
else
7392
{
74-
plr.SendErrorMessage("你手持的物块无法自动建造桥梁。(一般仅允许使用平台或团队块或种植盆。)");
75-
return;
93+
Main.tile[startX + i * directionX, j].wall = (ushort)selectedItem.createWall;
7694
}
7795

78-
int tileCount = 0;
79-
while (CheckTileAvailability(startX, startX + i, j, plr))
96+
TSPlayer.All.SendTileRect((short)(startX + i * directionX), (short)j, 1, 1);
97+
plr.SelectedItem.stack--;
98+
i++;
99+
if (directionY != 0) // 只有在垂直建造时改变Y坐标
80100
{
81-
WorldGen.PlaceTile(startX + i, j, selectedItem.createTile, false, true, -1, styleId);
82-
TSPlayer.All.SendTileRect((short)(startX + i), (short)j, 1, 1);
83-
plr.SelectedItem.stack--;
84-
i += direction;
85-
tileCount++;
101+
j += directionY;
86102
}
103+
placedCount++;
104+
}
87105

88-
plr.SendSuccessMessage($"{tileCount}格桥梁建造完成!");
106+
if (placedCount > 0)
107+
{
108+
plr.SendSuccessMessage($"{placedCount}格桥梁建造完成!");
89109
}
90110
else
91111
{
92-
if (!Config.AllowedwallIDs.Contains(selectedItem.createWall))
93-
{
94-
plr.SendErrorMessage("你手持的墙壁无法自动建造桥梁。(一般仅允许使用平台或团队块或种植盆。)");
95-
return;
96-
}
97-
int wallCount = 0;
98-
while (CheckTileAvailability(startX, startX + i, j, plr))
99-
{
100-
Main.tile[startX + i, j].wall = (ushort)selectedItem.createWall;
101-
TSPlayer.All.SendTileRect((short)(startX + i), (short)j, 1, 1);
102-
plr.SelectedItem.stack--;
103-
i += direction;
104-
wallCount++;
105-
}
106-
plr.SendSuccessMessage($"{wallCount}格桥梁建造完成!");
112+
plr.SendErrorMessage("没有足够的空间或物品来建造桥梁。");
107113
}
108114

109115
NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(plr.SelectedItem.Name), plr.Index, plr.TPlayer.selectedItem);
110116
NetMessage.SendData((int)PacketTypes.PlayerSlot, plr.Index, -1, NetworkText.FromLiteral(plr.SelectedItem.Name), plr.Index, plr.TPlayer.selectedItem);
111117
});
112118
}
113119

114-
115-
private static bool CheckTileAvailability(int startX, int x, int y, TSPlayer plr)
120+
private static bool CheckTileAvailability(int x, int y, TSPlayer plr, int directionX = 0, int directionY = 0)
116121
{
117-
bool canPlace = x < Main.maxTilesX && x >= 0 &&
118-
Math.Abs(startX - x) < Config.MaxPlaceLength &&
122+
bool canPlace = x < Main.maxTilesX && x >= 0 && y < Main.maxTilesY && y >= 0 &&
123+
Math.Abs(directionX != 0 ? plr.TileX - x : plr.TileY - y) < Config.MaxPlaceLength &&
119124
plr.SelectedItem.stack > 0 &&
120-
!TShock.Regions.InArea(x, y) &&
121-
!Main.tile[x, y].active();
125+
!TShock.Regions.InArea(x, y);
122126

123-
if (plr.SelectedItem.createTile < 0 && plr.SelectedItem.createWall >= 0)
127+
if (plr.SelectedItem.createTile < 0 && plr.SelectedItem.createWall >= 0) // 检查墙壁
124128
{
125129
canPlace &= Main.tile[x, y].wall == 0;
126130
}
131+
else if (plr.SelectedItem.createTile >= 0) // 检查物块
132+
{
133+
canPlace &= !Main.tile[x, y].active();
134+
}
127135

128136
return canPlace;
129137
}
138+
130139
}
131140
}
132141

BridgeBuilder/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
- 出处: [github](https://github.com/Soof4/BridgeBuilder)
55
- 快速向玩家面向的平行方向铺路,碰到方块则停止
66
- 可自定义铺桥方块,默认配置内已有:平台,种植盆,团队块
7-
7+
- 可以竖直放了
8+
- 科普:<>内是必填,[]内是选填
89
## 更新日志
910

1011
```
12+
1.0.6
13+
添加竖直方向
14+
1115
1.0.5
1216
修改添加了墙壁逻辑,填墙壁id就好了
1317
```
@@ -16,7 +20,7 @@
1620

1721
| 语法 | 权限 | 说明 |
1822
| -------------- | :-----------------: | :------: |
19-
| /bridge 或 /桥来 | bridgebuilder.bridge | 快速铺桥指令|
23+
| /bridge [up/down] 或 /桥来 [up/down]| bridgebuilder.bridge | 快速铺桥指令|
2024

2125
## 配置
2226

0 commit comments

Comments
 (0)