Skip to content

Commit

Permalink
Merge pull request #305 from FTBTeam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
desht authored Aug 5, 2024
2 parents 6f7ad34 + 0168dfe commit aebb832
Show file tree
Hide file tree
Showing 52 changed files with 1,852 additions and 455 deletions.
26 changes: 25 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,34 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2001.1.1]

### Added
* The waypoint manager screen has had a facelift
* No longer a full-screen GUI
* Added a delete button alongside the visibility toggle button on the manager screen
* Added waypoint sharing; there is now a "Share" option on the context menus for waypoints on the large map, and in the waypoint manager screen
* Player icon on the large map screen is now combined with a pointer indicating the player's facing direction
* Added new entity tag: `ftbchunks:entity_mob_griefing_blacklist`
* Prevents mob griefing by any entities in this tag if mob griefing protection is enabled in team settings
* Note: only works on NeoForge at this time (Fabric remains limited to Endermen only)
* Info text lines under the minimap are now highly configurable
* Configure with the "Minimap Info" icon on the left of the large map screen
* Entries can be enabled/disabled/reordered/configured
* Added new real time, game time and FPS lines in addition to existing zone/biome/player-pos/debug lines

### Fixed
* Fixed the `/ftbchunks waypoint add` command only working for loaded chunks
* Fixed block/item/entity tags not being detected
* If the minimap is being displayed in top-right of screen (the default), then any potion effect icons are moved to the left of the minimap to avoid overlap
* Fixed the map keybind (by default 'M') not working to close an open map
* In addition, Ctrl + M (or whatever the map key is bound to) no longer toggles minimap by default
* This was always a kludge; minimap toggling is now its own keybind (unbound by default)

## [2100.1.0]

### Changed
* Ported to Minecraft 1.20.6. Support for Fabric and NeoForge.
* Ported to Minecraft 1.21. Support for Fabric and NeoForge.
* Forge support may be re-added if/when Architectury adds support for Forge

