Skip to content

Commit 7c74ab6

Browse files
author
hamstar0
committed
v1.1.3.2 - Added tile section mapping for client to know if mirrors work
1 parent ea0801f commit 7c74ab6

File tree

7 files changed

+66
-26
lines changed

7 files changed

+66
-26
lines changed

MountedMagicMirrors/MyMod.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
using HamstarHelpers.Classes.Tiles.TilePattern;
2-
using HamstarHelpers.Helpers.Debug;
3-
using HamstarHelpers.Helpers.TModLoader.Mods;
4-
using Microsoft.Xna.Framework.Graphics;
5-
using MountedMagicMirrors.Tiles;
61
using System;
72
using System.Collections.Generic;
3+
using System.IO;
4+
using Microsoft.Xna.Framework.Graphics;
85
using Terraria;
96
using Terraria.ID;
107
using Terraria.Localization;
118
using Terraria.ModLoader;
9+
using HamstarHelpers.Classes.Tiles.TilePattern;
10+
using HamstarHelpers.Helpers.Debug;
11+
using HamstarHelpers.Helpers.TModLoader.Mods;
12+
using HamstarHelpers.Services.Network;
13+
using MountedMagicMirrors.Tiles;
1214

1315

1416
namespace MountedMagicMirrors {
@@ -56,6 +58,17 @@ public override void PostSetupContent() {
5658
if( Main.netMode != 2 && !Main.dedServ ) {
5759
this.MirrorTex = this.GetTexture( "Items/MountableMagicMirrorTileItem" );
5860
}
61+
62+
//
63+
64+
void onTileSectionPacketGet( int tileX, int tileY, int width, int height, BinaryReader data ) {
65+
var myworld = ModContent.GetInstance<MMMWorld>();
66+
myworld.RegisterTileSectionTile( tileX, tileY );
67+
}
68+
69+
//
70+
71+
Client.SubscribeToTileSectionPackets( onTileSectionPacketGet );
5972
}
6073

6174
public override void Unload() {

MountedMagicMirrors/MyMod_Draw.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,10 @@ public void DrawMirrorOnFullscreenMap( int tileX, int tileY, bool isTarget ) {
7979
int wldBaseY = ((tileY + 1) << 4) + 8;
8080
var wldPos = new Vector2(wldBaseX, wldBaseY);
8181

82-
//var overMapData = HUDMapHelpers.GetFullMapPositionAsScreenPosition( wldPos );
83-
//
84-
//if( overMapData.IsOnScreen ) {
85-
// Vector2 scrPos = overMapData.ScreenPosition;
86-
Tuple<Vector2, bool> overMapData = HUDMapHelpers.GetFullMapScreenPosition( wldPos );
87-
88-
if( overMapData.Item2 ) {
89-
Vector2 scrPos = overMapData.Item1;
82+
var overMapData = HUDMapHelpers.GetFullMapPositionAsScreenPosition( wldPos );
83+
84+
if( overMapData.IsOnScreen ) {
85+
Vector2 scrPos = overMapData.ScreenPosition;
9086

9187
Main.spriteBatch.Draw(
9288
texture: tex,

MountedMagicMirrors/MyPlayer_Mirrors.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using Microsoft.Xna.Framework;
45
using Terraria.ModLoader;
56
using Terraria;
6-
using Microsoft.Xna.Framework;
77
using HamstarHelpers.Helpers.Debug;
88
using HamstarHelpers.Helpers.DotNET.Extensions;
99
using HamstarHelpers.Helpers.Players;
@@ -15,16 +15,17 @@ namespace MountedMagicMirrors {
1515
partial class MMMPlayer : ModPlayer {
1616
public static bool? IsMirrorTileInvalid( int tileX, int tileY ) {
1717
if( Main.netMode == 1 ) {
18-
if( !TileChunkHelpers.IsTileSyncedForCurrentClient( tileX, tileY ) ) {
19-
Tile tile = Main.tile[tileX, tileY];
20-
if( tile == null ) {
21-
return null;
22-
}
18+
var myworld = ModContent.GetInstance<MMMWorld>();
19+
if( !myworld.IsTileLoaded(tileX, tileY) ) {
20+
return null;
21+
}
2322

24-
if( TileHelpers.IsEqual( tile, new Tile() ) ) {
23+
/*if( !TileChunkHelpers.IsTileSyncedForCurrentClient( tileX, tileY ) ) {
24+
Tile tile = Main.tile[tileX, tileY];
25+
if( tile == null || TileHelpers.IsEqual(tile, new Tile()) ) {
2526
return null;
2627
}
27-
}
28+
}*/
2829
}
2930

3031
return !MountedMagicMirrorsMod.Instance.MMMTilePattern.Check( tileX, tileY );

MountedMagicMirrors/MyPlayer_Update.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using Microsoft.Xna.Framework;
3-
using Terraria.ModLoader;
43
using Terraria;
4+
using Terraria.ModLoader;
55
using HamstarHelpers.Helpers.Debug;
66
using HamstarHelpers.Helpers.DotNET.Extensions;
77

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Terraria;
4+
using Terraria.ModLoader;
5+
using HamstarHelpers.Helpers.Debug;
6+
using HamstarHelpers.Helpers.DotNET.Extensions;
7+
8+
9+
namespace MountedMagicMirrors {
10+
partial class MMMWorld : ModWorld {
11+
private IDictionary<int, ISet<int>> TileSectionMapByTile = new Dictionary<int, ISet<int>>();
12+
13+
14+
15+
////////////////
16+
17+
public void RegisterTileSectionTile( int tileX, int tileY ) {
18+
this.TileSectionMapByTile.Set2D( tileX, tileY );
19+
}
20+
21+
////
22+
23+
public bool IsTileLoaded( int tileX, int tileY ) {
24+
int sectionX = Netplay.GetSectionX( tileX );
25+
int sectionY = Netplay.GetSectionY( tileY );
26+
27+
return this.TileSectionMapByTile.Contains2D( sectionX, sectionY );
28+
}
29+
}
30+
}

MountedMagicMirrors/MyWorld.cs renamed to MountedMagicMirrors/MyWorld_WorldGen.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
namespace MountedMagicMirrors {
11-
class MMMWorld : ModWorld {
11+
partial class MMMWorld : ModWorld {
1212
public override void ModifyWorldGenTasks( List<GenPass> tasks, ref float totalWeight ) {
1313
if( !MMMConfig.Instance.GenerateMountedMirrorsForNewWorlds ) {
1414
return;
@@ -35,7 +35,7 @@ public override void ModifyWorldGenTasks( List<GenPass> tasks, ref float totalWe
3535
break;
3636
}
3737

38-
tasks.Add( new MountedMirrorsGenPass(mirrors) );
38+
tasks.Add( new MountedMirrorsGenPass( mirrors ) );
3939
}
4040
}
4141
}

MountedMagicMirrors/build.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
displayName = Mounted Magic Mirrors
22
author = hamstar
3-
version = 1.1.3.1
4-
modReferences = HamstarHelpers@5.5.1
3+
version = 1.1.3.2
4+
modReferences = HamstarHelpers@5.6.1
55
buildIgnore = *.csproj, *.user, *.bat, obj\*, bin\*, .vs\*, .git\*
66
homepage = https://forums.terraria.org/index.php?threads/mounted-magic-mirrors-fast-travel.83296/

0 commit comments

Comments
 (0)