Skip to content

Commit

Permalink
Merge pull request #282 from FTBTeam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
desht authored Jun 5, 2024
2 parents c61673f + 7e17f98 commit 80a4dd3
Show file tree
Hide file tree
Showing 57 changed files with 729 additions and 961 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
with:
curse-publish-task: ""
maven-snapshots: true
java-version: 21
secrets:
ftb-maven-token: ${{ secrets.FTB_MAVEN_TOKEN }}
saps-token: ${{ secrets.SAPS_TOKEN }}
saps-token: ${{ secrets.SAPS_TOKEN }}
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ jobs:
uses: FTBTeam/mods-meta/.github/workflows/standard-release.yml@main
with:
curse-publish-task: curseforge
java-version: 21
secrets:
ftb-maven-token: ${{ secrets.FTB_MAVEN_TOKEN }}
saps-token: ${{ secrets.SAPS_TOKEN }}
curse-token: ${{ secrets.CURSEFORGE_KEY }}
curse-token: ${{ secrets.CURSEFORGE_KEY }}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ 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).

## [2006.1.0]

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

## [2004.1.3]

### Fixed
Expand Down
8 changes: 6 additions & 2 deletions 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.5-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
}

architectury {
Expand All @@ -18,6 +18,10 @@ subprojects {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
mappings loom.officialMojangMappings()
}

configurations.configureEach {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
}

allprojects {
Expand All @@ -33,7 +37,7 @@ allprojects {
// needs to be done AFTER version is set
apply from: "https://raw.githubusercontent.com/FTBTeam/mods-meta/main/gradle/publishing.gradle"

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = 17
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = 21

compileJava {
options.encoding = "UTF-8"
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
def ENV = System.getenv()

architectury {
common("forge", "fabric", "neoforge")
common(/* "forge", */ "fabric", "neoforge")
}

configurations {
Expand Down
33 changes: 19 additions & 14 deletions common/src/main/java/dev/ftb/mods/ftbchunks/FTBChunks.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.architectury.event.EventResult;
import dev.architectury.event.events.common.*;
import dev.architectury.hooks.level.entity.PlayerHooks;
import dev.architectury.networking.NetworkManager;
import dev.architectury.registry.registries.Registrar;
import dev.architectury.registry.registries.RegistrarManager;
import dev.architectury.utils.Env;
Expand All @@ -18,6 +19,7 @@
import dev.ftb.mods.ftbchunks.client.FTBChunksClient;
import dev.ftb.mods.ftbchunks.data.*;
import dev.ftb.mods.ftbchunks.net.*;
import dev.ftb.mods.ftbchunks.data.ChunkSyncInfo;
import dev.ftb.mods.ftblibrary.integration.stages.StageHelper;
import dev.ftb.mods.ftblibrary.math.ChunkDimPos;
import dev.ftb.mods.ftblibrary.math.MathUtils;
Expand Down Expand Up @@ -181,7 +183,7 @@ private void serverLevelLoad(ServerLevel level) {
if (ClaimedChunkManagerImpl.getInstance() != null) {
ClaimedChunkManagerImpl.getInstance().initForceLoadedChunks(level);
} else {
FTBChunks.LOGGER.warn("Level " + level.dimension().location() + " loaded before FTB Chunks manager was initialized! Unable to force-load chunks");
FTBChunks.LOGGER.warn("Level {} loaded before FTB Chunks manager was initialized! Unable to force-load chunks", level.dimension().location() );
}
}

Expand All @@ -205,24 +207,24 @@ private void loggedIn(PlayerLoggedInAfterTeamEvent event) {
SNBTCompoundTag config = new SNBTCompoundTag();
FTBChunksWorldConfig.CONFIG.write(config);
UUID managerId = FTBTeamsAPI.api().getManager().getId();
new LoginDataPacket(managerId, config).sendTo(player);
NetworkManager.sendToPlayer(player, new LoginDataPacket(managerId, config));
SendGeneralDataPacket.send(data, player);
FTBChunks.LOGGER.debug("server config and team data sent to {}", playerId);

long now = System.currentTimeMillis();
Map<Pair<ResourceKey<Level>, UUID>, List<SendChunkPacket.SingleChunk>> chunksToSend = new HashMap<>();
Map<Pair<ResourceKey<Level>, UUID>, List<ChunkSyncInfo>> chunksToSend = new HashMap<>();

for (ClaimedChunkImpl chunk : ClaimedChunkManagerImpl.getInstance().getAllClaimedChunks()) {
chunksToSend.computeIfAbsent(Pair.of(chunk.getPos().dimension(), chunk.getTeamData().getTeamId()), s -> new ArrayList<>())
.add(new SendChunkPacket.SingleChunk(now, chunk.getPos().x(), chunk.getPos().z(), chunk));
.add(ChunkSyncInfo.create(now, chunk.getPos().x(), chunk.getPos().z(), chunk));
}

chunksToSend.forEach((dimensionAndId, chunkPackets) -> {
FTBTeamsAPI.api().getManager().getTeamByID(dimensionAndId.getRight()).ifPresent(team -> {
ChunkTeamDataImpl teamData = ClaimedChunkManagerImpl.getInstance().getOrCreateData(team);
if (teamData.canPlayerUse(player, FTBChunksProperties.CLAIM_VISIBILITY)) {
SendManyChunksPacket packet = new SendManyChunksPacket(dimensionAndId.getLeft(), dimensionAndId.getRight(), chunkPackets);
packet.sendTo(player);
NetworkManager.sendToPlayer(player, packet);
}
});
});
Expand Down Expand Up @@ -414,7 +416,7 @@ private void playerCloned(ServerPlayer oldPlayer, ServerPlayer newPlayer, boolea
if (!wonGame) {
newPlayer.getLastDeathLocation().ifPresent(loc -> {
int num = newPlayer.getStats().getValue(Stats.CUSTOM.get(Stats.DEATHS));
new PlayerDeathPacket(loc, num).sendTo(newPlayer);
NetworkManager.sendToPlayer(newPlayer, new PlayerDeathPacket(loc, num));
});
}
}
Expand All @@ -425,7 +427,8 @@ private void playerChangedDimension(ServerPlayer serverPlayer, ResourceKey<Level
StageHelper.INSTANCE.getProvider().sync(serverPlayer);
}

private void teamConfig(TeamCollectPropertiesEvent event) {
@SuppressWarnings("UnreachableCode")
private void teamConfig(TeamCollectPropertiesEvent event) {
event.add(FTBChunksProperties.ALLOW_EXPLOSIONS);
event.add(FTBChunksProperties.ALLOW_MOB_GRIEFING);
event.add(FTBChunksProperties.ALLOW_ALL_FAKE_PLAYERS);
Expand Down Expand Up @@ -484,7 +487,8 @@ private void playerLeftParty(PlayerLeftPartyTeamEvent event) {
});
}

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

String fromName = transferFrom.getTeam().getShortName();
Expand All @@ -495,8 +499,8 @@ private void transferClaims(ChunkTeamDataImpl transferFrom, ChunkTeamDataImpl tr

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

Map<ResourceKey<Level>, List<SendChunkPacket.SingleChunk>> chunksToSend = new HashMap<>();
Map<ResourceKey<Level>, List<SendChunkPacket.SingleChunk>> chunksToUnclaim = new HashMap<>();
Map<ResourceKey<Level>, List<ChunkSyncInfo>> chunksToSend = new HashMap<>();
Map<ResourceKey<Level>, List<ChunkSyncInfo>> chunksToUnclaim = new HashMap<>();
int transferred = 0;
int unclaimed = 0;
long now = System.currentTimeMillis();
Expand All @@ -508,11 +512,11 @@ private void transferClaims(ChunkTeamDataImpl transferFrom, ChunkTeamDataImpl tr
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));
chunksToUnclaim.computeIfAbsent(cdp.dimension(), s -> new ArrayList<>()).add(ChunkSyncInfo.create(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));
chunksToSend.computeIfAbsent(cdp.dimension(), s -> new ArrayList<>()).add(ChunkSyncInfo.create(now, cdp.x(), cdp.z(), chunk));
transferred++;
}

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

chunksToUnclaim.forEach((dimension, chunkPackets) -> {
if (!chunkPackets.isEmpty()) {
new SendManyChunksPacket(dimension, Util.NIL_UUID, chunkPackets).sendToAll(sourceStack.getServer());
NetworkManager.sendToPlayers(sourceStack.getServer().getPlayerList().getPlayers(), new SendManyChunksPacket(dimension, Util.NIL_UUID, chunkPackets));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.mojang.util.UndashedUuid;
import dev.architectury.networking.NetworkManager;
import dev.ftb.mods.ftbchunks.api.ChunkTeamData;
import dev.ftb.mods.ftbchunks.api.ClaimResult;
import dev.ftb.mods.ftbchunks.api.ClaimedChunk;
Expand Down Expand Up @@ -180,7 +181,7 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat
.then(Commands.literal("block_color")
// .requires(source -> source.getServer().isSingleplayer())
.executes(context -> {
new RequestBlockColorPacket().sendTo(context.getSource().getPlayerOrException());
NetworkManager.sendToPlayer(context.getSource().getPlayerOrException(), new RequestBlockColorPacket());
return 1;
})
)
Expand All @@ -203,8 +204,7 @@ public static void registerCommands(CommandDispatcher<CommandSourceStack> dispat

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);
NetworkManager.sendToPlayer(source.getPlayerOrException(), new AddWaypointPacket(name, position, color.getColor()));
}
return 1;
}
Expand Down Expand Up @@ -465,13 +465,13 @@ private static int viewLoadedChunks(CommandSourceStack source, ServerLevel level
}

source.sendSuccess(() -> Component.literal(String.format("Chunks Loaded: %d. Check the map to see loaded chunks", chunks.size())), false);
new LoadedChunkViewPacket(level.dimension(), chunks).sendTo(source.getPlayerOrException());
NetworkManager.sendToPlayer(source.getPlayerOrException(), new LoadedChunkViewPacket(level.dimension(), chunks));

return 1;
}

private static int resetLoadedChunks(CommandSourceStack source, ServerLevel level) throws CommandSyntaxException {
new LoadedChunkViewPacket(level.dimension(), Long2IntMaps.EMPTY_MAP).sendTo(source.getPlayerOrException());
NetworkManager.sendToPlayer(source.getPlayerOrException(), new LoadedChunkViewPacket(level.dimension(), Long2IntMaps.EMPTY_MAP));
return 1;
}

Expand Down
Loading

0 comments on commit 80a4dd3

Please sign in to comment.