Skip to content

Commit

Permalink
Backport some changes from 1.19
Browse files Browse the repository at this point in the history
- 028debd: Add blueberry:gui.screens.mods.load
- 5f3e354: Fix blueberry text being empty
- d7e6e9e: more work
- f9bea22: Rebuild patches for 1.19-pre2
  • Loading branch information
acrylic-style committed Jun 15, 2022
1 parent 189bef2 commit 8b269ee
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.ApiStatus;

/**
* Blueberry common gui components
*/
public class BlueberryGuiComponents {
@ApiStatus.ScheduledForRemoval(inVersion = "1.5.0")
@Deprecated(forRemoval = true)
public static final TextComponent EMPTY_TEXT = new TextComponent("");
public static final ResourceLocation GUI_ICONS_LOCATION = new ResourceLocation("blueberry", "textures/gui/icons.png");
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected void init() {
this.minecraft.setScreen(this.previousScreen);
this.minecraft.setScreen(new ModListScreen(this.previousScreen));
}));
this.addRenderableWidget(new Button(this.width / 2 - 50, this.height - 38, 96, 20, new TranslatableComponent("structure_block.mode.load"), (button) ->
this.addRenderableWidget(new Button(this.width / 2 - 50, this.height - 38, 96, 20, BlueberryText.text("blueberry", "gui.screens.mods.load"), (button) ->
this.minecraft.setScreen(FileDialogScreen.create(
this,
FileDialogScreenOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.blueberrymc.common.bml.client.gui.screens;

import com.mojang.blaze3d.vertex.PoseStack;
import net.blueberrymc.client.gui.BlueberryGuiComponents;
import net.blueberrymc.client.gui.screens.BlueberryScreen;
import net.blueberrymc.common.resources.BlueberryCommonComponents;
import net.blueberrymc.common.resources.BlueberryText;
import net.blueberrymc.common.Blueberry;
import net.blueberrymc.common.bml.loading.ModLoadingError;
Expand Down Expand Up @@ -132,7 +132,7 @@ private void select() {

@Override
public @NotNull Component getNarration() {
return BlueberryGuiComponents.EMPTY_TEXT;
return BlueberryCommonComponents.EMPTY_TEXT;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package net.blueberrymc.common.resources;

import net.minecraft.network.chat.TextComponent;

public class BlueberryCommonComponents {
public static final BlueberryText MULTIPLAYER_COMPATIBLE = new BlueberryText("blueberry", "multiplayer.compatible");
public static final BlueberryText MULTIPLAYER_INCOMPATIBLE = new BlueberryText("blueberry", "multiplayer.incompatible");
public static final BlueberryText MULTIPLAYER_VANILLA = new BlueberryText("blueberry", "multiplayer.vanilla");
public static final TextComponent EMPTY_TEXT = new TextComponent("");
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.util.GsonHelper;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -35,6 +37,11 @@ public BlueberryText(@NotNull String namespace, @NotNull String path, @Nullable
this.args = arguments != null ? Arrays.asList(arguments) : null;
}

@Contract("_, _, _ -> new")
public static @NotNull BlueberryText text(@NotNull String namespace, @NotNull String path, @Nullable Object@Nullable... arguments) {
return new BlueberryText(namespace, path, arguments);
}

@NotNull
public String getNamespace() {
return namespace;
Expand Down Expand Up @@ -122,8 +129,13 @@ public String getContents() {
return text;
}

/**
* @deprecated This method will be removed in 1.5.0 due to Minecraft changes.
*/
@NotNull
@Override
@ApiStatus.ScheduledForRemoval(inVersion = "1.5.0")
@Deprecated(forRemoval = true)
public BaseComponent plainCopy() {
return new BlueberryText(this.namespace, this.path);
}
Expand All @@ -133,6 +145,15 @@ public BlueberryText cloneWithArgs(@Nullable Object@Nullable... args) {
return new BlueberryText(namespace, path, args);
}

@Override
public @NotNull String toString() {
return "BlueberryText{" +
"namespace='" + namespace + '\'' +
", path='" + path + '\'' +
", args=" + args +
'}';
}

static {
CustomComponentSerializer.registerSerializer(BlueberryText.class, new Serializer());
}
Expand Down
13 changes: 13 additions & 0 deletions Blueberry-API/src/main/java/net/blueberrymc/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import joptsimple.OptionSpec;
import net.blueberrymc.common.Blueberry;
import net.blueberrymc.common.util.VoidSafeExecutor;
import net.blueberrymc.common.util.function.ThrowableSupplier;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -231,4 +232,16 @@ public static Package getPackageRecursively(@NotNull ClassLoader cl, @NotNull St
}
return pkg;
}

@NotNull
@Contract(pure = true)
public static <T> T required(@NotNull ThrowableSupplier<T> supplier) {
try {
T value = supplier.get();
if (value == null) throw new IllegalStateException("Supplier returned null");
return value;
} catch (Exception throwable) {
throw new RuntimeException(throwable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"gui.screens.mods.refresh": "Refresh",
"gui.screens.mods.reload": "Reload",
"gui.screens.mods.recompile": "Recompile",
"gui.screens.mods.load": "Load",
"gui.screens.mods.enable": "Enable",
"gui.screens.mods.disable": "Disable",
"gui.screens.mods.config": "Config",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"gui.screens.mods.refresh": "再読み込み",
"gui.screens.mods.reload": "リロード",
"gui.screens.mods.recompile": "再コンパイル",
"gui.screens.mods.load": "読み込み",
"gui.screens.mods.enable": "有効化",
"gui.screens.mods.disable": "無効化",
"gui.screens.mods.config": "設定",
Expand Down

0 comments on commit 8b269ee

Please sign in to comment.