Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -42,6 +42,7 @@
import static com.ldtteam.structurize.api.util.constant.GUIConstants.DEFAULT_ICON;
import static com.ldtteam.structurize.api.util.constant.WindowConstants.BUILD_TOOL_RESOURCE_SUFFIX;
import static com.ldtteam.structurize.api.util.constant.WindowConstants.BUTTON_CONFIRM;
import static com.ldtteam.structurize.storage.ClientStructurePackLoader.getRandomPack;

/**
* BuildTool window.
Expand Down Expand Up @@ -210,7 +211,7 @@ private void init(final int groundstyle, final BlockPos pos)
return;
}

StructurePacks.selectedPack = StructurePacks.getPackMetas().iterator().next();
StructurePacks.selectedPack = getRandomPack();
}

if (structurePack != null && !structurePack.getName().equals(StructurePacks.selectedPack.getName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.*;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
Expand Down Expand Up @@ -155,7 +152,7 @@ public static void onWorldTick(final TickEvent.ClientTickEvent event)
StructurePacks.setFinishedLoading();
if (StructurePacks.selectedPack == null && !StructurePacks.getPackMetas().isEmpty())
{
StructurePacks.selectedPack = StructurePacks.getPackMetas().iterator().next();
StructurePacks.selectedPack = getRandomPack();
}
return;
}
Expand Down Expand Up @@ -190,7 +187,7 @@ public static void onServerSyncAttempt(final Map<String, Double> serverStructure
StructurePacks.setFinishedLoading();
if (StructurePacks.selectedPack == null && !StructurePacks.getPackMetas().isEmpty())
{
StructurePacks.selectedPack = StructurePacks.getPackMetas().iterator().next();
StructurePacks.selectedPack = getRandomPack();
}
return;
}
Expand Down Expand Up @@ -238,7 +235,7 @@ else if (version != pack.getVersion())
loadingState = ClientLoadingState.FINISHED_SYNCING;
if (StructurePacks.selectedPack == null && !StructurePacks.getPackMetas().isEmpty())
{
StructurePacks.selectedPack = StructurePacks.getPackMetas().iterator().next();
StructurePacks.selectedPack = getRandomPack();
}
StructurePacks.setFinishedLoading();
}
Expand Down Expand Up @@ -314,7 +311,7 @@ public static void onStructurePackTransfer(final String packName, final ByteBuf
{
loadingState = ClientLoadingState.FINISHED_SYNCING;
StructurePacks.setFinishedLoading();
StructurePacks.selectedPack = StructurePacks.getPackMetas().iterator().next();
StructurePacks.selectedPack = getRandomPack();
}
});
}
Expand Down Expand Up @@ -349,4 +346,22 @@ public static void handleSaveScanMessage(final CompoundTag compound, final Strin
RenderingCache.getOrCreateBlueprintPreviewData("blueprint").setPos(null);
Minecraft.getInstance().player.displayClientMessage(Component.translatable("Scan successfully saved as %s", fileName), false);
}

/**
* Get a random pack from the pack metas.
* @return the random pack.
*/
public static StructurePackMeta getRandomPack()
{
final Collection<StructurePackMeta> coll = StructurePacks.getPackMetas();
int num = (int) (Math.random() * coll.size());
for(StructurePackMeta t: coll)
{
if (--num < 0)
{
return t;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,16 @@ public static void onClientSyncAttempt(final Map<String, Double> clientStructure
}

@SubscribeEvent
public static void onWorldTick(final TickEvent.LevelTickEvent event)
public static void onWorldTick(final TickEvent.ServerTickEvent event)
{
if (event.phase == TickEvent.Phase.END && !event.level.isClientSide())
if (event.phase == TickEvent.Phase.END)
{
if (event.level.getGameTime() % 20 == 0 && loadingState == ServerLoadingState.FINISHED_LOADING && !clientSyncRequests.isEmpty())
if (event.getServer().getTickCount() % 20 == 0 && loadingState == ServerLoadingState.FINISHED_LOADING && !clientSyncRequests.isEmpty())
{
loadingState = ServerLoadingState.FINISHED_SYNCING;
for (final Map.Entry<UUID, Map<String, Double>> entry : clientSyncRequests.entrySet())
{
final ServerPlayer player = (ServerPlayer) event.level.getPlayerByUUID(entry.getKey());
final ServerPlayer player = event.getServer().getPlayerList().getPlayer(entry.getKey());
if (player != null)
{
handleClientUpdate(entry.getValue(), player);
Expand All @@ -199,7 +199,7 @@ public static void onWorldTick(final TickEvent.LevelTickEvent event)
if (!messageSendTasks.isEmpty())
{
final PackagedPack packData = messageSendTasks.poll();
final ServerPlayer player = (ServerPlayer) event.level.getPlayerByUUID(packData.player);
final ServerPlayer player = event.getServer().getPlayerList().getPlayer(packData.player);
// If the player logged off, we can just skip.
if (player != null)
{
Expand Down