|
|
|
@@ -1,19 +1,42 @@
|
|
|
|
|
package skybakery;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
import net.fabricmc.api.ClientModInitializer;
|
|
|
|
|
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
|
|
|
|
|
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
|
|
|
|
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
|
|
|
|
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
|
|
|
|
|
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
|
|
|
|
import net.minecraft.client.network.ServerInfo;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.screen.slot.Slot;
|
|
|
|
|
import skybakery.assets.NewYearCakeAsset;
|
|
|
|
|
import skybakery.mixin.client.HandledScreenAccessor;
|
|
|
|
|
import skybakery.repository.NewYearCakeRepository;
|
|
|
|
|
import skybakery.utilities.ChatMenu;
|
|
|
|
|
|
|
|
|
|
public class SkyBakeryClient implements ClientModInitializer {
|
|
|
|
|
public static final String HYPIXEL_URL = "hypixel.net";
|
|
|
|
|
public static final NewYearCakeRepository CAKE_REPOSITORY = new NewYearCakeRepository();
|
|
|
|
|
private static final int MAX_CAKE_YEAR = 500;
|
|
|
|
|
|
|
|
|
|
private static String formatRanges(List<Integer> years) {
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
int start = years.get(0);
|
|
|
|
|
int end = start;
|
|
|
|
|
for (int i = 1; i < years.size(); i++) {
|
|
|
|
|
if (years.get(i) == end + 1) {
|
|
|
|
|
end = years.get(i);
|
|
|
|
|
} else {
|
|
|
|
|
sb.append(start == end ? start : start + "-" + end).append(", ");
|
|
|
|
|
start = end = years.get(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sb.append(start == end ? start : start + "-" + end);
|
|
|
|
|
return sb.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onInitializeClient() {
|
|
|
|
@@ -41,6 +64,51 @@ public class SkyBakeryClient implements ClientModInitializer {
|
|
|
|
|
CAKE_REPOSITORY.save();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
|
|
|
|
|
dispatcher.register(
|
|
|
|
|
ClientCommandManager.literal("skybakery")
|
|
|
|
|
.then(ClientCommandManager.literal("missing")
|
|
|
|
|
.executes(ctx -> {
|
|
|
|
|
List<Integer> missing = CAKE_REPOSITORY.getMissingYears(MAX_CAKE_YEAR);
|
|
|
|
|
if (missing.isEmpty()) {
|
|
|
|
|
ChatMenu.send("You have all cakes from Year 1 to " + MAX_CAKE_YEAR + "!");
|
|
|
|
|
} else {
|
|
|
|
|
ChatMenu.send("Missing " + missing.size() + "/" + MAX_CAKE_YEAR + " cakes: " + formatRanges(missing));
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}))
|
|
|
|
|
.then(ClientCommandManager.literal("flush")
|
|
|
|
|
.executes(ctx -> {
|
|
|
|
|
CAKE_REPOSITORY.save();
|
|
|
|
|
ChatMenu.send("Cake collection flushed to disk.");
|
|
|
|
|
return 1;
|
|
|
|
|
}))
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
|
|
|
|
|
if (!(screen instanceof HandledScreen<?> handledScreen)) return;
|
|
|
|
|
if (!screen.getTitle().getString().contains("Auction")) return;
|
|
|
|
|
|
|
|
|
|
ScreenEvents.afterRender(screen).register((s, drawContext, mouseX, mouseY, tickDelta) -> {
|
|
|
|
|
HandledScreenAccessor accessor = (HandledScreenAccessor) handledScreen;
|
|
|
|
|
for (Slot slot : handledScreen.getScreenHandler().slots) {
|
|
|
|
|
ItemStack stack = slot.getStack();
|
|
|
|
|
if (stack.isEmpty()) continue;
|
|
|
|
|
if (!stack.getName().getString().contains("New Year Cake")) continue;
|
|
|
|
|
|
|
|
|
|
Optional<NewYearCakeAsset> asset = NewYearCakeAsset.from(stack);
|
|
|
|
|
if (asset.isEmpty()) continue;
|
|
|
|
|
|
|
|
|
|
if (CAKE_REPOSITORY.getByYear(asset.get().year()).isEmpty()) {
|
|
|
|
|
int x = accessor.getGuiLeft() + slot.x;
|
|
|
|
|
int y = accessor.getGuiTop() + slot.y;
|
|
|
|
|
drawContext.fill(x, y, x + 16, y + 16, 0x80FF0000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
|
|
|
|
|
if (client.player == null)
|
|
|
|
|
return;
|
|
|
|
|