Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import com.mojang.brigadier.CommandDispatcher;

import static net.minecraft.commands.Commands.*;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont remove this import, it's here for ease of use if/when client commands are added

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they can add it back when they do imo, rather that than danglign imports


public class GTClientCommands {

public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext buildContext) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
import com.gregtechceu.gtceu.api.registry.GTRegistry;
import com.gregtechceu.gtceu.common.commands.arguments.GTRegistryArgument;
import com.gregtechceu.gtceu.common.network.GTNetwork;
import com.gregtechceu.gtceu.common.network.packets.SCPacketShareProspection;
import com.gregtechceu.gtceu.common.network.packets.SPacketStartProspectionShare;
import com.gregtechceu.gtceu.data.loader.BedrockFluidLoader;
import com.gregtechceu.gtceu.data.loader.BedrockOreLoader;
import com.gregtechceu.gtceu.data.loader.GTOreLoader;
import com.gregtechceu.gtceu.data.pack.GTDynamicDataPack;
import com.gregtechceu.gtceu.integration.map.ClientCacheManager;

import net.minecraft.commands.*;
import net.minecraft.commands.arguments.EntityArgument;
Expand All @@ -30,7 +29,6 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.BulkSectionAccess;
import net.minecraft.world.level.levelgen.structure.templatesystem.AlwaysTrueTest;
Expand Down Expand Up @@ -163,10 +161,12 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co
.then(literal("share_prospection_data")
.then(argument("player", EntityArgument.player())
.executes(ctx -> {
Player player = EntityArgument.getPlayer(ctx, "player");
Thread sendThread = new Thread(new GTCommands.ProspectingShareTask(
ctx.getSource().getPlayerOrException().getUUID(), player.getUUID()));
sendThread.start();
// resolve both players server-side (uses the server player list),
// then ask the sender's client to read its cache and send the data
ServerPlayer sender = ctx.getSource().getPlayerOrException();
ServerPlayer receiver = EntityArgument.getPlayer(ctx, "player");
GTNetwork.sendToPlayer(sender,
new SPacketStartProspectionShare(receiver.getUUID()));
return 1;
}))));
}
Expand Down Expand Up @@ -346,33 +346,4 @@ private static int placeVein(CommandContext<CommandSourceStack> context, BlockPo

return 1;
}

private static class ProspectingShareTask implements Runnable {

private final List<ClientCacheManager.ProspectionInfo> prospectionData;
private final UUID sender;
private final UUID receiver;

public ProspectingShareTask(UUID sender, UUID receiver) {
prospectionData = ClientCacheManager.getProspectionShareData();
this.sender = sender;
this.receiver = receiver;
}

@Override
public void run() {
boolean first = true;
for (ClientCacheManager.ProspectionInfo info : prospectionData) {
GTNetwork.sendToServer(new SCPacketShareProspection(sender, receiver, info.cacheName, info.key,
info.isDimCache, info.dim, info.data, first));
first = false;

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,7 @@ public static void init() {
register(SPacketSendWorldID.class, SPacketSendWorldID::new, NetworkDirection.PLAY_TO_CLIENT);
register(SPacketNotifyCapeChange.class, SPacketNotifyCapeChange::new, NetworkDirection.PLAY_TO_CLIENT);
register(SCPacketShareProspection.class, SCPacketShareProspection::new, null);
register(SPacketStartProspectionShare.class, SPacketStartProspectionShare::new,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this above SCPacketProspectionShare's registration pls

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:sadge: unlucky

NetworkDirection.PLAY_TO_CLIENT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.gregtechceu.gtceu.common.network.packets;

import com.gregtechceu.gtceu.common.network.GTNetwork;
import com.gregtechceu.gtceu.integration.map.ClientCacheManager;

import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;

import lombok.AllArgsConstructor;

import java.util.List;
import java.util.UUID;

/**
* Sent from the server to the sender's client to kick off sharing their local prospection cache.
*
* The {@code /gtceu share_prospection_data} command is a server command. The prospection cache
* only exists on the client, so the server delegates the actual read + send back to the sender's
* client via this packet.
*/
@AllArgsConstructor
public class SPacketStartProspectionShare implements GTNetwork.INetPacket {

private UUID receiver;

@SuppressWarnings("unused")
public SPacketStartProspectionShare() {}

public SPacketStartProspectionShare(FriendlyByteBuf buf) {
receiver = buf.readUUID();
}

@Override
public void encode(FriendlyByteBuf buf) {
buf.writeUUID(receiver);
}

@Override
public void execute(NetworkEvent.Context context) {
UUID sender = Minecraft.getInstance().player.getUUID();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this fine to do on a dedicated server? I'm not sure.
Also check https://docs.minecraftforge.net/en/latest/networking/simpleimpl/#handling-packets

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it works on a dedi server, we tested before merging

Thread sendThread = new Thread(new ProspectingShareTask(sender, receiver));
sendThread.start();
}

private static class ProspectingShareTask implements Runnable {

private final List<ClientCacheManager.ProspectionInfo> prospectionData;
private final UUID sender;
private final UUID receiver;

public ProspectingShareTask(UUID sender, UUID receiver) {
prospectionData = ClientCacheManager.getProspectionShareData();
this.sender = sender;
this.receiver = receiver;
}

@Override
public void run() {
boolean first = true;
for (ClientCacheManager.ProspectionInfo info : prospectionData) {
GTNetwork.sendToServer(new SCPacketShareProspection(sender, receiver, info.cacheName, info.key,
info.isDimCache, info.dim, info.data, first));
first = false;

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
}
Loading