Skip to content

Commit

Permalink
more work
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Jul 18, 2024
1 parent 04126f8 commit b5f7507
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.time.Instant;
import java.util.ArrayList;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void crash(@NotNull CrashReport crashReport) {
Preconditions.checkNotNull(crashReport, "crashReport cannot be null");
Minecraft.fillReport(Minecraft.getInstance(), null, "unknown", null, crashReport);
LOGGER.fatal(crashReport.getFriendlyReport());
Minecraft.crash(crashReport);
Minecraft.crash(Minecraft.getInstance(), new File(Blueberry.getGameDir(), "crash-reports"), crashReport);
}

@Override
Expand Down Expand Up @@ -192,7 +193,7 @@ public static boolean showIncompatibleWorldModScreen(@NotNull String levelId, @N
}
Minecraft.getInstance().setScreen(new MultiLineBackupConfirmScreen(null, (backup, eraseCache) -> {
if (backup) {
EditWorldScreen.makeBackupAndShowToast(Minecraft.getInstance().getLevelSource(), levelId);
EditWorldScreen.makeBackupAndShowToast(levelStorageAccess);
}
runnable.run();
}, title, description, false, lines));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.ChatFormatting;
import net.minecraft.SharedConstants;
import net.minecraft.Util;
import net.minecraft.commands.CommandRuntimeException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.network.chat.ClickEvent;
Expand Down Expand Up @@ -181,8 +180,6 @@ public static int performCommand(@NotNull CommandSourceStack commandSourceStack,

try {
return DISPATCHER.execute(reader, commandSourceStack);
} catch (CommandRuntimeException commandRuntimeException) {
commandSourceStack.sendFailure(commandRuntimeException.getComponent());
} catch (CommandSyntaxException commandSyntaxException) {
commandSourceStack.sendFailure(ComponentUtils.fromMessage(commandSyntaxException.getRawMessage()));
if (commandSyntaxException.getInput() != null && commandSyntaxException.getCursor() >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, flo
if (this.renderBackground) {
RenderSystem.setShaderColor(0.125F, 0.125F, 0.125F, 1.0F);
int i5 = 32;
guiGraphics.blit(Screen.BACKGROUND_LOCATION, this.left, this.top, (float)this.right, (float)(this.bottom + (int)this.getScrollAmount()), this.right - this.left, this.bottom - this.top, 32, 32);
guiGraphics.blit(Screen.MENU_BACKGROUND, this.left, this.top, (float)this.right, (float)(this.bottom + (int)this.getScrollAmount()), this.right - this.left, this.bottom - this.top, 32, 32);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
}

Expand All @@ -222,11 +222,11 @@ public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, flo
this.renderList(guiGraphics, getRowLeft(), i6, mouseX, mouseY, deltaFrameTime);
RenderSystem.disableScissor();
if (this.renderTopAndBottom) {
RenderSystem.setShaderTexture(0, Screen.BACKGROUND_LOCATION);
RenderSystem.setShaderTexture(0, Screen.MENU_BACKGROUND);
int i8 = 32;
RenderSystem.setShaderColor(0.25F, 0.25F, 0.25F, 1.0F);
guiGraphics.blit(Screen.BACKGROUND_LOCATION, this.left, 0, 0.0F, 0.0F, this.width, this.top, 32, 32);
guiGraphics.blit(Screen.BACKGROUND_LOCATION, this.left, this.bottom, 0.0F, (float)this.bottom, this.width, this.height - this.bottom, 32, 32);
guiGraphics.blit(Screen.MENU_BACKGROUND, this.left, 0, 0.0F, 0.0F, this.width, this.top, 32, 32);
guiGraphics.blit(Screen.MENU_BACKGROUND, this.left, this.bottom, 0.0F, (float)this.bottom, this.width, this.height - this.bottom, 32, 32);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
int i9 = 4;
guiGraphics.fillGradient(this.left, this.top, this.right, this.top + 4, -16777216, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class FileList extends ObjectSelectionList<FileList.Entry> {
private final Button selectButton;

public FileList(@NotNull Minecraft minecraft) {
super(minecraft, FileDialogScreen.this.width, FileDialogScreen.this.height, 52, FileDialogScreen.this.height - 50, 18);
super(minecraft, FileDialogScreen.this.width, FileDialogScreen.this.height, 52, FileDialogScreen.this.height - 50/*, 18*/);

if (FileUtil.isRoot(options.getInitialDirectory()) && FileUtil.hasMultipleRoots()) {
for (File root : File.listRoots()) {
Expand Down Expand Up @@ -196,14 +196,14 @@ public boolean isFocused() {
}

@Override
protected void renderList(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float deltaFrameTime) {
super.renderList(guiGraphics, mouseX, mouseY, deltaFrameTime);
protected void renderListItems(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float deltaFrameTime) {
super.renderListItems(guiGraphics, mouseX, mouseY, deltaFrameTime);
int itemCount = this.getItemCount();

for (int itemIndex = 0; itemIndex < itemCount; ++itemIndex) {
int rowTop = this.getRowTop(itemIndex);
int rowBottom = this.getRowTop(itemIndex) + this.itemHeight;
if (rowBottom >= this.y0 && rowTop <= this.y1) {
if (rowBottom >= this.getY() && rowTop <= this.getBottom()) {
Entry entry = this.getEntry(itemIndex);
int rowWidth = this.getRowWidth();
if (this.isSelectedItem(itemIndex)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public void render(@NotNull GuiGraphics guiGraphics , int i, int i2, float f) {

class ModsList extends ObjectSelectionList<ModsList.Entry> {
public ModsList(@NotNull Minecraft minecraft) {
super(minecraft, ModListScreen.this.width / 5, ModListScreen.this.height, 32, ModListScreen.this.height - 87 + 4, 18);
super(minecraft/*, ModListScreen.this.width / 5*/, ModListScreen.this.height, 32, ModListScreen.this.height - 87 + 4, 18);

for(BlueberryMod mod : Blueberry.getModLoader().getLoadedMods()) {
Entry entry = new Entry(mod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ protected void init() {
this.addRenderableWidget(Button.builder(Component.translatable("selectWorld.backupJoinConfirmButton"), (button) -> this.listener.proceed(true, this.eraseCache.selected())).bounds(this.width / 2 - 155, 100 + y, 150, 20).build());
this.addRenderableWidget(Button.builder(Component.translatable("selectWorld.backupJoinSkipButton"), (button) -> this.listener.proceed(false, this.eraseCache.selected())).bounds(this.width / 2 - 155 + 160, 100 + y, 150, 20).build());
this.addRenderableWidget(Button.builder(CommonComponents.GUI_CANCEL, (button) -> Objects.requireNonNull(this.minecraft).setScreen(this.lastScreen)).bounds(this.width / 2 - 155 + 80, 124 + y, 150, 20).build());
this.eraseCache = new Checkbox(this.width / 2 - 155 + 80, 76 + y, 150, 20, Component.translatable("selectWorld.backupEraseCache"), false);
this.eraseCache = Checkbox.builder(Component.translatable("selectWorld.backupEraseCache"), font).pos(this.width / 2 - 155 + 80, 76 + y).selected(false).build();
//new Checkbox(, 150, 20, Component.translatable("selectWorld.backupEraseCache"), false);
if (this.promptForCacheErase) {
this.addRenderableWidget(this.eraseCache);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private static int executeTpsCommand(CommandSourceStack source) throws CommandSy
server = util.asClient().getIntegratedServer();
}
if (server == null) throw UNAVAILABLE_IN_THIS_ENVIRONMENT.create();
long[] tickTimes = server.tickTimes;
long[] tickTimes = server.getTickTimesNanos();
double last100t = round(getAverageTPS(tickTimes));
double l100t = round(getLowestTPS(tickTimes));
double last20t = round(getAverageTPS(Arrays.stream(tickTimes).limit(20)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package net.blueberrymc.common.bml;

import com.google.common.collect.ImmutableList;
import net.blueberrymc.common.Blueberry;
import net.blueberrymc.common.DeprecatedReason;
import net.blueberrymc.config.ModDescriptionFile;
import net.blueberrymc.network.mod.ModInfo;
import net.blueberrymc.util.DetectedVersion;
import net.minecraft.launchwrapper.LaunchClassLoader;
import net.minecraft.network.chat.Component;
import net.minecraft.server.packs.PackLocationInfo;
import net.minecraft.server.packs.PackResources;
import net.minecraft.server.packs.PackSelectionConfig;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.repository.KnownPack;
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.server.packs.repository.PackSource;
import org.jetbrains.annotations.ApiStatus;
Expand All @@ -20,7 +21,6 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down Expand Up @@ -189,28 +189,23 @@ default void loadPacks(@NotNull Consumer<Pack> consumer) {
PackResources packResources = mod.getResourceManager().getPackResources();
var resourcesSupplier = new Pack.ResourcesSupplier() {
@Override
public @NotNull PackResources openPrimary(@NotNull String s) {
public @NotNull PackResources openPrimary(@NotNull PackLocationInfo packLocationInfo) {
return packResources;
}

@Override
public @NotNull PackResources openFull(@NotNull String s, Pack.@NotNull Info info) {
public @NotNull PackResources openFull(@NotNull PackLocationInfo packLocationInfo, Pack.@NotNull Metadata metadata) {
return packResources;
}
};
Pack.Info info = Pack.readPackInfo(mod.modId(), resourcesSupplier, Objects.requireNonNull(DetectedVersion.tryDetectVersion()).getPackVersion(PackType.CLIENT_RESOURCES));
if (info == null) {
throw new RuntimeException("Failed to load mod pack info for " + mod.modId());
}
Pack pack = Pack.create(
PackLocationInfo locationInfo = new PackLocationInfo(
mod.getDescription().modId(),
Component.literal(mod.name()),
true,
resourcesSupplier,
info,
Pack.Position.BOTTOM,
false,
PackSource.BUILT_IN);
PackSource.FEATURE,
Optional.of(KnownPack.vanilla(mod.getDescription().modId()))
);
PackSelectionConfig config = new PackSelectionConfig(true, Pack.Position.BOTTOM, false);
Pack pack = Pack.readMetaAndCreate(locationInfo, resourcesSupplier, PackType.CLIENT_RESOURCES, config);
consumer.accept(pack);
} catch (IllegalArgumentException ex) {
break; // resource manager has not been loaded yet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void render(@NotNull GuiGraphics guiGraphics, int i, int i2, float f) {

class ProblemList extends ObjectSelectionList<ProblemList.Entry> {
public ProblemList(@NotNull Minecraft minecraft) {
super(minecraft, ModLoadingProblemScreen.this.width, ModLoadingProblemScreen.this.height, 32, ModLoadingProblemScreen.this.height - 65 + 4, 18);
super(minecraft/*, ModLoadingProblemScreen.this.width*/, ModLoadingProblemScreen.this.height, 32, ModLoadingProblemScreen.this.height - 65 + 4, 18);

for (ModLoadingError error : ModLoadingErrors.getErrors()) {
this.addEntry(new Entry(error));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package net.blueberrymc.common.resources;

import net.blueberrymc.common.bml.BlueberryMod;
import net.minecraft.network.chat.Component;
import net.minecraft.server.packs.PackLocationInfo;
import net.minecraft.server.packs.PackResources;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.PathPackResources;
import net.minecraft.server.packs.repository.KnownPack;
import net.minecraft.server.packs.repository.PackSource;
import net.minecraft.server.packs.resources.FallbackResourceManager;
import net.minecraft.server.packs.resources.IoSupplier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.InputStream;
import java.util.Optional;

public class BlueberryResourceManager extends FallbackResourceManager {
@NotNull private final BlueberryMod mod;
Expand All @@ -19,7 +24,13 @@ public BlueberryResourceManager(@NotNull BlueberryMod mod) {
super(PackType.CLIENT_RESOURCES, mod.getDescription().modId());
this.mod = mod;
if (this.mod.getFile().isDirectory()) {
packResources = new PathPackResources("Mod Resources for " + mod.name() + " (Folder)", this.mod.getFile().toPath(), true) {
PackLocationInfo locationInfo = new PackLocationInfo(
mod.modId(),
Component.literal("Mod Resources for " + mod.name() + " (Folder)"),
PackSource.FEATURE,
Optional.of(KnownPack.vanilla(mod.modId()))
);
packResources = new PathPackResources(locationInfo, this.mod.getFile().toPath()) {
@Nullable
@Override
public IoSupplier<InputStream> getRootResource(String @NotNull ... paths) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ public BlueberryText cloneWithArgs(@Nullable Object@Nullable... args) {
return contentConsumer.accept(getContents());
}

@Override
public @NotNull Type<?> type() {
// TODO
return new Type<>(null, "blueberry");
}

@Override
public <T> @NotNull Optional<T> visit(@NotNull FormattedText.StyledContentConsumer<T> styledContentConsumer, @NotNull Style style) {
return styledContentConsumer.accept(style, getContents());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import com.mojang.logging.LogUtils;
import net.blueberrymc.common.bml.BlueberryMod;
import net.minecraft.DetectedVersion;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.AbstractPackResources;
import net.minecraft.server.packs.PackLocationInfo;
import net.minecraft.server.packs.PackResources;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.repository.KnownPack;
import net.minecraft.server.packs.repository.PackSource;
import net.minecraft.server.packs.resources.IoSupplier;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.ApiStatus;
Expand All @@ -20,9 +24,11 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.Cleaner;
import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
Expand All @@ -34,7 +40,7 @@ public class ModPackResources extends AbstractPackResources {
private final String prefix;

public ModPackResources(BlueberryMod mod) {
super("Mod Resources for " + mod.name() + " (File)", true);
super(new PackLocationInfo(mod.modId(), Component.literal("Mod Resources for " + mod.name() + " (File)"), PackSource.FEATURE, Optional.of(KnownPack.vanilla(mod.modId()))));
this.mod = mod;
this.zipFileAccess = new SharedZipFileAccess(mod.getFile());
this.prefix = "";
Expand Down Expand Up @@ -178,6 +184,7 @@ static class SharedZipFileAccess implements AutoCloseable {

SharedZipFileAccess(File file) {
this.file = file;
Cleaner.create().register(this, () -> LOGGER.error("WARNING: SharedZipFileAccess " + file.getAbsolutePath() + " was not cleaned. This will cause problems."));
}

@Nullable ZipFile getOrCreateZipFile() {
Expand Down Expand Up @@ -205,11 +212,5 @@ public void close() {
}

}

@Deprecated
protected void finalize() throws Throwable {
this.close();
super.finalize();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public void onActivityJoin(@NotNull String secret) {
lobbyManager.openNetworkChannel(lobby, NETWORK_SYSTEM_MESSAGE_ID, true);
var me = core.userManager().getCurrentUser();
var tag = me.getUsername() + "#" + me.getDiscriminator();
// TODO: translate
byte[] data = Component.Serializer.toJson(Component.literal(tag + " joined the lobby!").withStyle(ChatFormatting.YELLOW)).getBytes(StandardCharsets.UTF_8);
// TODO: translate & fix nulls
byte[] data = Component.Serializer.toJson(Component.literal(tag + " joined the lobby!").withStyle(ChatFormatting.YELLOW), null).getBytes(StandardCharsets.UTF_8);
for (DiscordUser user : lobbyManager.getMemberUsers(lobby)) {
lobbyManager.sendNetworkMessage(lobby, user.getUserId(), NETWORK_SYSTEM_MESSAGE_ID, data);
}
Expand All @@ -193,7 +193,8 @@ public void onActivityJoin(@NotNull String secret) {
public void onNetworkMessage(long lobbyId, long userId, byte channelId, byte @NotNull [] data) {
if (channelId == NETWORK_SYSTEM_MESSAGE_ID) {
try {
Component component = Component.Serializer.fromJson(new String(data));
// TODO: fix null
Component component = Component.Serializer.fromJson(new String(data), null);
if (component != null && currentUserId.get() == userId) {
var player = Minecraft.getInstance().player;
if (player != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
import com.google.gson.JsonSerializationContext;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.MutableComponent;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

public interface CustomComponentSerializer<T extends ComponentContents> {
@NotNull
Map<Class<?>, CustomComponentSerializer<?>> SERIALIZERS = new ConcurrentHashMap<>();
Component.Serializer COMPONENT_SERIALIZER = new Component.Serializer();

@NotNull
@SuppressWarnings("unchecked")
Expand All @@ -35,7 +32,8 @@ private JsonElement serializeUnchecked(@NotNull ComponentContents component, @No

@NotNull
default Object deserializeGlobal(@NotNull JsonElement element, @NotNull JsonDeserializationContext context) {
return COMPONENT_SERIALIZER.deserialize(element, element.getClass(), context);
// TODO
return Component.Serializer.fromJson(element, null);
}

static <T extends ComponentContents> void registerSerializer(@NotNull Class<T> componentClass, @NotNull CustomComponentSerializer<T> componentSerializerClass) {
Expand Down
Loading

0 comments on commit b5f7507

Please sign in to comment.