Skip to content

Commit

Permalink
Merge pull request #272 from FTBTeam/1.19/dev
Browse files Browse the repository at this point in the history
1.19/dev
  • Loading branch information
desht authored Dec 22, 2023
2 parents c139121 + b9dc65f commit 0df9a12
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ 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).

## [1902.4.3]

### Added
* Added `/ftbchunks waypoint add <name> <pos> [<color>]` command, to add waypoints from server-side
* Name can contain spaces if it's quoted
* Pos is a standard blockpos spec, e.g. `~ ~ ~` for the player's current pos
* Color is optional; either a chat color or, if omitted, a random color is picked

## [1902.4.2]

### Fixes
Expand Down
30 changes: 30 additions & 0 deletions common/src/main/java/dev/ftb/mods/ftbchunks/FTBChunksCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.mojang.util.UUIDTypeAdapter;
import dev.ftb.mods.ftbchunks.data.*;
import dev.ftb.mods.ftbchunks.net.AddWaypointPacket;
import dev.ftb.mods.ftbchunks.net.LoadedChunkViewPacket;
import dev.ftb.mods.ftbchunks.net.SendGeneralDataPacket;
import dev.ftb.mods.ftblibrary.math.ChunkDimPos;
Expand All @@ -18,11 +20,14 @@
import dev.ftb.mods.ftbteams.data.TeamArgumentProvider;
import it.unimi.dsi.fastutil.longs.Long2IntMaps;
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
import net.minecraft.ChatFormatting;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.ColorArgument;
import net.minecraft.commands.arguments.DimensionArgument;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.commands.arguments.coordinates.ColumnPosArgument;
import net.minecraft.commands.arguments.coordinates.Coordinates;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -173,11 +178,36 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
.requires(source -> source.getServer().isSingleplayer())
.executes(context -> FTBChunks.PROXY.blockColor())
)
.then(Commands.literal("waypoint")
.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")))
)
)
)
)
)
);

dispatcher.register(Commands.literal("chunks").redirect(command));
}

private static int addWaypoint(CommandSourceStack source, String name, BlockPos position, ChatFormatting color) throws CommandSyntaxException {
if (color.getColor() != null) {
ServerPlayer player = source.getPlayerOrException();
new AddWaypointPacket(name, position, color.getColor()).sendTo(player);
}
return 1;
}

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]);
}

private static int bypassProtection(CommandSourceStack source) throws CommandSyntaxException {
ServerPlayer player = source.getPlayerOrException();
ClaimedChunkManager manager = FTBChunksAPI.getManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ public void maybeClearDeathpoint(Player player) {

public void updateTrackedPlayerPos(GameProfile profile, BlockPos pos, boolean valid) {
}

public void addWaypoint(Player player, String name, BlockPos pos, int color) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,15 @@ public boolean skipBlock(BlockState state) {
return id == null || ColorMapLoader.getBlockColor(id).isIgnored();
}

@Override
public void addWaypoint(Player player, String name, BlockPos pos, int color) {
MapDimension mapDimension = MapManager.inst.getDimension(player.level.dimension());
Waypoint w = new Waypoint(mapDimension, pos.getX(), pos.getY(), pos.getZ());
w.name = name;
w.color = color;
mapDimension.getWaypointManager().add(w);
}

public EventResult customClick(CustomClickEvent event) {
if (event.id().equals(BUTTON_ID_MAP)) {
openGui();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dev.ftb.mods.ftbchunks.net;

import dev.architectury.networking.NetworkManager;
import dev.architectury.networking.simple.BaseS2CMessage;
import dev.architectury.networking.simple.MessageType;
import dev.ftb.mods.ftbchunks.FTBChunks;
import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;

public class AddWaypointPacket extends BaseS2CMessage {
private final String name;
private final BlockPos position;
private final int color;

public AddWaypointPacket(String name, BlockPos position, int color) {
this.name = name;
this.position = position;
this.color = color;
}

public AddWaypointPacket(FriendlyByteBuf buf) {
name = buf.readUtf();
position = buf.readBlockPos();
color = buf.readInt();
}

@Override
public MessageType getType() {
return FTBChunksNet.ADD_WAYPOINT;
}

@Override
public void write(FriendlyByteBuf buf) {
buf.writeUtf(name);
buf.writeBlockPos(position);
buf.writeInt(color);
}

@Override
public void handle(NetworkManager.PacketContext context) {
FTBChunks.PROXY.addWaypoint(context.getPlayer(), name, position, color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public interface FTBChunksNet {
MessageType SERVER_CONFIG_REQUEST = MAIN.registerC2S("server_config_request", ServerConfigRequestPacket::new);
MessageType SERVER_CONFIG_RESPONSE = MAIN.registerS2C("server_config_response", ServerConfigResponsePacket::new);
MessageType CHUNK_CHANGE_RESPONSE = MAIN.registerS2C("chunk_change_response", ChunkChangeResponsePacket::new);
MessageType ADD_WAYPOINT = MAIN.registerS2C("add_waypoint", AddWaypointPacket::new);

static void init() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ private void entityInteractSpecific(PlayerInteractEvent.EntityInteractSpecific e
}

private void mobGriefing(EntityMobGriefingEvent event) {
if (event.getEntity().getLevel().isClientSide) {
// shouldn't ever be called clientside but yay Optifine :(
return;
}

// we could do this for all mob griefing but that's arguably OP (could trivialize wither fights, for example)
// enderman block stealing is the most common annoyance, and this also has parity with the fabric support
if (event.getEntity() instanceof EnderMan) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.daemon=false
mod_id=ftbchunks
archives_base_name=ftb-chunks
maven_group=dev.ftb.mods
mod_version=1902.4.2
mod_version=1902.4.3
mod_author=FTB Team
minecraft_version=1.19.2
forge_version=43.2.8
Expand Down

0 comments on commit 0df9a12

Please sign in to comment.