Skip to content

Commit 4942f76

Browse files
authored
Merge pull request #363 from FTBTeam/dev
Dev
2 parents 1d725e0 + f2302d2 commit 4942f76

File tree

14 files changed

+150
-38
lines changed

14 files changed

+150
-38
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,32 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [2101.1.10]
8+
9+
### Added
10+
* Waypoints added via API can now be marked as transient
11+
* Transient waypoints are not persisted on the client after player logout or dimension changing
12+
* Transient waypoints should be added via the new `WaypointManagerEvent.AVAILABLE` Architectury event
13+
14+
### Fixed
15+
* Fixed minimap game time display being out by 6 game hours
16+
* Fixed added waypoint Y values being way out in void dimensions
17+
* Fixed Yellow Archwood (Ars Elemental) being wrong colour on the map (thanks @cragolf)
18+
* Fixed a dupe bug under certain circumstances
19+
720
## [2101.1.9]
821

922
### Added
1023
* Added `pt_br` translation (thanks @Xlr11)
1124
* Added `es_max` translation (thanks @TheLegendofSaram)
1225
* Added `ja_jp` translation (thanks @twister716)
13-
* Fixed Create framed glass blocks rendering black on the map (thanks @Varocraft25)
1426

1527
### Fixed
1628
* Ensure F3 isn't being held when checking for key presses
1729
* e.g. if "Add Waypoint" is bound to "B", pressing F3+B no longer pops up the add waypoint dialog
1830
* Fixed an edge case causing NPE's during checking blockstates for water
1931
* Fixed some entity face map icons going missing when using higher-resolution texture packs
32+
* Fixed Create framed glass blocks rendering black on the map (thanks @Varocraft25)
2033

2134
## [2101.1.8]
2235

