Skip to content

Commit

Permalink
Merge pull request #274 from FTBTeam/1.20.1/dev
Browse files Browse the repository at this point in the history
1.20.1/dev
  • Loading branch information
desht authored Jan 2, 2024
2 parents 9ac64d8 + a23518c commit 7966b54
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Java CI - Build on Push

on:
push:
branches: [ main, dev, "1.*" ]
branches: [ main, dev, "1.**" ]
workflow_dispatch:
inputs:
skip_maven_publish:
Expand Down
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ 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.2.5]

### 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

### Fixed
* Fixed a couple of claim and force load limit issues
* Max claim/force limits weren't synced to clients when changed in server config
* Team claim/force limits weren't always correctly recalculated when a player joined/left a team

## [2001.2.4]

### Fixed
Expand All @@ -16,7 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added a team property to control whether PvP is permitted in a team's claims
* If PvP is prevented, then if either the attacking player or the attacked player is in such a claim, PvP damage will be cancelled
* Can be controlled by server admin with the server config "Allow PvP Combat"
* "always" (default) allows PvP everywhere
* "always" (default) allows PvP everywhere
* "never" prevents PvP in all claimed chunks
* "per_team" allows teams to configure PvP for their claims via new team property "Allow PvP Combat"
* Not 100% guaranteed to prevent all forms of PvP damage, but direct or projectile damage is prevented where the damage source can be traced back to a player
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.2-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false
}

architectury {
Expand Down
43 changes: 27 additions & 16 deletions common/src/main/java/dev/ftb/mods/ftbchunks/FTBChunks.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,40 +475,49 @@ private void playerLeftParty(PlayerLeftPartyTeamEvent event) {
// return the departing player's original claims to them, if possible
transferClaims(partyData, playerData, partyData.getOriginalClaims(event.getPlayerId()));
}
});

partyData.deleteMemberData(event.getPlayerId());

partyData.updateLimits();
partyData.deleteMemberData(event.getPlayerId());

if (event.getPlayer() != null) {
PlayerVisibilityPacket.syncToLevel(event.getPlayer().level());
partyData.syncChunksToPlayer(event.getPlayer());
}
if (event.getPlayer() != null) {
PlayerVisibilityPacket.syncToLevel(event.getPlayer().level());
}
});
}

