[NO-ORBIT] Unified Porting Branch
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterCommandEvent.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterCommandEvent.java
|
||||
@@ -37,7 +37,7 @@
|
||||
@Nullable
|
||||
public BridgedPlayer getPlayer() {
|
||||
try {
|
||||
- Player p = parseResults.getContext().getLastChild().getSource().getPlayer();
|
||||
+ Player p = parseResults.getContext().getLastChild().getSource().getPlayerOrException();
|
||||
|
||||
if (p != null)
|
||||
return BridgedPlayer.of(p);
|
@@ -0,0 +1,22 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/api/networking/CommonPacketWrapper.java
|
||||
+++ /dev/null
|
||||
@@ -1,19 +1,0 @@
|
||||
-package com.hypherionmc.craterlib.api.networking;
|
||||
-
|
||||
-import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
||||
-import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
||||
-import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
-
|
||||
-public record CommonPacketWrapper<T>(PacketHolder<T> container, T packet) implements CustomPacketPayload
|
||||
-{
|
||||
- public void encode(BridgedFriendlyByteBuf buf)
|
||||
- {
|
||||
- container().encoder().accept(packet(), buf);
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public Type<? extends CustomPacketPayload> type()
|
||||
- {
|
||||
- return container.type();
|
||||
- }
|
||||
-}
|
@@ -0,0 +1,155 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/CraterConfigScreen.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/CraterConfigScreen.java
|
||||
@@ -8,19 +8,20 @@
|
||||
import com.hypherionmc.craterlib.core.config.annotations.Tooltip;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
+import com.mojang.math.Matrix4f;
|
||||
import me.hypherionmc.moonconfig.core.conversion.SpecComment;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.Font;
|
||||
-import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.ConfirmScreen;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
+import net.minecraft.network.chat.TextComponent;
|
||||
+import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
-import org.joml.Matrix4f;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -49,7 +50,7 @@
|
||||
private boolean dragging;
|
||||
|
||||
public CraterConfigScreen(ModuleConfig config, Screen parent, Object subConfig) {
|
||||
- super(Component.translatable("cl." + config.getClass().getSimpleName().toLowerCase() + ".title"));
|
||||
+ super(new TranslatableComponent("cl." + config.getClass().getSimpleName().toLowerCase() + ".title"));
|
||||
this.parent = parent;
|
||||
this.config = config;
|
||||
if (subConfig != null) {
|
||||
@@ -64,11 +65,11 @@
|
||||
}
|
||||
|
||||
private static Component toText(Enum<?> val) {
|
||||
- return Component.translatable(val.toString());
|
||||
+ return new TranslatableComponent(val.toString());
|
||||
}
|
||||
|
||||
private static Component toText(Boolean bool) {
|
||||
- return Component.translatable(bool.toString());
|
||||
+ return new TranslatableComponent(bool.toString());
|
||||
}
|
||||
|
||||
private void setupScreenFromConfig(Object object, Class<?> clazz) {
|
||||
@@ -94,7 +95,7 @@
|
||||
tooltipLang = field.getAnnotation(Tooltip.class).value();
|
||||
}
|
||||
|
||||
- add(Component.translatable(baseLangKey),
|
||||
+ add(new TranslatableComponent(baseLangKey),
|
||||
val,
|
||||
() -> val,
|
||||
(ret) -> {
|
||||
@@ -172,24 +173,24 @@
|
||||
((List) children()).addAll(options);
|
||||
|
||||
int buttonWidths = Math.min(200, (width - 50 - 12) / 3);
|
||||
- addRenderableWidget(new InternalConfigButton(this, width / 2 - buttonWidths - 3, height - 22, buttonWidths, 20, Component.empty(), true));
|
||||
- addRenderableWidget(new InternalConfigButton(this, width / 2 + 3, height - 22, buttonWidths, 20, Component.empty(), false));
|
||||
+ addRenderableWidget(new InternalConfigButton(this, width / 2 - buttonWidths - 3, height - 22, buttonWidths, 20, new TextComponent(""), true));
|
||||
+ addRenderableWidget(new InternalConfigButton(this, width / 2 + 3, height - 22, buttonWidths, 20, new TextComponent(""), false));
|
||||
}
|
||||
|
||||
@Override
|
||||
- public void render(@NotNull GuiGraphics matrices, int mouseX, int mouseY, float delta) {
|
||||
- overlayBackground(matrices.pose(), TOP, height - BOTTOM, 32);
|
||||
+ public void render(@NotNull PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
+ overlayBackground(matrices, TOP, height - BOTTOM, 32);
|
||||
+
|
||||
renderScrollBar();
|
||||
|
||||
- matrices.pose().pushPose();
|
||||
- matrices.pose().translate(0, 0, 500.0);
|
||||
- overlayBackground(matrices.pose(), 0, TOP, 64);
|
||||
- overlayBackground(matrices.pose(), height - BOTTOM, height, 64);
|
||||
- renderShadow(matrices.pose());
|
||||
- matrices.drawCenteredString(font, getTitle(), width / 2, 9, 0xFFFFFF);
|
||||
- matrices.pose().popPose();
|
||||
-
|
||||
+ matrices.pushPose();
|
||||
+ matrices.translate(0, 0, 500.0);
|
||||
+ overlayBackground(matrices, 0, TOP, 64);
|
||||
+ overlayBackground(matrices, height - BOTTOM, height, 64);
|
||||
+ renderShadow(matrices);
|
||||
+ drawCenteredString(matrices, font, getTitle(), width / 2, 9, 0xFFFFFF);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
+ matrices.popPose();
|
||||
|
||||
int y = (int) (TOP + 4 - Math.round(scrollerAmount));
|
||||
for (Option<?> option : options) {
|
||||
@@ -268,9 +269,9 @@
|
||||
protected void overlayBackground(Matrix4f matrix, int minX, int minY, int maxX, int maxY, int red, int green, int blue, int startAlpha, int endAlpha) {
|
||||
Tesselator tesselator = Tesselator.getInstance();
|
||||
BufferBuilder buffer = tesselator.getBuilder();
|
||||
- RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
||||
- RenderSystem.setShaderTexture(0, Screen.MENU_BACKGROUND);
|
||||
+ RenderSystem.setShaderTexture(0, Screen.BACKGROUND_LOCATION);
|
||||
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
+ RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
|
||||
buffer.vertex(matrix, minX, maxY, 0.0F).uv(minX / 32.0F, maxY / 32.0F).color(red, green, blue, endAlpha).endVertex();
|
||||
buffer.vertex(matrix, maxX, maxY, 0.0F).uv(maxX / 32.0F, maxY / 32.0F).color(red, green, blue, endAlpha).endVertex();
|
||||
@@ -324,22 +325,22 @@
|
||||
@Override
|
||||
public void onClose() {
|
||||
if (isEdited()) {
|
||||
- minecraft.setScreen(new ConfirmScreen(this::acceptConfirm, Component.translatable("t.clc.quit_config"),
|
||||
- Component.translatable("t.clc.quit_config_sure"),
|
||||
- Component.translatable("t.clc.quit_discard"),
|
||||
- Component.translatable("gui.cancel")));
|
||||
+ minecraft.setScreen(new ConfirmScreen(this::acceptConfirm, new TranslatableComponent("t.clc.quit_config"),
|
||||
+ new TranslatableComponent("t.clc.quit_config_sure"),
|
||||
+ new TranslatableComponent("t.clc.quit_discard"),
|
||||
+ new TranslatableComponent("gui.cancel")));
|
||||
} else {
|
||||
minecraft.setScreen(parent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
- public boolean mouseScrolled(double d, double e, double f, double g) {
|
||||
+ public boolean mouseScrolled(double d, double e, double f) {
|
||||
if (e >= TOP && e <= height - BOTTOM) {
|
||||
scrollerAmount = Mth.clamp(scrollerAmount - f * 16.0D, 0, scrollHeight());
|
||||
return true;
|
||||
}
|
||||
- return super.mouseScrolled(d, e, f, g);
|
||||
+ return super.mouseScrolled(d, e, f);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -378,15 +379,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
- private void renderConfigTooltip(GuiGraphics stack, Font font, int mouseX, int mouseY, int startX, int startY, int sizeX, int sizeY, String title, String... description) {
|
||||
+ private void renderConfigTooltip(PoseStack stack, Font font, int mouseX, int mouseY, int startX, int startY, int sizeX, int sizeY, String title, String... description) {
|
||||
if (mouseX > startX && mouseX < startX + sizeX) {
|
||||
if (mouseY > startY && mouseY < startY + sizeY) {
|
||||
List<Component> list = new ArrayList<>();
|
||||
- list.add(Component.translatable(ChatFormatting.BOLD + "" + ChatFormatting.YELLOW + title));
|
||||
+ list.add(new TranslatableComponent(ChatFormatting.BOLD + "" + ChatFormatting.YELLOW + title));
|
||||
for (String desc : description) {
|
||||
- list.add(Component.translatable(desc));
|
||||
+ list.add(new TranslatableComponent(desc));
|
||||
}
|
||||
- stack.renderComponentTooltip(font, list, mouseX, mouseY);
|
||||
+ renderComponentTooltip(stack, list, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/AbstractConfigWidget.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/AbstractConfigWidget.java
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
||||
|
||||
+import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
-import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
public W widget;
|
||||
|
||||
@Override
|
||||
- public void render(Minecraft minecraft, Font font, int x, int y, int width, int height, GuiGraphics matrices, int mouseX, int mouseY, float delta) {
|
||||
+ public void render(Minecraft minecraft, Font font, int x, int y, int width, int height, PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
super.render(minecraft, font, x, y, width, height, matrices, mouseX, mouseY, delta);
|
||||
int i = (widget instanceof EditBox ? 1 : 0);
|
||||
- widget.setX(x + width - 200 - resetButtonOffset + i);
|
||||
- widget.setY(y + i + 1);
|
||||
+ widget.x = (x + width - 200 - resetButtonOffset + i);
|
||||
+ widget.y = (y + i + 1);
|
||||
widget.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/BaseWidget.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/BaseWidget.java
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
||||
|
||||
+import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
-import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
-import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.TextColor;
|
||||
+import net.minecraft.network.chat.TextComponent;
|
||||
|
||||
/**
|
||||
* Copied from Cloth Config Lite
|
||||
@@ -16,7 +16,7 @@
|
||||
public class BaseWidget<T> extends Option<T> {
|
||||
|
||||
public static final int resetButtonOffset = 48;
|
||||
- private final Button resetButton = addChild(Button.builder(Component.literal("Reset"), this::onResetPressed).size(46, 20).build());
|
||||
+ private final Button resetButton = addChild(new Button(0, 0, 46, 20, new TextComponent("Reset"), this::onResetPressed));
|
||||
private boolean hideReset = false;
|
||||
|
||||
private boolean isSubConfig = false;
|
||||
@@ -39,8 +39,8 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
- public void render(Minecraft minecraft, Font font, int x, int y, int width, int height, GuiGraphics matrices, int mouseX, int mouseY, float delta) {
|
||||
- MutableComponent text = Component.literal(this.text.getString());
|
||||
+ public void render(Minecraft minecraft, Font font, int x, int y, int width, int height, PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
+ MutableComponent text = new TextComponent(this.text.getString());
|
||||
boolean edited = isEdited() || hasErrors;
|
||||
if (edited) {
|
||||
text.withStyle(ChatFormatting.ITALIC);
|
||||
@@ -50,9 +50,9 @@
|
||||
} else {
|
||||
text.withStyle(ChatFormatting.GRAY);
|
||||
}
|
||||
- matrices.drawString(font, text, x, y + font.lineHeight - 2, 0xFFFFFF);
|
||||
- resetButton.setX(x + width - 46);
|
||||
- resetButton.setY(y + 1);
|
||||
+ font.draw(matrices, text, x, y, 0xFFFFFF);
|
||||
+ resetButton.x = (x + width - 46);
|
||||
+ resetButton.y = (y + 1);
|
||||
resetButton.active = isNotDefault();
|
||||
if (!hideReset) {
|
||||
resetButton.render(matrices, mouseX, mouseY, delta);
|
@@ -0,0 +1,42 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/InternalConfigButton.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/InternalConfigButton.java
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
||||
|
||||
import com.hypherionmc.craterlib.client.gui.config.CraterConfigScreen;
|
||||
-import net.minecraft.client.gui.GuiGraphics;
|
||||
+import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.components.AbstractButton;
|
||||
import net.minecraft.client.gui.narration.NarratedElementType;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
import net.minecraft.network.chat.Component;
|
||||
+import net.minecraft.network.chat.TranslatableComponent;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
@@ -22,19 +24,19 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
- protected void renderWidget(GuiGraphics arg, int i, int j, float f) {
|
||||
+ public void render(@NotNull PoseStack poseStack, int i, int j, float f) {
|
||||
if (cancel) {
|
||||
- setMessage(Component.translatable(screen.isEdited() ? "t.clc.cancel_discard" : "gui.cancel"));
|
||||
+ setMessage(new TranslatableComponent(screen.isEdited() ? "t.clc.cancel_discard" : "gui.cancel"));
|
||||
} else {
|
||||
boolean hasErrors = screen.hasErrors();
|
||||
active = screen.isEdited() && !hasErrors;
|
||||
- setMessage(Component.translatable(hasErrors ? "t.clc.error" : "t.clc.save"));
|
||||
+ setMessage(new TranslatableComponent(hasErrors ? "t.clc.error" : "t.clc.save"));
|
||||
}
|
||||
- super.renderWidget(arg, i, j, f);
|
||||
+ super.render(poseStack, i, j, f);
|
||||
}
|
||||
|
||||
@Override
|
||||
- protected void updateWidgetNarration(NarrationElementOutput narrationElementOutput) {
|
||||
+ public void updateNarration(NarrationElementOutput narrationElementOutput) {
|
||||
narrationElementOutput.add(NarratedElementType.USAGE, getMessage());
|
||||
}
|
||||
|
@@ -0,0 +1,23 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/Option.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/Option.java
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
||||
|
||||
+import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
-import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.events.AbstractContainerEventHandler;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -34,7 +34,7 @@
|
||||
@Getter
|
||||
private List<String> langKeys = new ArrayList<>();
|
||||
|
||||
- public abstract void render(Minecraft minecraft, Font font, int x, int y, int width, int height, GuiGraphics matrices, int mouseX, int mouseY, float delta);
|
||||
+ public abstract void render(Minecraft minecraft, Font font, int x, int y, int width, int height, PoseStack matrices, int mouseX, int mouseY, float delta);
|
||||
|
||||
public int height() {
|
||||
return 22;
|
@@ -0,0 +1,33 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/SubConfigWidget.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/SubConfigWidget.java
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
import com.hypherionmc.craterlib.client.gui.config.CraterConfigScreen;
|
||||
import com.hypherionmc.craterlib.core.config.ModuleConfig;
|
||||
+import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
-import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
-import net.minecraft.network.chat.Component;
|
||||
+import net.minecraft.network.chat.TranslatableComponent;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
@@ -23,12 +23,12 @@
|
||||
this.subConfig = subConfig;
|
||||
this.screen = screen;
|
||||
|
||||
- this.widget = addChild(Button.builder(Component.translatable("t.clc.opensubconfig"), this::openSubConfig).size(200, buttonHeight).build());
|
||||
+ this.widget = addChild(new Button(0, 0, 200, buttonHeight, new TranslatableComponent("t.clc.opensubconfig"), this::openSubConfig));
|
||||
}
|
||||
|
||||
@Override
|
||||
- public void render(Minecraft minecraft, Font font, int x, int y, int width, int height, GuiGraphics matrices, int mouseX, int mouseY, float delta) {
|
||||
- this.text = Component.literal(subConfig.getClass().getSimpleName().toLowerCase());
|
||||
+ public void render(Minecraft minecraft, Font font, int x, int y, int width, int height, PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
+ this.text = new TranslatableComponent(subConfig.getClass().getSimpleName().toLowerCase());
|
||||
this.hideReset();
|
||||
super.render(minecraft, font, x, y, width, height, matrices, mouseX, mouseY, delta);
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/TextConfigOption.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/TextConfigOption.java
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
||||
|
||||
+import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
-import net.minecraft.client.gui.GuiGraphics;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
- public void render(Minecraft minecraft, Font font, int x, int y, int width, int height, GuiGraphics matrices, int mouseX, int mouseY, float delta) {
|
||||
+ public void render(Minecraft minecraft, Font font, int x, int y, int width, int height, PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
widget.setTextColor(hasErrors ? 16733525 : 14737632);
|
||||
super.render(minecraft, font, x, y, width, height, matrices, mouseX, mouseY, delta);
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/ToggleButton.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/ToggleButton.java
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.network.chat.Component;
|
||||
+import net.minecraft.network.chat.TextComponent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
@@ -18,7 +19,7 @@
|
||||
public ToggleButton(List<T> options, Function<T, Component> toComponent) {
|
||||
this.options = options;
|
||||
this.toComponent = toComponent;
|
||||
- this.widget = addChild(Button.builder(Component.empty(), this::switchNext).size(buttonWidth, buttonHeight).build());
|
||||
+ this.widget = addChild(new Button(0, 0, buttonWidth, buttonHeight, new TextComponent(""), this::switchNext));
|
||||
}
|
||||
|
||||
@Override
|
@@ -0,0 +1,43 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/core/networking/data/PacketHolder.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/core/networking/data/PacketHolder.java
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.hypherionmc.craterlib.core.networking.data;
|
||||
|
||||
-import com.hypherionmc.craterlib.api.networking.CommonPacketWrapper;
|
||||
import com.hypherionmc.craterlib.nojang.network.BridgedFriendlyByteBuf;
|
||||
import com.hypherionmc.craterlib.nojang.resources.ResourceIdentifier;
|
||||
-import net.minecraft.network.FriendlyByteBuf;
|
||||
-import net.minecraft.network.codec.StreamCodec;
|
||||
-import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
@@ -14,27 +10,9 @@
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
-public record PacketHolder<T>(CustomPacketPayload.Type<? extends CustomPacketPayload> type,
|
||||
+public record PacketHolder<T>(ResourceIdentifier type,
|
||||
Class<T> messageType,
|
||||
BiConsumer<T, BridgedFriendlyByteBuf> encoder,
|
||||
Function<BridgedFriendlyByteBuf, T> decoder,
|
||||
Consumer<PacketContext<T>> handler) {
|
||||
-
|
||||
- public PacketHolder(ResourceIdentifier packetId, Class<T> messageType, BiConsumer<T, BridgedFriendlyByteBuf> encoder, Function<BridgedFriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
||||
- this(new CustomPacketPayload.Type<>(packetId.toMojang()), messageType, encoder, decoder, handler);
|
||||
- }
|
||||
-
|
||||
- @SuppressWarnings("unchecked")
|
||||
- public <K extends CustomPacketPayload> CustomPacketPayload.Type<K> getType()
|
||||
- {
|
||||
- return (CustomPacketPayload.Type<K>) type();
|
||||
- }
|
||||
-
|
||||
- public StreamCodec<FriendlyByteBuf, CommonPacketWrapper> getCodec()
|
||||
- {
|
||||
- return CustomPacketPayload.codec(
|
||||
- (packet, buf) -> this.encoder().accept((T)packet.packet(), BridgedFriendlyByteBuf.of(buf)),
|
||||
- (buf) -> new CommonPacketWrapper<>(this, this.decoder().apply(BridgedFriendlyByteBuf.of(buf))));
|
||||
- }
|
||||
-
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/CommandMixin.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/CommandMixin.java
|
||||
@@ -3,35 +3,55 @@
|
||||
import com.google.common.base.Throwables;
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterCommandEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
+import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.ParseResults;
|
||||
+import com.mojang.brigadier.StringReader;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
+import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
+import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(Commands.class)
|
||||
public class CommandMixin {
|
||||
|
||||
- @Inject(method = "performCommand",
|
||||
- at = @At(value = "INVOKE",
|
||||
- target = "Lnet/minecraft/commands/Commands;finishParsing(Lcom/mojang/brigadier/ParseResults;Ljava/lang/String;Lnet/minecraft/commands/CommandSourceStack;)Lcom/mojang/brigadier/context/ContextChain;",
|
||||
- shift = At.Shift.BEFORE
|
||||
- ), cancellable = true
|
||||
+ @Shadow
|
||||
+ @Final
|
||||
+ private CommandDispatcher<CommandSourceStack> dispatcher;
|
||||
+
|
||||
+ @Inject(
|
||||
+ method = "performCommand",
|
||||
+ at = @At(
|
||||
+ value = "INVOKE",
|
||||
+ target = "Lnet/minecraft/util/profiling/ProfilerFiller;push(Ljava/lang/String;)V",
|
||||
+ shift = At.Shift.AFTER
|
||||
+ ),
|
||||
+ cancellable = true
|
||||
)
|
||||
- private void injectCommandEvent(ParseResults<CommandSourceStack> stackParseResults, String command, CallbackInfo ci) {
|
||||
- CraterCommandEvent commandEvent = CraterCommandEvent.of(stackParseResults, command);
|
||||
- CraterEventBus.INSTANCE.postEvent(commandEvent);
|
||||
- if (commandEvent.wasCancelled()) {
|
||||
- ci.cancel();
|
||||
- return;
|
||||
- }
|
||||
-
|
||||
- if (commandEvent.getException() != null) {
|
||||
- Throwables.throwIfUnchecked(commandEvent.getException());
|
||||
- ci.cancel();
|
||||
- }
|
||||
+ private void injectCommandEvent(CommandSourceStack stack, String command, CallbackInfoReturnable<Integer> cir) {
|
||||
+ StringReader stringreader = new StringReader(command);
|
||||
+ if (stringreader.canRead() && stringreader.peek() == '/') {
|
||||
+ stringreader.skip();
|
||||
+ }
|
||||
+
|
||||
+ try {
|
||||
+ ParseResults<CommandSourceStack> parse = dispatcher.parse(stringreader, stack);
|
||||
+
|
||||
+ CraterCommandEvent commandEvent = CraterCommandEvent.of(parse, command);
|
||||
+ CraterEventBus.INSTANCE.postEvent(commandEvent);
|
||||
+ if (commandEvent.wasCancelled()) {
|
||||
+ cir.setReturnValue(1);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ if (commandEvent.getException() != null) {
|
||||
+ Throwables.throwIfUnchecked(commandEvent.getException());
|
||||
+ cir.setReturnValue(1);
|
||||
+ }
|
||||
+ } catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/PlayerAdvancementsMixin.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/PlayerAdvancementsMixin.java
|
||||
@@ -5,7 +5,6 @@
|
||||
import com.hypherionmc.craterlib.nojang.advancements.BridgedAdvancement;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
-import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -21,11 +20,10 @@
|
||||
private ServerPlayer player;
|
||||
|
||||
@Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V", shift = At.Shift.AFTER))
|
||||
- private void injectAdvancementEvent(AdvancementHolder advancementHolder, String string, CallbackInfoReturnable<Boolean> cir) {
|
||||
- Advancement advancement = advancementHolder.value();
|
||||
+ private void injectAdvancementEvent(Advancement advancement, String string, CallbackInfoReturnable<Boolean> cir) {
|
||||
+ if (advancement.getDisplay() == null || !advancement.getDisplay().shouldAnnounceChat())
|
||||
+ return;
|
||||
|
||||
- if (advancement.display().isPresent() && advancement.display().get().shouldAnnounceChat()) {
|
||||
- CraterEventBus.INSTANCE.postEvent(new CraterAdvancementEvent(BridgedPlayer.of(this.player), BridgedAdvancement.of(advancementHolder.value())));
|
||||
- }
|
||||
+ CraterEventBus.INSTANCE.postEvent(new CraterAdvancementEvent(BridgedPlayer.of(this.player), BridgedAdvancement.of(advancement)));
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/PlayerListMixin.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/PlayerListMixin.java
|
||||
@@ -9,9 +9,9 @@
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.network.Connection;
|
||||
+import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
-import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -20,20 +20,21 @@
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
+import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Mixin(PlayerList.class)
|
||||
public class PlayerListMixin {
|
||||
|
||||
- @Inject(method = "broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Ljava/util/function/Function;Z)V", at = @At("HEAD"))
|
||||
- private void injectBroadcastEvent(Component component, Function<ServerPlayer, Component> function, boolean bl, CallbackInfo ci) {
|
||||
+ @Inject(method = "broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V", at = @At("HEAD"))
|
||||
+ private void injectBroadcast(Component component, ChatType chatType, UUID uUID, CallbackInfo ci) {
|
||||
String thread = Thread.currentThread().getStackTrace()[3].getClassName();
|
||||
- MessageBroadcastEvent event = new MessageBroadcastEvent(ChatUtils.mojangToAdventure(component), (f) -> ChatUtils.mojangToAdventure(component), bl, thread);
|
||||
+ MessageBroadcastEvent event = new MessageBroadcastEvent(ChatUtils.mojangToAdventure(component), (s) -> null, false, thread);
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
}
|
||||
|
||||
@Inject(method = "placeNewPlayer", at = @At("TAIL"))
|
||||
- private void injectPlayerLoginEvent(Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, CallbackInfo ci) {
|
||||
+ private void injectPlayerLoginEvent(Connection arg, ServerPlayer serverPlayer, CallbackInfo ci) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer)));
|
||||
}
|
||||
|
@@ -0,0 +1,11 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/ClientLevelMixin.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/ClientLevelMixin.java
|
||||
@@ -15,7 +15,7 @@
|
||||
public class ClientLevelMixin {
|
||||
|
||||
@Inject(method = "addEntity", at = @At("HEAD"))
|
||||
- private void injectSinglePlayerJoinEvent(Entity entity, CallbackInfo ci) {
|
||||
+ private void injectSinglePlayerJoinEvent(int i, Entity entity, CallbackInfo ci) {
|
||||
if (entity instanceof Player player) {
|
||||
CraterSinglePlayerEvent.PlayerLogin playerLogin = new CraterSinglePlayerEvent.PlayerLogin(BridgedPlayer.of(player));
|
||||
CraterEventBus.INSTANCE.postEvent(playerLogin);
|
@@ -0,0 +1,13 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/RealmsMainScreenMixin.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/RealmsMainScreenMixin.java
|
||||
@@ -14,8 +14,8 @@
|
||||
@Mixin(RealmsMainScreen.class)
|
||||
public class RealmsMainScreenMixin {
|
||||
|
||||
- @Inject(at = @At("HEAD"), method = "play(Lcom/mojang/realmsclient/dto/RealmsServer;Lnet/minecraft/client/gui/screens/Screen;Z)V")
|
||||
- private static void play(RealmsServer serverData, Screen arg2, boolean bl, CallbackInfo ci) {
|
||||
+ @Inject(at = @At("HEAD"), method = "play")
|
||||
+ private void play(RealmsServer serverData, Screen arg2, CallbackInfo ci) {
|
||||
PlayerJoinRealmEvent playerJoinRealm = new PlayerJoinRealmEvent(BridgedRealmsServer.of(serverData));
|
||||
CraterEventBus.INSTANCE.postEvent(playerJoinRealm);
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/nojang/advancements/BridgedAdvancement.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/nojang/advancements/BridgedAdvancement.java
|
||||
@@ -11,8 +11,8 @@
|
||||
private final Advancement internal;
|
||||
|
||||
public Optional<BridgedDisplayInfo> displayInfo() {
|
||||
- if (internal.display().isPresent()) {
|
||||
- return Optional.of(BridgedDisplayInfo.of(internal.display().get()));
|
||||
+ if (internal.getDisplay() != null) {
|
||||
+ return Optional.of(BridgedDisplayInfo.of(internal.getDisplay()));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
@@ -0,0 +1,20 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java
|
||||
@@ -35,7 +35,7 @@
|
||||
}
|
||||
|
||||
public boolean isRealmServer() {
|
||||
- return internal.getCurrentServer() != null && internal.getCurrentServer().isRealm();
|
||||
+ return internal.getCurrentServer() != null && internal.isConnectedToRealms();
|
||||
}
|
||||
|
||||
public boolean isSinglePlayer() {
|
||||
@@ -59,7 +59,7 @@
|
||||
}
|
||||
|
||||
public UUID getPlayerId() {
|
||||
- return internal.getUser().getProfileId();
|
||||
+ return internal.getUser().getGameProfile().getId();
|
||||
}
|
||||
|
||||
@Nullable
|
@@ -0,0 +1,31 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java
|
||||
@@ -3,6 +3,7 @@
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
+import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.multiplayer.ServerStatusPinger;
|
||||
|
||||
@@ -24,13 +25,17 @@
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
- if (internal.players == null) {
|
||||
+ if (!internal.pinged || internal.status.getString() == null) {
|
||||
try {
|
||||
- new ServerStatusPinger().pingServer(internal, () -> {}, () -> {});
|
||||
+ new ServerStatusPinger().pingServer(internal, () -> {});
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
- return internal.players == null ? 0 : internal.players.max();
|
||||
+ try {
|
||||
+ return Integer.parseInt(ChatFormatting.stripFormatting(internal.status.getString()).split("/")[1]);
|
||||
+ } catch (Exception ignored) {}
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
public ServerData toMojang() {
|
@@ -0,0 +1,11 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/nojang/commands/BridgedCommandSourceStack.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/nojang/commands/BridgedCommandSourceStack.java
|
||||
@@ -13,7 +13,7 @@
|
||||
private final CommandSourceStack internal;
|
||||
|
||||
public void sendSuccess(Supplier<Component> supplier, boolean bl) {
|
||||
- internal.sendSuccess(() -> ChatUtils.adventureToMojang(supplier.get()), bl);
|
||||
+ internal.sendSuccess(ChatUtils.adventureToMojang(supplier.get()), bl);
|
||||
}
|
||||
|
||||
public CommandSourceStack toMojang() {
|
@@ -0,0 +1,28 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/nojang/commands/BridgedFakePlayer.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/nojang/commands/BridgedFakePlayer.java
|
||||
@@ -5,6 +5,7 @@
|
||||
import net.minecraft.commands.CommandSource;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
+import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
@@ -37,14 +38,14 @@
|
||||
public final Consumer<net.kyori.adventure.text.Component> errorCallback;
|
||||
|
||||
MojangBridge(MinecraftServer server, int perm, String name, BiConsumer<Supplier<net.kyori.adventure.text.Component>, Boolean> successCallback, Consumer<net.kyori.adventure.text.Component> errorCallback) {
|
||||
- super(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, server.overworld(), perm, name, Component.literal(name), server, null);
|
||||
+ super(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, server.overworld(), perm, name, new TextComponent(name), server, null);
|
||||
this.successCallback = successCallback;
|
||||
this.errorCallback = errorCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
- public void sendSuccess(Supplier<Component> supplier, boolean bl) {
|
||||
- successCallback.accept(() -> ChatUtils.mojangToAdventure(supplier.get()), bl);
|
||||
+ public void sendSuccess(Component supplier, boolean bl) {
|
||||
+ successCallback.accept(() -> ChatUtils.mojangToAdventure(supplier), bl);
|
||||
}
|
||||
|
||||
@Override
|
@@ -0,0 +1,11 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/nojang/commands/CommandsRegistry.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/nojang/commands/CommandsRegistry.java
|
||||
@@ -70,7 +70,7 @@
|
||||
profiles.forEach(p -> bridgedGameProfiles.add(BridgedGameProfile.of(p)));
|
||||
|
||||
((TriConsumer<BridgedPlayer, List<BridgedGameProfile>, BridgedCommandSourceStack>) pair.getRight())
|
||||
- .accept(BridgedPlayer.of(context.getSource().getPlayer()), bridgedGameProfiles, BridgedCommandSourceStack.of(context.getSource()));
|
||||
+ .accept(BridgedPlayer.of(context.getSource().getPlayerOrException()), bridgedGameProfiles, BridgedCommandSourceStack.of(context.getSource()));
|
||||
return 1;
|
||||
}
|
||||
|
@@ -0,0 +1,29 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/nojang/server/BridgedMinecraftServer.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/nojang/server/BridgedMinecraftServer.java
|
||||
@@ -7,6 +7,8 @@
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.SharedConstants;
|
||||
+import net.minecraft.Util;
|
||||
+import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.players.UserBanListEntry;
|
||||
import net.minecraft.server.players.UserWhiteListEntry;
|
||||
@@ -44,7 +46,7 @@
|
||||
}
|
||||
|
||||
public void broadcastSystemMessage(Component text, boolean bl) {
|
||||
- internal.getPlayerList().broadcastSystemMessage(ChatUtils.adventureToMojang(text), bl);
|
||||
+ internal.getPlayerList().broadcastMessage(ChatUtils.adventureToMojang(text), ChatType.SYSTEM, Util.NIL_UUID);
|
||||
}
|
||||
|
||||
public boolean isPlayerBanned(BridgedGameProfile profile) {
|
||||
@@ -81,7 +83,7 @@
|
||||
}
|
||||
|
||||
public void executeCommand(BridgedMinecraftServer server, BridgedFakePlayer player, String command) {
|
||||
- internal.getCommands().performPrefixedCommand(player.toMojang(), command);
|
||||
+ internal.getCommands().performCommand(player.toMojang(), command);
|
||||
}
|
||||
|
||||
public MinecraftServer toMojang() {
|
@@ -0,0 +1,65 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/utils/ChatUtils.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/utils/ChatUtils.java
|
||||
@@ -5,22 +5,31 @@
|
||||
import me.hypherionmc.mcdiscordformatter.minecraft.MinecraftSerializer;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
+import net.kyori.adventure.text.serializer.json.JSONOptions;
|
||||
+import net.kyori.option.OptionState;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.Util;
|
||||
-import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
+import net.minecraft.network.chat.TextComponent;
|
||||
+import net.minecraft.network.chat.TranslatableComponent;
|
||||
|
||||
public class ChatUtils {
|
||||
|
||||
+ private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().options(
|
||||
+ OptionState.optionState()
|
||||
+ .value(JSONOptions.EMIT_HOVER_SHOW_ENTITY_ID_AS_INT_ARRAY, false)
|
||||
+ .value(JSONOptions.EMIT_HOVER_EVENT_TYPE, JSONOptions.HoverEventValueMode.MODERN_ONLY).build()
|
||||
+ ).build();
|
||||
+
|
||||
public static Component adventureToMojang(net.kyori.adventure.text.Component inComponent) {
|
||||
- final String serialised = GsonComponentSerializer.gson().serialize(inComponent);
|
||||
- return Component.Serializer.fromJson(serialised, RegistryAccess.EMPTY);
|
||||
+ final String serialised = adventureSerializer.serialize(inComponent);
|
||||
+ return Component.Serializer.fromJson(serialised);
|
||||
}
|
||||
|
||||
public static net.kyori.adventure.text.Component mojangToAdventure(Component inComponent) {
|
||||
- final String serialised = Component.Serializer.toJson(inComponent, RegistryAccess.EMPTY);
|
||||
- return GsonComponentSerializer.gson().deserialize(serialised);
|
||||
+ final String serialised = Component.Serializer.toJson(inComponent);
|
||||
+ return adventureSerializer.deserialize(serialised);
|
||||
}
|
||||
|
||||
// Some text components contain duplicate text, resulting in duplicate messages
|
||||
@@ -28,7 +37,7 @@
|
||||
public static Component safeCopy(Component inComponent) {
|
||||
String value = inComponent.getString();
|
||||
Style style = inComponent.getStyle();
|
||||
- return Component.literal(value).withStyle(style);
|
||||
+ return new TextComponent(value).withStyle(style);
|
||||
}
|
||||
|
||||
public static String strip(String inString, String... toStrip) {
|
||||
@@ -57,7 +66,7 @@
|
||||
}
|
||||
|
||||
public static net.kyori.adventure.text.Component resolve(String component, boolean formatted) {
|
||||
- Component returnVal = Component.literal(component);
|
||||
+ Component returnVal = new TextComponent(component);
|
||||
if (formatted) {
|
||||
returnVal = MinecraftSerializer.INSTANCE.serialize(component);
|
||||
}
|
||||
@@ -85,6 +94,6 @@
|
||||
if (identifier == null)
|
||||
return net.kyori.adventure.text.Component.text("Unknown");
|
||||
|
||||
- return mojangToAdventure(Component.translatable(Util.makeDescriptionId("biome", identifier.toMojang())));
|
||||
+ return mojangToAdventure(new TranslatableComponent(Util.makeDescriptionId("biome", identifier.toMojang())));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user