common/src/main/java/dev/ftb/mods/ftbchunks/FTBChunks.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import net.minecraft.world.entity.LivingEntity;
4545
import net.minecraft.world.entity.MobSpawnType;
4646
import net.minecraft.world.entity.player.Player;
47+
import net.minecraft.world.item.BlockItem;
4748
import net.minecraft.world.item.ItemStack;
4849
import net.minecraft.world.level.BaseSpawner;
4950
import net.minecraft.world.level.Explosion;
@@ -280,9 +281,17 @@ public EventResult blockLeftClick(Player player, InteractionHand hand, BlockPos
280281
public EventResult blockRightClick(Player player, InteractionHand hand, BlockPos pos, Direction face) {
281282
// calling architectury stub method
282283
//noinspection ConstantConditions
283-
if (player instanceof ServerPlayer sp && ClaimedChunkManagerImpl.getInstance().shouldPreventInteraction(player, hand, pos, FTBChunksExpected.getBlockInteractProtection(), null)) {
284-
FTBCUtils.forceHeldItemSync(sp, hand);
285-
return EventResult.interruptFalse();
284+
if (player instanceof ServerPlayer sp) {
285+
boolean blockItem = sp.getItemInHand(hand).getItem() instanceof BlockItem;
286+
ClaimedChunkManagerImpl mgr = ClaimedChunkManagerImpl.getInstance();
287+
// not ideal since it also prevents right-clicking *any* blocks if holding a block item when block placement is prevented
288+
// but necessary - https://github.com/FTBTeam/FTB-Mods-Issues/issues/1752
289+
if (mgr.shouldPreventInteraction(player, hand, pos, FTBChunksExpected.getBlockInteractProtection(), null)
290+
|| blockItem && mgr.shouldPreventInteraction(player, hand, pos, FTBChunksExpected.getBlockPlaceProtection(), null))
291+
{
292+
FTBCUtils.forceHeldItemSync(sp, hand);
293+
return EventResult.interruptFalse();
294+
}
286295
}
287296

288297
return EventResult.pass();
@@ -418,7 +427,7 @@ private void playerChangedDimension(ServerPlayer serverPlayer, ResourceKey<Level
418427
}
419428

420429
@SuppressWarnings("UnreachableCode")
421-
private void teamConfig(TeamCollectPropertiesEvent event) {
430+
private void teamConfig(TeamCollectPropertiesEvent event) {
422431
event.add(FTBChunksProperties.ALLOW_EXPLOSIONS);
423432
event.add(FTBChunksProperties.ALLOW_MOB_GRIEFING);
424433
event.add(FTBChunksProperties.ALLOW_ALL_FAKE_PLAYERS);
@@ -478,7 +487,7 @@ private void playerLeftParty(PlayerLeftPartyTeamEvent event) {
478487
}
479488

480489
@SuppressWarnings("UnreachableCode")
481-
private void transferClaims(ChunkTeamDataImpl transferFrom, ChunkTeamDataImpl transferTo, Collection<ClaimedChunkImpl> chunksToTransfer) {
490+
private void transferClaims(ChunkTeamDataImpl transferFrom, ChunkTeamDataImpl transferTo, Collection<ClaimedChunkImpl> chunksToTransfer) {
482491
CommandSourceStack sourceStack = ClaimedChunkManagerImpl.getInstance().getMinecraftServer().createCommandSourceStack();
483492

484493
String fromName = transferFrom.getTeam().getShortName();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package dev.ftb.mods.ftbchunks.api.client.event;
2+
3+
import dev.architectury.event.Event;
4+
import dev.architectury.event.EventFactory;
5+
import dev.ftb.mods.ftbchunks.api.client.waypoint.WaypointManager;
6+
7+
public interface WaypointManagerEvent {
8+
/**
9+
* @see #onAvailable(WaypointManager)
10+
*/
11+
Event<WaypointManagerEvent> AVAILABLE = EventFactory.createLoop();
12+
13+
/**
14+
* Fired when the {@link WaypointManager} becomes available, immediately after the client player enters a new
15+
* dimension, including initial login.
16+
*/
17+
void onAvailable(WaypointManager manager);
18+
}

common/src/main/java/dev/ftb/mods/ftbchunks/api/client/waypoint/Waypoint.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.ftb.mods.ftbchunks.api.client.waypoint;
22

33
import dev.ftb.mods.ftbchunks.api.client.icon.WaypointIcon;
4+
import dev.ftb.mods.ftbchunks.client.map.WaypointImpl;
45
import net.minecraft.core.BlockPos;
56
import net.minecraft.resources.ResourceKey;
67
import net.minecraft.world.entity.Entity;
@@ -58,27 +59,35 @@ public interface Waypoint {
5859
Waypoint setName(String name);
5960

6061
/**
61-
* Get the waypoint's color, in RGBA format
62-
*
63-
* @return the color
62+
* {@return the waypoint's color, in RGB format}
6463
*/
6564
int getColor();
6665

6766
/**
6867
* Change the waypoint's color.
6968
*
70-
* @param color the new color
69+
* @param color the new color, in RGB format
7170
* @return the waypoint itself, for fluent calling
7271
*/
7372
Waypoint setColor(int color);
7473

7574
/**
76-
* Is this a player death point?
77-
*
78-
* @return true for a death point, false for a normal waypoint
75+
* {@return true if this waypoint is a death point, false if a normal waypoint}
7976
*/
8077
boolean isDeathpoint();
8178

79+
/**
80+
* {@return true if this waypoint is transient - not saved across client sessions}
81+
*/
82+
boolean isTransient();
83+
84+
/**
85+
* Set the transient status of this waypoint. Transient waypoints are not saved across client sessions.
86+
* @param isTransient the new transient status
87+
* @return the waypoint itself, for fluent calling
88+
*/
89+
Waypoint setTransient(boolean isTransient);
90+
8291
/**
8392
* Get the squared distance from the waypoint to the given entity (typically the client player).
8493
*

common/src/main/java/dev/ftb/mods/ftbchunks/api/client/waypoint/WaypointManager.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.ftb.mods.ftbchunks.api.client.waypoint;
22

33
import dev.ftb.mods.ftbchunks.api.client.FTBChunksClientAPI;
4+
import dev.ftb.mods.ftbchunks.api.client.event.WaypointManagerEvent;
45
import net.minecraft.core.BlockPos;
56
import net.minecraft.resources.ResourceKey;
67
import net.minecraft.world.entity.player.Player;
@@ -10,8 +11,8 @@
1011

1112
/**
1213
* Allows access to the waypoints for a particular dimension. A waypoint manager is dimension-specific; an instance
13-
* of the manager for a dimension can be obtained via {@link FTBChunksClientAPI#getWaypointManager()} or
14-
* {@link FTBChunksClientAPI#getWaypointManager(ResourceKey)}.
14+
* of the manager for a dimension can be obtained via {@link FTBChunksClientAPI#getWaypointManager()},
15+
* {@link FTBChunksClientAPI#getWaypointManager(ResourceKey)}, or via the {@link WaypointManagerEvent}.
1516
*/
1617
public interface WaypointManager {
1718
/**
@@ -26,6 +27,21 @@ public interface WaypointManager {
2627
*/
2728
Waypoint addWaypointAt(BlockPos pos, String name);
2829

30+
/**
31+
* Acts like {@link #addWaypointAt(BlockPos, String)} but waypoints added with this method do not persist across
32+
* client sessions; they are forgotten when the player changes dimension or logs out.
33+
* <p>
34+
* Therefore, this method should be called when the client player enters a dimension, including on initial login;
35+
* use the {@link WaypointManagerEvent#AVAILABLE} event to ensure the waypoint manager is definitely available.
36+
* Level-joined events fired by Architectury or the current mod loader may be fired too early, before the waypoint
37+
* manager is available for the dimension.
38+
*
39+
* @param pos the position to add the waypoint at
40+
* @param name the waypoint's displayed name
41+
* @return a newly-added waypoint
42+
*/
43+
Waypoint addTransientWaypointAt(BlockPos pos, String name);
44+
2945
/**
3046
* Remove the waypoint at the given position from the manager, if there is one.
3147
*
@@ -51,7 +67,7 @@ public interface WaypointManager {
5167
Collection<Waypoint> getAllWaypoints();
5268

5369
/**
54-
* Get the death point closes to the given player (typically the client player), if any.
70+
* Get the death point closest to the given player (typically the client player), if any.
5571
*
5672
* @param player the player to check
5773
* @return the closest death point, or {@code Optional.empty()} if there are no deathpoints currently

common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClient.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
import dev.ftb.mods.ftbchunks.api.FTBChunksAPI;
2222
import dev.ftb.mods.ftbchunks.api.client.FTBChunksClientAPI;
2323
import dev.ftb.mods.ftbchunks.api.client.event.MapIconEvent;
24+
import dev.ftb.mods.ftbchunks.api.client.event.WaypointManagerEvent;
2425
import dev.ftb.mods.ftbchunks.api.client.icon.MapIcon;
2526
import dev.ftb.mods.ftbchunks.api.client.icon.MapType;
2627
import dev.ftb.mods.ftbchunks.api.client.icon.WaypointIcon;
2728
import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapContext;
2829
import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapInfoComponent;
2930
import dev.ftb.mods.ftbchunks.api.client.waypoint.Waypoint;
31+
import dev.ftb.mods.ftbchunks.api.client.waypoint.WaypointManager;
3032
import dev.ftb.mods.ftbchunks.client.gui.*;
3133
import dev.ftb.mods.ftbchunks.client.map.*;
3234
import dev.ftb.mods.ftbchunks.client.map.color.ColorUtils;
@@ -47,6 +49,7 @@
4749
import dev.ftb.mods.ftblibrary.ui.GuiHelper;
4850
import dev.ftb.mods.ftblibrary.ui.Theme;
4951
import dev.ftb.mods.ftblibrary.ui.input.Key;
52+
import dev.ftb.mods.ftblibrary.util.ModUtils;
5053
import dev.ftb.mods.ftblibrary.util.client.ClientUtils;
5154
import dev.ftb.mods.ftbteams.api.event.ClientTeamPropertiesChangedEvent;
5255
import dev.ftb.mods.ftbteams.api.event.TeamEvent;
@@ -182,6 +185,10 @@ public void init() {
182185
ClientReloadShadersEvent.EVENT.register(this::reloadShaders);
183186
registerPlatform();
184187

188+
if (ModUtils.isDevMode()) {
189+
WaypointManagerEvent.AVAILABLE.register(this::waypointManagerAvailable);
190+
}
191+
185192
// Register minimap components
186193
FTBChunksClientAPI clientApi = FTBChunksAPI.clientApi();
187194
clientApi.registerMinimapComponent(new PlayerPosInfoComponent());
@@ -195,6 +202,13 @@ public void init() {
195202
ClientLifecycleEvent.CLIENT_STARTED.register(this::clientStarted);
196203
}
197204

205+
private void waypointManagerAvailable(WaypointManager mgr) {
206+
// only called in dev mode, testing transient waypoints
207+
if (Minecraft.getInstance().level.dimension().equals(Level.OVERWORLD)) {
208+
mgr.addTransientWaypointAt(new BlockPos(0, 65, 0), "Transient Dev-Mode Waypoint").setColor(0x808080);
209+
}
210+
}
211+
198212
private void maybeMigrateClientConfig() {
199213
// TODO delete in 1.22
200214
Path oldConfig = Platform.getGameFolder().resolve("local/ftbchunks/client-config.snbt");

common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/LargeMapScreen.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ public boolean mousePressed(MouseButton button) {
239239
prevMouseY = getMouseY();
240240
return true;
241241
} else if (button.isRight()) {
242-
final BlockPos pos = new BlockPos(regionPanel.blockX, regionPanel.blockY, regionPanel.blockZ);
242+
int fixedY = Math.max(regionPanel.blockY, Minecraft.getInstance().level.getMinBuildHeight());
243+
final BlockPos pos = new BlockPos(regionPanel.blockX, fixedY, regionPanel.blockZ);
243244
GlobalPos globalPos = GlobalPos.of(dimension.dimension, pos);
244245
List<ContextMenuItem> list = new ArrayList<>();
245246
Component title = Component.translatable("ftbchunks.gui.add_waypoint");

common/src/main/java/dev/ftb/mods/ftbchunks/client/map/MapDimension.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.collect.ImmutableList;
44
import dev.ftb.mods.ftbchunks.FTBChunks;
55
import dev.ftb.mods.ftbchunks.api.FTBChunksAPI;
6+
import dev.ftb.mods.ftbchunks.api.client.event.WaypointManagerEvent;
67
import dev.ftb.mods.ftbchunks.client.ClientTaskQueue;
78
import dev.ftb.mods.ftbchunks.client.FTBChunksClient;
89
import dev.ftb.mods.ftblibrary.math.XZ;
@@ -70,6 +71,10 @@ public static Optional<MapDimension> getCurrent() {
7071
currentDimension = MapManager.getInstance()
7172
.map(m -> m.getDimension(level.dimension()))
7273
.orElse(null);
74+
75+
if (currentDimension != null) {
76+
WaypointManagerEvent.AVAILABLE.invoker().onAvailable(currentDimension.getWaypointManager());
77+
}
7378
}
7479

7580
return Optional.ofNullable(currentDimension);

common/src/main/java/dev/ftb/mods/ftbchunks/client/map/WaypointImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class WaypointImpl implements Waypoint {
2424
private String name = "";
2525
private int color = 0xFFFFFF;
2626
private WaypointMapIcon mapIcon;
27+
private boolean isTransient;
2728

2829
public WaypointImpl(WaypointType type, MapDimension mapDimension, BlockPos pos) {
2930
this.type = type;
@@ -86,6 +87,17 @@ public WaypointImpl setColor(int color) {
8687
return this;
8788
}
8889

90+
@Override
91+
public boolean isTransient() {
92+
return isTransient;
93+
}
94+
95+
@Override
96+
public WaypointImpl setTransient(boolean isTransient) {
97+
this.isTransient = isTransient;
98+
return this;
99+
}
100+
89101
@Override
90102
public double getDistanceSq(Entity entity) {
91103
return entity.distanceToSqr(Vec3.atCenterOf(pos));

common/src/main/java/dev/ftb/mods/ftbchunks/client/map/WaypointManagerImpl.java

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,17 @@ public static void writeJson(MapDimension mapDimension, List<WaypointImpl> waypo
7575
JsonArray waypointArray = new JsonArray();
7676

7777
for (WaypointImpl w : waypoints) {
78-
JsonObject o = new JsonObject();
79-
o.addProperty("hidden", w.isHidden());
80-
o.addProperty("name", w.getName());
81-
o.addProperty("x", w.getPos().getX());
82-
o.addProperty("y", w.getPos().getY());
83-
o.addProperty("z", w.getPos().getZ());
84-
o.addProperty("color", String.format("#%06X", 0xFFFFFF & w.getColor()));
85-
o.addProperty("type", w.getType().getId());
86-
waypointArray.add(o);
78+
if (!w.isTransient()) {
79+
JsonObject o = new JsonObject();
80+
o.addProperty("hidden", w.isHidden());
81+
o.addProperty("name", w.getName());
82+
o.addProperty("x", w.getPos().getX());
83+
o.addProperty("y", w.getPos().getY());
84+
o.addProperty("z", w.getPos().getZ());
85+
o.addProperty("color", String.format("#%06X", 0xFFFFFF & w.getColor()));
86+
o.addProperty("type", w.getType().getId());
87+
waypointArray.add(o);
88+
}
8789
}
8890

8991
json.add("waypoints", waypointArray);
@@ -129,13 +131,6 @@ public boolean isEmpty() {
129131
return waypoints.isEmpty();
130132
}
131133

132-
@Override
133-
public Optional<WaypointImpl> getNearestDeathpoint(Player player) {
134-
return deathpoints.isEmpty() ?
135-
Optional.empty() :
136-
deathpoints.stream().min(Comparator.comparingDouble(o -> o.getDistanceSq(player)));
137-
}
138-
139134
@NotNull
140135
@Override
141136
public Iterator<WaypointImpl> iterator() {
@@ -159,6 +154,13 @@ public Waypoint addWaypointAt(BlockPos pos, String name) {
159154
return waypoint;
160155
}
161156

157+
@Override
158+
public Waypoint addTransientWaypointAt(BlockPos pos, String name) {
159+
WaypointImpl waypoint = new WaypointImpl(WaypointType.DEFAULT, mapDimension, pos).setName(name).setTransient(true);
160+
add(waypoint);
161+
return waypoint;
162+
}
163+
162164
@Override
163165
public boolean removeWaypointAt(BlockPos pos) {
164166
WaypointImpl impl = new WaypointImpl(WaypointType.DEFAULT, mapDimension, pos);
@@ -178,4 +180,11 @@ public boolean removeWaypoint(Waypoint waypoint) {
178180
public Collection<Waypoint> getAllWaypoints() {
179181
return Collections.unmodifiableCollection(waypoints);
180182
}
183+
184+
@Override
185+
public Optional<WaypointImpl> getNearestDeathpoint(Player player) {
186+
return deathpoints.isEmpty() ?
187+
Optional.empty() :
188+
deathpoints.stream().min(Comparator.comparingDouble(o -> o.getDistanceSq(player)));
189+
}
181190
}

0 commit comments

Comments
 (0)