## [2006.1.1]
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ publishMods {

// TODO: Migrate to something else
def tag = providers.environmentVariable("TAG").getOrElse("release")
type = tag == "beta" ? BETA : (tag == "alpha" ? ALPHA : STABLE)
type = tag.endsWith("-beta") ? BETA : (tag.endsWith("-alpha") ? ALPHA : STABLE)

def createOptions = (String projectName) -> {
publishOptions {
Expand Down
29 changes: 23 additions & 6 deletions common/src/main/java/dev/ftb/mods/ftbchunks/FTBChunksCommands.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.ftb.mods.ftbchunks;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
Expand Down Expand Up @@ -38,6 +39,7 @@
import net.minecraft.commands.arguments.coordinates.ColumnPosArgument;
import net.minecraft.commands.arguments.coordinates.Coordinates;
import net.minecraft.core.BlockPos;
import net.minecraft.core.GlobalPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -189,9 +191,15 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
.then(Commands.literal("add")
.then(Commands.argument("name", StringArgumentType.string())
.then(Commands.argument("position", BlockPosArgument.blockPos())
.executes(context -> addWaypoint(context.getSource(), StringArgumentType.getString(context, "name"), BlockPosArgument.getLoadedBlockPos(context, "position")))
.then(Commands.argument("color", ColorArgument.color())
.executes(context -> addWaypoint(context.getSource(), StringArgumentType.getString(context, "name"), BlockPosArgument.getLoadedBlockPos(context, "position"), ColorArgument.getColor(context, "color")))
.executes(context -> addWaypoint(context.getSource(), StringArgumentType.getString(context, "name"), BlockPosArgument.getBlockPos(context, "position")))
.then(Commands.argument("dimension", DimensionArgument.dimension())
.executes(context -> addWaypoint(context.getSource(), StringArgumentType.getString(context, "name"), DimensionArgument.getDimension(context, "dimension"), BlockPosArgument.getBlockPos(context, "position")))
.then(Commands.argument("color", ColorArgument.color())
.executes(context -> addWaypoint(context.getSource(), StringArgumentType.getString(context, "name"), DimensionArgument.getDimension(context, "dimension"), BlockPosArgument.getBlockPos(context, "position"), ColorArgument.getColor(context, "color")))
.then(Commands.argument("gui", BoolArgumentType.bool())
.executes(context -> addWaypoint(context.getSource(), StringArgumentType.getString(context, "name"), DimensionArgument.getDimension(context, "dimension"), BlockPosArgument.getBlockPos(context, "position"), ColorArgument.getColor(context, "color"), BoolArgumentType.getBool(context, "gui")))
)
)
)
)
)
Expand All @@ -202,16 +210,25 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
dispatcher.register(Commands.literal("chunks").redirect(command));
}

private static int addWaypoint(CommandSourceStack source, String name, BlockPos position, ChatFormatting color) throws CommandSyntaxException {
private static int addWaypoint(CommandSourceStack source, String name, ServerLevel level, BlockPos position, ChatFormatting color, boolean useGui) throws CommandSyntaxException {
if (color.getColor() != null) {
NetworkManager.sendToPlayer(source.getPlayerOrException(), new AddWaypointPacket(name, position, color.getColor()));
NetworkManager.sendToPlayer(source.getPlayerOrException(), new AddWaypointPacket(name, new GlobalPos(level.dimension(), position), color.getColor(), useGui));
}
return 1;
}

private static int addWaypoint(CommandSourceStack source, String name, ServerLevel level, BlockPos position, ChatFormatting color) throws CommandSyntaxException {
return addWaypoint(source, name, level ,position, color, false);
}

private static int addWaypoint(CommandSourceStack source, String name, BlockPos position) throws CommandSyntaxException {
int idx = source.getPlayerOrException().getRandom().nextInt(ChatFormatting.values().length);
return addWaypoint(source, name, position, ChatFormatting.values()[idx]);
return addWaypoint(source, name, source.getLevel() ,position, ChatFormatting.values()[idx], false);
}

private static int addWaypoint(CommandSourceStack source, String name, ServerLevel level, BlockPos position) throws CommandSyntaxException {
int idx = source.getPlayerOrException().getRandom().nextInt(ChatFormatting.values().length);
return addWaypoint(source, name, level ,position, ChatFormatting.values()[idx], false);
}

private static int bypassProtection(CommandSourceStack source) throws CommandSyntaxException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public interface FTBChunksWorldConfig {
DoubleValue MAX_IDLE_DAYS_BEFORE_UNFORCE = FORCE_LOADING.addDouble("max_idle_days_before_unforce", 0D, 0D, 3650D).comment("Maximum time (in real-world days) where if no player in a team logs in, any forceloaded chunks owned by the team are no longer forceloaded.", "Prevents chunks being forceloaded indefinitely by teams who no longer play.","Default of 0 means no automatic loss of forceloading.");
IntValue HARD_TEAM_FORCE_LIMIT = FORCE_LOADING.addInt("hard_team_force_limit", 0, 0, Integer.MAX_VALUE).comment("Hard limit for the number of chunks a team can force-load, regardless of how many members. Default of 0 means no hard limit.");

SNBTConfig WAYPOINT_SHARING = CONFIG.addGroup("waypoint_sharing");
BooleanValue WAYPOINT_SHARING_SERVER = WAYPOINT_SHARING.addBoolean("waypoint_sharing_server", true).comment("Allow players to share waypoints with the entire server.");
BooleanValue WAYPOINT_SHARING_PARTY = WAYPOINT_SHARING.addBoolean("waypoint_sharing_party", true).comment("Allow players to share waypoints with their party.");
BooleanValue WAYPOINT_SHARING_PLAYERS = WAYPOINT_SHARING.addBoolean("waypoint_sharing_players", true).comment("Allow players to share waypoints with other players.");

static int getMaxClaimedChunks(ChunkTeamData playerData, ServerPlayer player) {
if (player != null) {
return PermissionsHelper.getMaxClaimedChunks(player, MAX_CLAIMED_CHUNKS.get()) + playerData.getExtraClaimChunks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ enum StandardProblem implements ClaimResult {
NOT_LOADED("not_loaded"),
;

public static final NameMap<StandardProblem> NAME_MAP = NameMap.of(NOT_OWNER, values()).create();
public static final NameMap<StandardProblem> NAME_MAP = NameMap.of(NOT_OWNER, values()).baseNameKey("ftbchunks.standard_problem").create();

private final String resultName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ public static class Entities {
= TagKey.create(Registries.ENTITY_TYPE, FTBChunksAPI.rl("entity_interact_whitelist"));
public static final TagKey<EntityType<?>> NONLIVING_ENTITY_ATTACK_WHITELIST_TAG
= TagKey.create(Registries.ENTITY_TYPE, FTBChunksAPI.rl("nonliving_entity_attack_whitelist"));
public static final TagKey<EntityType<?>> ENTITY_MOB_GRIEFING_BLACKLIST_TAG
= TagKey.create(Registries.ENTITY_TYPE, FTBChunksAPI.rl("entity_mob_griefing_blacklist"));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.ftb.mods.ftbchunks.api.client;

import com.google.common.collect.ImmutableList;
import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapInfoComponent;
import dev.ftb.mods.ftbchunks.api.client.waypoint.WaypointManager;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -27,4 +29,33 @@ public interface FTBChunksClientAPI {
* entities...)
*/
void requestMinimapIconRefresh();

/**
* Register a custom minimap info component {@link MinimapInfoComponent} to be rendered on the minimap.
*
* This should be called during mod initialization as this list will be finalized once Minecraft has "started"
* per the client lifecycle events
*
* @param component the component to register
*/
void registerMinimapComponent(MinimapInfoComponent component);


/**
* @param component the component to check if it is enabled
* @return is the component enabled and will render under the minimap
*/
boolean isMinimapComponentEnabled(MinimapInfoComponent component);

/**
* Enable or disable a specific minimap component for rendering under the minimap
* @param component the component to enable or disable to that shoul
* @param enabled the state to set the component to
*/
void setMinimapComponentEnabled(MinimapInfoComponent component, boolean enabled);

/**
* Provides an immutable list of all registered minimap components.
*/
ImmutableList<MinimapInfoComponent> getMinimapComponents();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package dev.ftb.mods.ftbchunks.api.client.minimap;

import dev.ftb.mods.ftbchunks.client.map.MapDimension;
import dev.ftb.mods.ftblibrary.math.XZ;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.phys.Vec3;

import java.util.Map;

/**
* Minimal context for Minimap Info Components
*
* @param minecraft The Minecraft instance (Helper)
* @param player The client player
* @param mapDimension The dimension of the players location
* @param mapChunksPos The chunk for the players location
* @param playerPos the players pos
* @param infoSettings raw settings for this component
*/
public record MinimapContext(
Minecraft minecraft,
LocalPlayer player,
MapDimension mapDimension,
XZ mapChunksPos,
Vec3 playerPos,
Map<String, String> infoSettings
) {

public String getSetting(MinimapInfoComponent infoComponent) {
return infoSettings.getOrDefault(infoComponent.id().toString(), "");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package dev.ftb.mods.ftbchunks.api.client.minimap;

import dev.ftb.mods.ftbchunks.client.FTBChunksClientConfig;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;

import java.util.Collections;
import java.util.Set;

/**
* An entry point for developers to create custom minimap info components.
*/
public interface MinimapInfoComponent {
/**
* The ID of this component.
*/
ResourceLocation id();

/**
* Render your component here, the {@link com.mojang.blaze3d.vertex.PoseStack} will already be scaled and
* translated to the correct position (centered by default). We do not provide an X and Y position as
* 0, 0 is the center of the correct location. Use 0, 0 as the center of the component and {@link #height(MinimapContext)}
* to allocate the correct height for the component.
*
* @param context The minimap context
* @param graphics The graphics object see {@link GuiGraphics}
* @param font The font object
*/
void render(MinimapContext context, GuiGraphics graphics, Font font);

/**
* Set of Info {@link TranslatedOption} that are used to configure options for rendering the waypoint
* this is exposed in the right click action of Minimap Info GUI
* @return the set of {@link TranslatedOption}.
*/
default Set<TranslatedOption> getConfigComponents() {
return Set.of();
}

/**
* The height of the component is used to allocate the correct space for the component. Failure to return the correct
* height will result in the component overlapping with other components.
*
* @param context The minimap context
* @return The height of the component
*/
default int height(MinimapContext context) {
return computeLineHeight(context.minecraft(), 1) + 1;
}

/**
* Checked on each render frame to determine if the height for the component should be allocated
*/
default boolean shouldRender(MinimapContext context) {
return true;
}

/**
* Helper method to compute the height of a text component whilst taking into account the font scale
*/
default int computeLineHeight(Minecraft minecraft, int lines) {
final float fontScale = FTBChunksClientConfig.MINIMAP_FONT_SCALE.get().floatValue();
return (int) ((minecraft.font.lineHeight + 2) * lines * fontScale);
}

/**
* Helper method to draw centered text without the faff of calculating the width of the text
*/
default void drawCenteredText(Font font, GuiGraphics graphics, Component text, int y) {
int textWidth = font.width(text.getVisualOrderText());
graphics.drawString(font, text, -textWidth / 2, y, 0xFFFFFFFF, true);
}


/**
* @return display name render in the Minimap Info Settings GUI
*/
default Component displayName() {
return Component.translatable("minimap.info." + id().getNamespace() + "." + id().getPath() + ".title");
}

/**
* @return hover texted displayed render in the Minimap Info Settings GUI
*/
default Component description() {
return Component.translatable("minimap.info." + id().getNamespace() + "." + id().getPath() + ".description");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.ftb.mods.ftbchunks.api.client.minimap;

public record TranslatedOption(
String optionName,
String translationKey
) {

public static TranslatedOption of(String optionName) {
String translatedKey = optionName.toLowerCase().replaceAll("[^a-z0-9]", "_");
return new TranslatedOption(optionName, "minimap.option." + translatedKey);
}
}
Loading

0 comments on commit aebb832

Please sign in to comment.