Skip to content

Commit

Permalink
chore: Improve the island scan
Browse files Browse the repository at this point in the history
  • Loading branch information
Awakened-Redstone committed Jun 20, 2024
1 parent 990d13d commit 3dac985
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 135 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/awakenedredstone/neoskies/NeoSkies.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.awakenedredstone.neoskies.font.FontManager;
import com.awakenedredstone.neoskies.logic.EventListeners;
import com.awakenedredstone.neoskies.logic.IslandLogic;
import com.awakenedredstone.neoskies.logic.level.IslandScanner;
import com.awakenedredstone.neoskies.logic.protection.NeoSkiesProtectionProvider;
import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings;
import com.awakenedredstone.neoskies.logic.registry.NeoSkiesPermissionLevels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
}

private static void run(ServerCommandSource source, CommandDispatcher<ServerCommandSource> dispatcher) {
ParseResults<ServerCommandSource> parseResults = dispatcher.parse(IslandLogic.getConfig().command, source);
ParseResults<ServerCommandSource> parseResults = dispatcher.parse(IslandLogic.getConfig().commands.command, source);
if (parseResults.getContext().getNodes().isEmpty()) {
source.sendError(Texts.of("commands.neoskies.error.no_commands"));
return;
Expand All @@ -61,7 +61,7 @@ private static boolean sendCommands(Collection<CommandNode<ServerCommandSource>>
if (node.getChildren().isEmpty() || node.getCommand() != null) {
String command = node.getUsageText();
MutableText prefix = Texts.of("commands.neoskies.help.prefix", map -> {
map.put("prefix", IslandLogic.getConfig().command);
map.put("prefix", IslandLogic.getConfig().commands.command);
map.put("command", parent + command);
});
String string = "commands.description.neoskies." + parentTranslation + command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.awakenedredstone.neoskies.gui.PagedGui;
import com.awakenedredstone.neoskies.logic.Island;
import com.awakenedredstone.neoskies.logic.IslandLogic;
import com.awakenedredstone.neoskies.mixin.accessor.FluidBlockAccessor;
import com.awakenedredstone.neoskies.util.*;
import com.mojang.brigadier.CommandDispatcher;
import eu.pb4.polymer.virtualentity.api.ElementHolder;
Expand All @@ -16,7 +17,9 @@
import eu.pb4.sgui.api.elements.GuiElementInterface;
import eu.pb4.sgui.api.gui.SimpleGui;
import net.minecraft.block.Block;
import net.minecraft.block.FluidBlock;
import net.minecraft.entity.decoration.Brightness;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
Expand Down Expand Up @@ -86,12 +89,22 @@ private static int view(ServerCommandSource source) {

List<GuiElementInterface> elements = new ArrayList<>();

island.getBlocks().forEach((block, count) -> {
Integer points = IslandLogic.getRankingConfig().getPoints(block);
island.getBlocks().forEach((blockId, count) -> {
Integer points = IslandLogic.getRankingConfig().getPoints(blockId);
sum.addAndGet(points * count);

Block block1 = Registries.BLOCK.get(block);
ItemStack stack = block1.getPickStack(island.getOverworld(), BlockPos.ORIGIN, block1.getDefaultState());
Block block = Registries.BLOCK.get(blockId);
ItemStack stack;
if (block instanceof FluidBlockAccessor fluid) {
stack = fluid.getFluid().getBucketItem().getDefaultStack();
} else {
ItemStack item = block.asItem().getDefaultStack();
if (!item.isEmpty()) {
stack = item;
} else {
stack = block.getPickStack(island.getOverworld(), BlockPos.ORIGIN, block.getDefaultState());
}
}
GuiElementBuilder builder = GuiElementBuilder.from(stack.isEmpty() ? new ItemStack(Items.BARRIER) : stack)
.hideDefaultTooltip()
.addLoreLine(Text.empty())
Expand All @@ -101,10 +114,10 @@ private static int view(ServerCommandSource source) {
placeholders.put("count", String.valueOf(count));
}));

builder.setName(block1.getName());
builder.setName(block.getName());
if (stack.isEmpty()) {
//TODO: color
builder.setName(block1.getName().formatted(Formatting.WHITE));
builder.setName(block.getName().formatted(Formatting.WHITE));
}
elements.add(builder.build());
});
Expand Down Expand Up @@ -203,13 +216,13 @@ private static int runScan(ServerCommandSource source) {
toScan.set(total);
display.setText(Texts.of("message.neoskies.island.level.scan.progress", new MapBuilder.StringMap()
.putAny("progress", 0)
.putAny("total", total)
.putAny("total", UnitConvertions.readableNumber(total))
.build()));
}, current -> {
int total = toScan.get();
Text progress = Texts.of("message.neoskies.island.level.scan.progress", new MapBuilder.StringMap()
.putAny("progress", current)
.putAny("total", total)
.putAny("progress", UnitConvertions.readableNumber(current))
.putAny("total", UnitConvertions.readableNumber(total))
.build());
IslandLogic.getInstance().scheduler.schedule(new Identifier("neoskies", "island-scan/" + island.getIslandId().toString()), 0, () -> display.setText(progress));
}, (timeTaken, scannedBlocks) -> {
Expand All @@ -218,31 +231,33 @@ private static int runScan(ServerCommandSource source) {

source.sendFeedback(() -> Texts.of("message.neoskies.island.level.scan.time_taken", new MapBuilder.StringMap()
.put("time", UnitConvertions.formatTimings(timeTaken))
.putAny("count", scanned)
.putAny("count", UnitConvertions.readableNumber(scanned))
.build()), false);
removeDisplay(display);
float width = getTextWidth(text);
AtomicInteger i = new AtomicInteger();
List<BlockDisplayElement> blockDisplays = new ArrayList<>();
List<TextDisplayElement> labels = new ArrayList<>();
scannedBlocks.forEach((id, amount) -> {
if (i.get() > 8) return;
List<Map.Entry<Identifier, Integer>> list = scannedBlocks.entrySet().stream().toList();
for (int i = 0; i < Math.min(8, list.size()); i++) {
Map.Entry<Identifier, Integer> entry = list.get(i);
Identifier id = entry.getKey();
Integer amount = entry.getValue();

Block block = Registries.BLOCK.get(id);
BlockDisplayElement blockDisplay = new BlockDisplayElement();
blockDisplay.setBlockState(block.getDefaultState());
blockDisplay.setYaw(yaw + 180);
blockDisplay.setScale(new Vec3d(0.25, 0.25, 0.01).toVector3f());
blockDisplay.setTranslation(new Vec3d(-width + 0.3, 0.25 * (lines) + 0.0625 - (i.get()) * 0.3, 0).toVector3f());
blockDisplay.setTranslation(new Vec3d(-width + 0.3, 0.25 * (lines) + 0.0625 - i * 0.3, 0).toVector3f());
blockDisplay.setBrightness(Brightness.FULL);
holder.addElement(blockDisplay);
blockDisplays.add(blockDisplay);
Text amountText = Texts.of("message.neoskies.island.level.scan.block_info", new MapBuilder.StringMap()
.putAny("amount", amount)
.putAny("amount", UnitConvertions.readableNumber(amount))
.put("block", block.getName().getString())
.build());
labels.add(createDisplay(amountText, yaw, new Vec3d(-width + 0.7 + (getTextWidth(amountText)), 0.25 * (lines) + 0.0625 - (i.get()) * 0.3 - 0.03125, 0)));
i.getAndIncrement();
});
labels.add(createDisplay(amountText, yaw, new Vec3d(-width + 0.7 + (getTextWidth(amountText)), 0.25 * (lines) + 0.0625 - i * 0.3 - 0.03125, 0)));
}

var ref = new Object() {
Pair<TextDisplayElement, Set<InteractionElement>> closeButton = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
)
);

for (String alias : IslandLogic.getConfig().commandAliases) {
for (String alias : IslandLogic.getConfig().commands.commandAliases) {
dispatcher.register(CommandManager.literal(alias).executes(context -> MenuCommand.execute(context.getSource())));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ public static Predicate<ServerCommandSource> mustBeIslandOwner(@NotNull String p
}

public static LiteralArgumentBuilder<ServerCommandSource> node() {
return literal(IslandLogic.getConfig().command);
return literal(IslandLogic.getConfig().commands.command);
}

public static LiteralArgumentBuilder<ServerCommandSource> adminNode() {
return literal(IslandLogic.getConfig().adminCommand);
return literal(IslandLogic.getConfig().commands.adminCommand);
}

public static LiteralCommandNode<ServerCommandSource> register(CommandDispatcher<ServerCommandSource> dispatcher, final LiteralArgumentBuilder<ServerCommandSource> command) {
LiteralCommandNode<ServerCommandSource> node = dispatcher.register(command);

for (String alias : IslandLogic.getConfig().commandAliases) {
for (String alias : IslandLogic.getConfig().commands.commandAliases) {
dispatcher.register(CommandManager.literal(alias).redirect(node));
}

Expand All @@ -83,7 +83,7 @@ public static LiteralCommandNode<ServerCommandSource> register(CommandDispatcher
public static LiteralCommandNode<ServerCommandSource> registerAdmin(CommandDispatcher<ServerCommandSource> dispatcher, final LiteralArgumentBuilder<ServerCommandSource> command) {
LiteralCommandNode<ServerCommandSource> node = dispatcher.register(command);

for (String alias : IslandLogic.getConfig().adminCommandAliases) {
for (String alias : IslandLogic.getConfig().commands.adminCommandAliases) {
dispatcher.register(CommandManager.literal(alias).redirect(node));
}

Expand Down
35 changes: 21 additions & 14 deletions src/main/java/com/awakenedredstone/neoskies/config/MainConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import blue.endless.jankson.Comment;
import com.awakenedredstone.neoskies.config.source.Config;
import com.awakenedredstone.neoskies.config.source.JanksonBuilder;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class MainConfig extends Config {
public MainConfig() {
Expand All @@ -19,17 +16,8 @@ public MainConfig() {
@Comment("The mod language")
public String language = "en_us";

@Comment("The mod main command")
public String command = "sb";

@Comment("The mod main command aliases")
public List<String> commandAliases = new ArrayList<>(List.of("skyblock"));

@Comment("The mod admin command")
public String adminCommand = "sba";

@Comment("The mod admin command aliases")
public List<String> adminCommandAliases = new ArrayList<>(List.of("skyblockadmin"));
public Commands commands = new Commands();
public IslandScan islandScan = new IslandScan();

@Comment("Disables spawning lightning and horse traps in the hub")
public boolean disableLightningOnHub = true;
Expand Down Expand Up @@ -72,4 +60,23 @@ public MainConfig() {

@Comment("Whenever the player gets the island protection messages")
public boolean showProtectionMessages = true;

public static class Commands {
@Comment("The mod main command")
public String command = "sb";

@Comment("The mod main command aliases")
public List<String> commandAliases = new ArrayList<>(List.of("skyblock"));

@Comment("The mod admin command")
public String adminCommand = "sba";

@Comment("The mod admin command aliases")
public List<String> adminCommandAliases = new ArrayList<>(List.of("skyblockadmin"));
}

public static class IslandScan {
@Comment("The amount of cores dedicated for processing the chunk data on an island scan")
public byte chunkCores = 4;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@ public static IslandRankingConfig getRankingConfig() {
public static void runOnNextTick(Runnable runnable) {
IslandLogic.getScheduler().schedule(0, runnable);
}
public static void scheduleDelayed(long delay, Runnable runnable) {
IslandLogic.getScheduler().scheduleDelayed(getServer(), delay, runnable);
}
}
Loading

0 comments on commit 3dac985

Please sign in to comment.