private void transferClaims(ChunkTeamDataImpl transferFrom, ChunkTeamDataImpl transferTo, Collection<ClaimedChunkImpl> chunksToTransfer) {
CommandSourceStack sourceStack = ClaimedChunkManagerImpl.getInstance().getMinecraftServer().createCommandSourceStack();

String fromName = transferFrom.getTeam().getShortName();
String toName = transferTo.getTeam().getShortName();

transferFrom.clearClaimCaches();
transferTo.clearClaimCaches();

int nChunks = transferTo.getClaimedChunks().size();

Map<ResourceKey<Level>, List<SendChunkPacket.SingleChunk>> chunksToSend = new HashMap<>();
Map<ResourceKey<Level>, List<SendChunkPacket.SingleChunk>> chunksToUnclaim = new HashMap<>();
int chunks = 0;
int transferred = 0;
int unclaimed = 0;
long now = System.currentTimeMillis();
int total = transferTo.getClaimedChunks().size();

FTBChunks.LOGGER.info("attempting to transfer {} chunks from {} to {}", chunksToTransfer.size(), fromName, toName);

for (ClaimedChunkImpl chunk : chunksToTransfer) {
ChunkDimPos cdp = chunk.getPos();
if (total >= transferTo.getMaxClaimChunks()) {
chunk.unclaim(sourceStack, false);
chunksToUnclaim.computeIfAbsent(cdp.dimension(), s -> new ArrayList<>()).add(new SendChunkPacket.SingleChunk(now, cdp.x(), cdp.z(), null));
unclaimed++;
} else {
chunk.setTeamData(transferTo);
chunksToSend.computeIfAbsent(cdp.dimension(), s -> new ArrayList<>()).add(new SendChunkPacket.SingleChunk(now, cdp.x(), cdp.z(), chunk));
chunks++;
transferred++;
}

if (chunk.isForceLoaded()) {
// also transfer any claim tickets for the old team's ID, since it's no longer valid
// also transfer any force-load tickets for the old team's ID, since it's no longer valid
ServerLevel level = ClaimedChunkManagerImpl.getInstance().getMinecraftServer().getLevel(cdp.dimension());
if (level != null) {
FTBChunksExpected.addChunkToForceLoaded(level, FTBChunks.MOD_ID, transferFrom.getTeamId(), cdp.x(), cdp.z(), false);
Expand All @@ -521,10 +530,10 @@ private void transferClaims(ChunkTeamDataImpl transferFrom, ChunkTeamDataImpl tr
total++;
}

transferFrom.markDirty();
transferTo.markDirty();
transferFrom.updateLimits();
transferTo.updateLimits();

if (chunks > 0) {
if (transferred > 0 || unclaimed > 0) {
chunksToSend.forEach((dimension, chunkPackets) -> {
if (!chunkPackets.isEmpty()) {
ChunkSendingUtils.sendManyChunksToAll(sourceStack.getServer(), transferTo, new SendManyChunksPacket(dimension, transferTo.getTeamId(), chunkPackets));
Expand All @@ -536,9 +545,11 @@ private void transferClaims(ChunkTeamDataImpl transferFrom, ChunkTeamDataImpl tr
new SendManyChunksPacket(dimension, Util.NIL_UUID, chunkPackets).sendToAll(sourceStack.getServer());
}
});

FTBChunks.LOGGER.info("Transferred " + chunks + "/" + total + " chunks from " + transferFrom + " to " + transferTo);
}

FTBChunks.LOGGER.info("Transferred {} chunks from {} ({}) to {} ({})", transferred, transferFrom, fromName, transferTo, toName);
FTBChunks.LOGGER.info("Unclaimed {} chunks for {} ({}) due to claim limits", unclaimed, transferFrom, fromName);
FTBChunks.LOGGER.info("Team {} had {} claimed chunks, now has {}", toName, nChunks, nChunks + transferred);
}

private void teamOwnershipTransferred(PlayerTransferredTeamOwnershipEvent event) {
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,6 +2,7 @@

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;
Expand All @@ -13,6 +14,7 @@
import dev.ftb.mods.ftbchunks.data.ChunkTeamDataImpl;
import dev.ftb.mods.ftbchunks.data.ClaimedChunkImpl;
import dev.ftb.mods.ftbchunks.data.ClaimedChunkManagerImpl;
import dev.ftb.mods.ftbchunks.net.AddWaypointPacket;
import dev.ftb.mods.ftbchunks.net.LoadedChunkViewPacket;
import dev.ftb.mods.ftbchunks.net.RequestBlockColorPacket;
import dev.ftb.mods.ftbchunks.net.SendGeneralDataPacket;
Expand All @@ -24,11 +26,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 @@ -179,11 +184,36 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
return 1;
})
)
.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();
ClaimedChunkManagerImpl manager = claimManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import dev.ftb.mods.ftbchunks.FTBChunks;
import dev.ftb.mods.ftbchunks.FTBChunksWorldConfig;
import dev.ftb.mods.ftbchunks.api.FTBChunksAPI;
import dev.ftb.mods.ftbchunks.api.client.FTBChunksClientAPI;
import dev.ftb.mods.ftbchunks.api.client.event.MapIconEvent;
import dev.ftb.mods.ftbchunks.api.client.icon.MapIcon;
import dev.ftb.mods.ftbchunks.api.client.icon.MapType;
Expand Down Expand Up @@ -145,7 +146,7 @@ public enum FTBChunksClient {
private Matrix4f worldMatrix;
private Vec3 cameraPos;

public void init() {
public void init() {
if (Minecraft.getInstance() == null) {
return;
}
Expand Down Expand Up @@ -1161,4 +1162,11 @@ public List<Component> getChunkSummary() {
public int getMinimapTextureId() {
return minimapTextureId;
}

public static void addWaypoint(Player player, String name, BlockPos position, int color) {
FTBChunksAPI.clientApi().getWaypointManager(player.level().dimension()).ifPresent(mgr -> {
Waypoint wp = mgr.addWaypointAt(position, name);
wp.setColor(color);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,10 @@ public int getMaxForceLoadChunks() {
public void updateLimits() {
updateMemberLimitData(!memberData.isEmpty());

if (!team.isPartyTeam()) {
int prevMaxClaimed = maxClaimChunks;
int prevMaxForced = maxForceLoadChunks;

if (!team.isPartyTeam()) {
TeamMemberData m = getTeamMemberData(getTeam().getId());
maxClaimChunks = m.getMaxClaims();
maxForceLoadChunks = m.getMaxForceLoads();
Expand Down Expand Up @@ -602,7 +605,7 @@ public void updateLimits() {
maxClaimChunks += m.getMaxClaims();
maxForceLoadChunks += m.getMaxForceLoads();
});
if (memberData.size() > 0) {
if (!memberData.isEmpty()) {
maxClaimChunks /= memberData.size();
maxForceLoadChunks /= memberData.size();
}
Expand All @@ -617,7 +620,9 @@ public void updateLimits() {
maxForceLoadChunks = Math.min(maxForceLoadChunks, FTBChunksWorldConfig.HARD_TEAM_FORCE_LIMIT.get());
}

SendGeneralDataPacket.send(this, getTeam().getOnlineMembers());
if (maxClaimChunks != prevMaxClaimed || maxForceLoadChunks != prevMaxForced) {
SendGeneralDataPacket.send(this, getTeam().getOnlineMembers());
}

markDirty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;

public class ClaimedChunkImpl implements ClaimedChunk {
private ChunkTeamDataImpl teamData;
Expand All @@ -41,7 +42,9 @@ public ChunkTeamDataImpl getTeamData() {
return teamData;
}

public void setTeamData(ChunkTeamDataImpl teamData) {
public void setTeamData(@NotNull ChunkTeamDataImpl teamData) {
teamData.clearClaimCaches();
this.teamData.clearClaimCaches();
this.teamData = teamData;
}

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.client.FTBChunksClient;
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) {
FTBChunksClient.addWaypoint(context.getPlayer(), name, position, color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public interface FTBChunksNet {
MessageType SERVER_CONFIG_RESPONSE = MAIN.registerS2C("server_config_response", ServerConfigResponsePacket::new);
MessageType CHUNK_CHANGE_RESPONSE = MAIN.registerS2C("chunk_change_response", ChunkChangeResponsePacket::new);
MessageType REQUEST_BLOCK_COLOR = MAIN.registerS2C("request_block_color", RequestBlockColorPacket::new);
MessageType ADD_WAYPOINT = MAIN.registerS2C("add_waypoint", AddWaypointPacket::new);

static void init() {
}
Expand Down
Loading

0 comments on commit 7966b54

Please sign in to comment.