Compare commits
5 Commits
old/1.18.2
...
old/1.20
Author | SHA1 | Date | |
---|---|---|---|
31ad6dd453 | |||
8ccbb6b9e6 | |||
0ee676e724 | |||
2ab4e67c1d | |||
7504c231ff |
@@ -9,7 +9,7 @@ pipeline {
|
||||
stage("Notify Discord") {
|
||||
steps {
|
||||
discordSend webhookURL: env.FDD_WH_ADMIN,
|
||||
title: "Deploy Started: CraterLib 1.18.2 Deploy #${BUILD_NUMBER}",
|
||||
title: "Deploy Started: CraterLib 1.20 Deploy #${BUILD_NUMBER}",
|
||||
link: env.BUILD_URL,
|
||||
result: 'SUCCESS',
|
||||
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})"
|
||||
@@ -38,7 +38,7 @@ pipeline {
|
||||
deleteDir()
|
||||
|
||||
discordSend webhookURL: env.FDD_WH_ADMIN,
|
||||
title: "CraterLib 1.18.2 Deploy #${BUILD_NUMBER}",
|
||||
title: "CraterLib 1.20 Deploy #${BUILD_NUMBER}",
|
||||
link: env.BUILD_URL,
|
||||
result: currentBuild.currentResult,
|
||||
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})\nStatus: ${currentBuild.currentResult}"
|
||||
|
@@ -13,7 +13,7 @@ pipeline {
|
||||
stage("Notify Discord") {
|
||||
steps {
|
||||
discordSend webhookURL: env.SSS_WEBHOOK,
|
||||
title: "Deploy Started: ${projectName} 1.18.2 Deploy #${BUILD_NUMBER}",
|
||||
title: "Deploy Started: ${projectName} 1.20.1/2 Deploy #${BUILD_NUMBER}",
|
||||
link: env.BUILD_URL,
|
||||
result: 'SUCCESS',
|
||||
description: "Build: [${BUILD_NUMBER}](${env.BUILD_URL})"
|
||||
@@ -54,7 +54,7 @@ pipeline {
|
||||
versionName: "Snapshot 1.1.${BUILD_NUMBER}",
|
||||
version: "1.1.${BUILD_NUMBER}",
|
||||
modLoaders: "forge|fabric|quilt",
|
||||
minecraftVersions: "1.18.2",
|
||||
minecraftVersions: "1.20|1.20.1",
|
||||
failWebhook: env.SSS_WEBHOOK,
|
||||
publishWebhooks: "${env.SSS_WEBHOOK}|${env.FDD_WH}"
|
||||
|
||||
|
@@ -2,7 +2,7 @@ archivesBaseName = "${mod_name.replace(" ", "")}-Common-${minecraft_version}"
|
||||
|
||||
dependencies {
|
||||
implementation "com.hypherionmc:rpcsdk:1.0"
|
||||
implementation("me.hypherionmc.sdlink:mcdiscordformatter-1.18.1:2.0.0")
|
||||
implementation("me.hypherionmc.sdlink:mcdiscordformatter-1.19.1:2.0.0")
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
@@ -10,7 +10,7 @@ shadowJar {
|
||||
dependencies {
|
||||
include(dependency("me.hypherionmc.moon-config:core:${moon_config}"))
|
||||
include(dependency("me.hypherionmc.moon-config:toml:${moon_config}"))
|
||||
include(dependency("me.hypherionmc.sdlink:mcdiscordformatter-1.18.1:2.0.0"))
|
||||
include(dependency("me.hypherionmc.sdlink:mcdiscordformatter-1.19.1:2.0.0"))
|
||||
|
||||
relocate 'me.hypherionmc.moonconfig', 'shadow.hypherionmc.moonconfig'
|
||||
relocate 'me.hypherionmc.mcdiscordformatter', 'shadow.hypherionmc.mcdiscordformatter'
|
||||
|
@@ -1,21 +1,21 @@
|
||||
package com.hypherionmc.craterlib.api.event.server;
|
||||
|
||||
import com.hypherionmc.craterlib.core.event.CraterEvent;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class MessageBroadcastEvent extends CraterEvent {
|
||||
|
||||
private final Component component;
|
||||
private final UUID uuid;
|
||||
private final ChatType bl;
|
||||
private final Function<ServerPlayer, Component> function;
|
||||
private final boolean bl;
|
||||
private final String threadName;
|
||||
|
||||
public MessageBroadcastEvent(Component component, UUID uuid, ChatType bl, String threadName) {
|
||||
public MessageBroadcastEvent(Component component, Function<ServerPlayer, Component> function, boolean bl, String threadName) {
|
||||
this.component = component;
|
||||
this.uuid = uuid;
|
||||
this.function = function;
|
||||
this.bl = bl;
|
||||
this.threadName = threadName;
|
||||
}
|
||||
@@ -24,12 +24,12 @@ public class MessageBroadcastEvent extends CraterEvent {
|
||||
return component;
|
||||
}
|
||||
|
||||
public ChatType getChatType() {
|
||||
return this.bl;
|
||||
public boolean isBl() {
|
||||
return bl;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
public Function<ServerPlayer, Component> getFunction() {
|
||||
return function;
|
||||
}
|
||||
|
||||
public String getThreadName() {
|
||||
|
@@ -0,0 +1,28 @@
|
||||
package com.hypherionmc.craterlib.api.networking;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
public interface CraterNetworkHandler {
|
||||
|
||||
<T> void sendToServer(T packet);
|
||||
|
||||
<T> void sendToServer(T packet, boolean ignoreCheck);
|
||||
|
||||
<T> void sendToClient(T packet, ServerPlayer player);
|
||||
|
||||
default <T> void sendToClients(T packet, List<ServerPlayer> players) {
|
||||
for (ServerPlayer player : players) {
|
||||
sendToClient(packet, player);
|
||||
}
|
||||
}
|
||||
|
||||
default <T> void sendToAllClients(T packet, MinecraftServer server) {
|
||||
sendToClients(packet, server.getPlayerList().getPlayers());
|
||||
}
|
||||
}
|
@@ -2,17 +2,16 @@ package com.hypherionmc.craterlib.client.gui.config;
|
||||
|
||||
import com.hypherionmc.craterlib.CraterConstants;
|
||||
import com.hypherionmc.craterlib.client.gui.config.widgets.*;
|
||||
import com.hypherionmc.craterlib.core.abstraction.text.AbstractComponent;
|
||||
import com.hypherionmc.craterlib.core.config.ModuleConfig;
|
||||
import com.hypherionmc.craterlib.core.config.annotations.HideFromScreen;
|
||||
import com.hypherionmc.craterlib.core.config.annotations.SubConfig;
|
||||
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;
|
||||
@@ -21,6 +20,7 @@ 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 +49,7 @@ public class CraterConfigScreen extends Screen {
|
||||
private boolean dragging;
|
||||
|
||||
public CraterConfigScreen(ModuleConfig config, Screen parent, Object subConfig) {
|
||||
super(AbstractComponent.translatable("cl." + config.getClass().getSimpleName().toLowerCase() + ".title"));
|
||||
super(Component.translatable("cl." + config.getClass().getSimpleName().toLowerCase() + ".title"));
|
||||
this.parent = parent;
|
||||
this.config = config;
|
||||
if (subConfig != null) {
|
||||
@@ -64,11 +64,11 @@ public class CraterConfigScreen extends Screen {
|
||||
}
|
||||
|
||||
private static Component toText(Enum<?> val) {
|
||||
return AbstractComponent.translatable(val.toString());
|
||||
return Component.translatable(val.toString());
|
||||
}
|
||||
|
||||
private static Component toText(Boolean bool) {
|
||||
return AbstractComponent.translatable(bool.toString());
|
||||
return Component.translatable(bool.toString());
|
||||
}
|
||||
|
||||
private void setupScreenFromConfig(Object object, Class<?> clazz) {
|
||||
@@ -94,7 +94,7 @@ public class CraterConfigScreen extends Screen {
|
||||
tooltipLang = field.getAnnotation(Tooltip.class).value();
|
||||
}
|
||||
|
||||
add(AbstractComponent.translatable(baseLangKey),
|
||||
add(Component.translatable(baseLangKey),
|
||||
val,
|
||||
() -> val,
|
||||
(ret) -> {
|
||||
@@ -172,24 +172,24 @@ public class CraterConfigScreen extends Screen {
|
||||
((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, AbstractComponent.empty(), true));
|
||||
addRenderableWidget(new InternalConfigButton(this, width / 2 + 3, height - 22, buttonWidths, 20, AbstractComponent.empty(), false));
|
||||
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));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(@NotNull PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
overlayBackground(matrices, TOP, height - BOTTOM, 32);
|
||||
public void render(@NotNull GuiGraphics matrices, int mouseX, int mouseY, float delta) {
|
||||
overlayBackground(matrices.pose(), TOP, height - BOTTOM, 32);
|
||||
|
||||
renderScrollBar();
|
||||
|
||||
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);
|
||||
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);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
matrices.popPose();
|
||||
matrices.pose().popPose();
|
||||
|
||||
int y = (int) (TOP + 4 - Math.round(scrollerAmount));
|
||||
for (Option<?> option : options) {
|
||||
@@ -325,10 +325,10 @@ public class CraterConfigScreen extends Screen {
|
||||
@Override
|
||||
public void onClose() {
|
||||
if (isEdited()) {
|
||||
minecraft.setScreen(new ConfirmScreen(this::acceptConfirm, AbstractComponent.translatable("t.clc.quit_config"),
|
||||
AbstractComponent.translatable("t.clc.quit_config_sure"),
|
||||
AbstractComponent.translatable("t.clc.quit_discard"),
|
||||
AbstractComponent.translatable("gui.cancel")));
|
||||
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")));
|
||||
} else {
|
||||
minecraft.setScreen(parent);
|
||||
}
|
||||
@@ -379,15 +379,15 @@ public class CraterConfigScreen extends Screen {
|
||||
}
|
||||
}
|
||||
|
||||
private void renderConfigTooltip(PoseStack stack, Font font, int mouseX, int mouseY, int startX, int startY, int sizeX, int sizeY, String title, String... description) {
|
||||
private void renderConfigTooltip(GuiGraphics 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(AbstractComponent.translatable(ChatFormatting.BOLD + "" + ChatFormatting.YELLOW + title));
|
||||
list.add(Component.translatable(ChatFormatting.BOLD + "" + ChatFormatting.YELLOW + title));
|
||||
for (String desc : description) {
|
||||
list.add(AbstractComponent.translatable(desc));
|
||||
list.add(Component.translatable(desc));
|
||||
}
|
||||
renderComponentTooltip(stack, list, mouseX, mouseY);
|
||||
stack.renderComponentTooltip(font, list, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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 class AbstractConfigWidget<T, W extends AbstractWidget> extends BaseWidge
|
||||
public W widget;
|
||||
|
||||
@Override
|
||||
public void render(Minecraft minecraft, Font font, int x, int y, int width, int height, PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
public void render(Minecraft minecraft, Font font, int x, int y, int width, int height, GuiGraphics 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.x = (x + width - 200 - resetButtonOffset + i);
|
||||
widget.y = (y + i + 1);
|
||||
widget.setX(x + width - 200 - resetButtonOffset + i);
|
||||
widget.setY(y + i + 1);
|
||||
widget.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
||||
|
||||
import com.hypherionmc.craterlib.core.abstraction.text.AbstractComponent;
|
||||
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;
|
||||
|
||||
@@ -16,7 +16,7 @@ import net.minecraft.network.chat.TextColor;
|
||||
public class BaseWidget<T> extends Option<T> {
|
||||
|
||||
public static final int resetButtonOffset = 48;
|
||||
private final Button resetButton = addChild(new Button(0, 0, 46, 20, AbstractComponent.literal("Reset"), this::onResetPressed));
|
||||
private final Button resetButton = addChild(Button.builder(Component.literal("Reset"), this::onResetPressed).size(46, 20).build());
|
||||
private boolean hideReset = false;
|
||||
|
||||
private boolean isSubConfig = false;
|
||||
@@ -39,8 +39,8 @@ public class BaseWidget<T> extends Option<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
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 = AbstractComponent.literal(this.text.getString());
|
||||
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());
|
||||
boolean edited = isEdited() || hasErrors;
|
||||
if (edited) {
|
||||
text.withStyle(ChatFormatting.ITALIC);
|
||||
@@ -50,9 +50,9 @@ public class BaseWidget<T> extends Option<T> {
|
||||
} else {
|
||||
text.withStyle(ChatFormatting.GRAY);
|
||||
}
|
||||
font.draw(matrices, text, x, y, 0xFFFFFF);
|
||||
resetButton.x = (x + width - 46);
|
||||
resetButton.y = (y + 1);
|
||||
matrices.drawString(font, text, x, y, 0xFFFFFF);
|
||||
resetButton.setX(x + width - 46);
|
||||
resetButton.setY(y + 1);
|
||||
resetButton.active = isNotDefault();
|
||||
if (!hideReset) {
|
||||
resetButton.render(matrices, mouseX, mouseY, delta);
|
||||
|
@@ -1,8 +1,7 @@
|
||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
||||
|
||||
import com.hypherionmc.craterlib.client.gui.config.CraterConfigScreen;
|
||||
import com.hypherionmc.craterlib.core.abstraction.text.AbstractComponent;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.AbstractButton;
|
||||
import net.minecraft.client.gui.narration.NarratedElementType;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
@@ -24,17 +23,22 @@ public class InternalConfigButton extends AbstractButton {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(@NotNull PoseStack poseStack, int i, int j, float f) {
|
||||
public void render(@NotNull GuiGraphics poseStack, int i, int j, float f) {
|
||||
if (cancel) {
|
||||
setMessage(AbstractComponent.translatable(screen.isEdited() ? "t.clc.cancel_discard" : "gui.cancel"));
|
||||
setMessage(Component.translatable(screen.isEdited() ? "t.clc.cancel_discard" : "gui.cancel"));
|
||||
} else {
|
||||
boolean hasErrors = screen.hasErrors();
|
||||
active = screen.isEdited() && !hasErrors;
|
||||
setMessage(AbstractComponent.translatable(hasErrors ? "t.clc.error" : "t.clc.save"));
|
||||
setMessage(Component.translatable(hasErrors ? "t.clc.error" : "t.clc.save"));
|
||||
}
|
||||
super.render(poseStack, i, j, f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateWidgetNarration(NarrationElementOutput narrationElementOutput) {
|
||||
narrationElementOutput.add(NarratedElementType.USAGE, getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPress() {
|
||||
if (cancel) {
|
||||
@@ -45,8 +49,4 @@ public class InternalConfigButton extends AbstractButton {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateNarration(NarrationElementOutput narrationElementOutput) {
|
||||
narrationElementOutput.add(NarratedElementType.USAGE, getMessage());
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,13 @@
|
||||
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.events.AbstractContainerEventHandler;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -38,7 +38,7 @@ public abstract class Option<T> extends AbstractContainerEventHandler {
|
||||
this.langKeys = langKeys;
|
||||
}
|
||||
|
||||
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 abstract void render(Minecraft minecraft, Font font, int x, int y, int width, int height, GuiGraphics matrices, int mouseX, int mouseY, float delta);
|
||||
|
||||
public int height() {
|
||||
return 22;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
||||
|
||||
import com.hypherionmc.craterlib.client.gui.config.CraterConfigScreen;
|
||||
import com.hypherionmc.craterlib.core.abstraction.text.AbstractComponent;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
@@ -23,12 +23,12 @@ public class SubConfigWidget<T> extends AbstractConfigWidget<T, Button> {
|
||||
this.subConfig = subConfig;
|
||||
this.screen = screen;
|
||||
|
||||
this.widget = addChild(new Button(0, 0, 200, buttonHeight, AbstractComponent.translatable("t.clc.opensubconfig"), this::openSubConfig));
|
||||
this.widget = addChild(Button.builder(Component.translatable("t.clc.opensubconfig"), this::openSubConfig).size(200, buttonHeight).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
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 = AbstractComponent.literal(subConfig.getClass().getSimpleName().toLowerCase());
|
||||
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());
|
||||
this.hideReset();
|
||||
super.render(minecraft, font, x, y, width, height, matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
|
@@ -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 @@ public class TextConfigOption<T> extends AbstractConfigWidget<T, WrappedEditBox>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Minecraft minecraft, Font font, int x, int y, int width, int height, PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
public void render(Minecraft minecraft, Font font, int x, int y, int width, int height, GuiGraphics matrices, int mouseX, int mouseY, float delta) {
|
||||
widget.setTextColor(hasErrors ? 16733525 : 14737632);
|
||||
super.render(minecraft, font, x, y, width, height, matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.hypherionmc.craterlib.client.gui.config.widgets;
|
||||
|
||||
import com.hypherionmc.craterlib.core.abstraction.text.AbstractComponent;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
@@ -19,7 +18,7 @@ public class ToggleButton<T> extends AbstractConfigWidget<T, Button> {
|
||||
public ToggleButton(List<T> options, Function<T, Component> toComponent) {
|
||||
this.options = options;
|
||||
this.toComponent = toComponent;
|
||||
this.widget = addChild(new Button(0, 0, buttonWidth, buttonHeight, AbstractComponent.empty(), this::switchNext));
|
||||
this.widget = addChild(Button.builder(Component.empty(), this::switchNext).size(buttonWidth, buttonHeight).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -21,7 +21,7 @@ public class WrappedEditBox extends EditBox {
|
||||
for (GuiEventListener child : Minecraft.getInstance().screen.children()) {
|
||||
if (child instanceof TextConfigOption<?> option) {
|
||||
WrappedEditBox box = option.widget;
|
||||
box.setFocused(box == this);
|
||||
super.setFocused(box == this);
|
||||
}
|
||||
}
|
||||
super.setFocused(bl);
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.hypherionmc.craterlib.client.gui.widgets;
|
||||
|
||||
import com.hypherionmc.craterlib.core.abstraction.text.AbstractComponent;
|
||||
import net.minecraft.client.gui.components.AbstractSliderButton;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
@@ -36,9 +35,9 @@ public class TimeSliderWidget extends AbstractSliderButton {
|
||||
if (this.value * this.maxValue >= 1200) {
|
||||
String appendString = (minutes == 1) ? "Minute" : "Minutes";
|
||||
String doSeconds = ((seconds - (minutes * 60)) > 0) ? ", " + (seconds - (minutes * 60)) + " Seconds" : "";
|
||||
return AbstractComponent.literal(minutes + " " + appendString + doSeconds);
|
||||
return Component.literal(minutes + " " + appendString + doSeconds);
|
||||
} else {
|
||||
return AbstractComponent.literal(seconds + " Seconds");
|
||||
return Component.literal(seconds + " Seconds");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@ import net.minecraft.network.chat.MutableComponent;
|
||||
public class AbstractCommand {
|
||||
|
||||
public static void replySuccess(CommandContext<CommandSourceStack> stack, MutableComponent message) {
|
||||
stack.getSource().sendSuccess(message, false);
|
||||
stack.getSource().sendSuccess(() -> message, false);
|
||||
}
|
||||
|
||||
public static void replyFailure(CommandContext<CommandSourceStack> stack, MutableComponent message) {
|
||||
|
@@ -9,6 +9,7 @@ import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class AbstractFakePlayer extends CommandSourceStack {
|
||||
|
||||
@@ -24,13 +25,13 @@ public class AbstractFakePlayer extends CommandSourceStack {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSuccess(Component component, boolean bl) {
|
||||
this.onSuccess(component, bl);
|
||||
public void sendSuccess(Supplier<Component> component, boolean bl) {
|
||||
this.onSuccess(component.get(), bl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendFailure(Component component) {
|
||||
sendSuccess(component, false);
|
||||
sendSuccess(() -> component, false);
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
|
@@ -1,14 +1,16 @@
|
||||
package com.hypherionmc.craterlib.core.abstraction.server;
|
||||
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class AbstractServer {
|
||||
|
||||
public static void broadcastMessage(MinecraftServer server, MutableComponent message) {
|
||||
server.getPlayerList().broadcastMessage(message, ChatType.CHAT, Util.NIL_UUID);
|
||||
server.getPlayerList().broadcastSystemMessage(message, false);
|
||||
}
|
||||
|
||||
public static void executeCommand(MinecraftServer server, CommandSourceStack stack, String command) {
|
||||
server.getCommands().performPrefixedCommand(stack, command);
|
||||
}
|
||||
}
|
||||
|
@@ -1,29 +1,23 @@
|
||||
package com.hypherionmc.craterlib.core.abstraction.text;
|
||||
|
||||
import net.minecraft.network.chat.*;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
|
||||
public class AbstractComponent {
|
||||
|
||||
public static MutableComponent literal(String component) {
|
||||
return new TextComponent(component);
|
||||
return Component.literal(component);
|
||||
}
|
||||
|
||||
public static MutableComponent translatable(String component) {
|
||||
return new TranslatableComponent(component);
|
||||
}
|
||||
|
||||
public static MutableComponent translatable(String component, Object... objects) {
|
||||
return new TranslatableComponent(component, objects);
|
||||
return Component.translatable(component);
|
||||
}
|
||||
|
||||
public static Component safeCopy(Component inComponent) {
|
||||
String value = inComponent.getString();
|
||||
Style style = inComponent.getStyle();
|
||||
return new TextComponent(value).withStyle(style);
|
||||
}
|
||||
|
||||
public static Component empty() {
|
||||
return new TextComponent("");
|
||||
return Component.literal(value).withStyle(style);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ import java.util.function.Supplier;
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public interface CraterNetworkHandler {
|
||||
|
||||
<T extends CraterPacket<T>> void registerPacket(Class<? extends T> clazz, Supplier<T> supplier, PacketDirection packetDirection);
|
||||
|
@@ -6,6 +6,7 @@ import net.minecraft.world.entity.player.Player;
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public interface CraterPacket<T extends CraterPacket<T>> {
|
||||
|
||||
void write(final FriendlyByteBuf buf);
|
||||
|
@@ -3,6 +3,7 @@ package com.hypherionmc.craterlib.core.network;
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public enum PacketDirection {
|
||||
TO_SERVER,
|
||||
TO_CLIENT
|
||||
|
@@ -0,0 +1,44 @@
|
||||
package com.hypherionmc.craterlib.core.networking;
|
||||
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
public class CraterPacketNetwork {
|
||||
|
||||
private final PacketRegistry packetRegistry;
|
||||
public static CraterPacketNetwork INSTANCE;
|
||||
private static DeferredPacketRegistrar delayedHandler;
|
||||
|
||||
public CraterPacketNetwork(PacketRegistry registry) {
|
||||
INSTANCE = this;
|
||||
this.packetRegistry = registry;
|
||||
getDelayedHandler().registerQueuedPackets(registry);
|
||||
}
|
||||
|
||||
private static DeferredPacketRegistrar getDelayedHandler() {
|
||||
if (delayedHandler == null) {
|
||||
delayedHandler = new DeferredPacketRegistrar();
|
||||
}
|
||||
return delayedHandler;
|
||||
}
|
||||
|
||||
public static <T> PacketRegistrar registerPacket(ResourceLocation id, Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
||||
if (INSTANCE != null) {
|
||||
return INSTANCE.packetRegistry.registerPacket(id, messageType, encoder, decoder, handler);
|
||||
} else {
|
||||
return getDelayedHandler().registerPacket(id, messageType, encoder, decoder, handler);
|
||||
}
|
||||
}
|
||||
|
||||
public PacketRegistry getPacketRegistry() {
|
||||
return packetRegistry;
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package com.hypherionmc.craterlib.core.networking;
|
||||
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
public class DeferredPacketRegistrar implements PacketRegistrar {
|
||||
|
||||
private static final Map<Class<?>, PacketHolder<?>> QUEUED_PACKET_MAP = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public PacketSide side() {
|
||||
return PacketSide.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> PacketRegistrar registerPacket(ResourceLocation packetIdentifier, Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
||||
PacketHolder<T> container = new PacketHolder<>(packetIdentifier, messageType, encoder, decoder, handler);
|
||||
QUEUED_PACKET_MAP.put(messageType, container);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public void registerQueuedPackets(PacketRegistry packetRegistration) {
|
||||
if (!QUEUED_PACKET_MAP.isEmpty()) {
|
||||
packetRegistration.PACKET_MAP.putAll(QUEUED_PACKET_MAP);
|
||||
QUEUED_PACKET_MAP.forEach((aClass, container) -> packetRegistration.registerPacket(container));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package com.hypherionmc.craterlib.core.networking;
|
||||
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
public interface PacketRegistrar {
|
||||
|
||||
PacketSide side();
|
||||
|
||||
<T> PacketRegistrar registerPacket(ResourceLocation id, Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler);
|
||||
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package com.hypherionmc.craterlib.core.networking;
|
||||
|
||||
import com.hypherionmc.craterlib.api.networking.CraterNetworkHandler;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
public abstract class PacketRegistry implements CraterNetworkHandler, PacketRegistrar {
|
||||
|
||||
final Map<Class<?>, PacketHolder<?>> PACKET_MAP = new HashMap<>();
|
||||
|
||||
protected final PacketSide side;
|
||||
|
||||
public PacketRegistry(PacketSide side) {
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
public <T> PacketRegistrar registerPacket(ResourceLocation id, Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, Consumer<PacketContext<T>> handler) {
|
||||
PacketHolder<T> holder = new PacketHolder<>(id, messageType, encoder, decoder, handler);
|
||||
PACKET_MAP.put(messageType, holder);
|
||||
registerPacket(holder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PacketSide side() {
|
||||
return side;
|
||||
}
|
||||
|
||||
protected abstract <T> void registerPacket(PacketHolder<T> packetHolder);
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package com.hypherionmc.craterlib.core.networking.data;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
public record PacketContext<T>(@Nullable Player sender, T message, PacketSide side) {
|
||||
|
||||
public PacketContext(T message, PacketSide side) {
|
||||
this(null, message, side);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.hypherionmc.craterlib.core.networking.data;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
public record PacketHolder<T>(ResourceLocation packetId,
|
||||
Class<T> messageType,
|
||||
BiConsumer<T, FriendlyByteBuf> encoder,
|
||||
Function<FriendlyByteBuf, T> decoder,
|
||||
Consumer<PacketContext<T>> handler) {
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package com.hypherionmc.craterlib.core.networking.data;
|
||||
|
||||
public enum PacketSide {
|
||||
CLIENT,
|
||||
SERVER;
|
||||
|
||||
public PacketSide flipped() {
|
||||
if (CLIENT.equals(this))
|
||||
return SERVER;
|
||||
|
||||
return CLIENT;
|
||||
}
|
||||
}
|
@@ -3,14 +3,10 @@ package com.hypherionmc.craterlib.mixin.events;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.hypherionmc.craterlib.api.event.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.CallbackInfoReturnable;
|
||||
@@ -18,38 +14,24 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@Mixin(Commands.class)
|
||||
public class CommandMixin {
|
||||
|
||||
@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
|
||||
@Inject(method = "performCommand",
|
||||
at = @At(value = "INVOKE",
|
||||
target = "Lcom/mojang/brigadier/CommandDispatcher;execute(Lcom/mojang/brigadier/ParseResults;)I",
|
||||
shift = At.Shift.BEFORE
|
||||
), cancellable = true
|
||||
)
|
||||
private void injectCommandEvent(CommandSourceStack stack, String command, CallbackInfoReturnable<Integer> cir) {
|
||||
StringReader stringreader = new StringReader(command);
|
||||
if (stringreader.canRead() && stringreader.peek() == '/') {
|
||||
stringreader.skip();
|
||||
private void injectCommandEvent(ParseResults<CommandSourceStack> stackParseResults, String command, CallbackInfoReturnable<Integer> cir) {
|
||||
CraterCommandEvent commandEvent = new CraterCommandEvent(stackParseResults, command);
|
||||
CraterEventBus.INSTANCE.postEvent(commandEvent);
|
||||
if (commandEvent.wasCancelled()) {
|
||||
cir.setReturnValue(1);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
ParseResults<CommandSourceStack> parse = dispatcher.parse(stringreader, stack);
|
||||
|
||||
CraterCommandEvent commandEvent = new CraterCommandEvent(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) {}
|
||||
if (commandEvent.getException() != null) {
|
||||
Throwables.throwIfUnchecked(commandEvent.getException());
|
||||
cir.setReturnValue(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ import com.hypherionmc.craterlib.api.event.server.PlayerPreLoginEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
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.players.PlayerList;
|
||||
@@ -17,15 +16,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
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 = "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) {
|
||||
@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) {
|
||||
String thread = Thread.currentThread().getStackTrace()[3].getClassName();
|
||||
MessageBroadcastEvent event = new MessageBroadcastEvent(component, uUID, chatType, thread);
|
||||
MessageBroadcastEvent event = new MessageBroadcastEvent(component, function, bl, thread);
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,7 @@ public class PlayerMixin {
|
||||
|
||||
@Inject(method = "die", at = @At("HEAD"), cancellable = true)
|
||||
private void injectPlayerDeathEvent(DamageSource damageSource, CallbackInfo ci) {
|
||||
CraterLivingDeathEvent event = new CraterLivingDeathEvent(((Player)(Object) this), damageSource);
|
||||
CraterLivingDeathEvent event = new CraterLivingDeathEvent(((Player) (Object) this), damageSource);
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
if (event.wasCancelled())
|
||||
ci.cancel();
|
||||
|
@@ -3,16 +3,18 @@ package com.hypherionmc.craterlib.mixin.events;
|
||||
import com.hypherionmc.craterlib.api.event.server.CraterServerChatEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.FilteredText;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.server.network.TextFilter;
|
||||
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 java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Mixin(value = ServerGamePacketListenerImpl.class, priority = Integer.MIN_VALUE)
|
||||
public class ServerGamePacketListenerImplMixin {
|
||||
|
||||
@@ -20,16 +22,12 @@ public class ServerGamePacketListenerImplMixin {
|
||||
public ServerPlayer player;
|
||||
|
||||
@Inject(
|
||||
method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/TextFilter$FilteredText;getFiltered()Ljava/lang/String;"),
|
||||
method = "lambda$handleChat$8",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
private void injectChatEvent(TextFilter.FilteredText arg, CallbackInfo ci) {
|
||||
Component message = new TextComponent(arg.getRaw());
|
||||
if (message.getString().startsWith("/"))
|
||||
return;
|
||||
|
||||
CraterServerChatEvent event = new CraterServerChatEvent(this.player, arg.getFiltered(), message);
|
||||
private void injectChatEvent(PlayerChatMessage arg, CompletableFuture completableFuture, CompletableFuture completableFuture2, Void void_, CallbackInfo ci) {
|
||||
CraterServerChatEvent event = new CraterServerChatEvent(this.player, arg.decoratedContent().getString(), arg.decoratedContent());
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
if (event.wasCancelled())
|
||||
ci.cancel();
|
||||
|
@@ -4,18 +4,19 @@ import com.hypherionmc.craterlib.api.event.client.ScreenEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
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.jetbrains.annotations.Nullable;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public class MinecraftMixin {
|
||||
|
||||
@Shadow @Nullable public Screen screen;
|
||||
@Shadow
|
||||
@Nullable
|
||||
public Screen screen;
|
||||
|
||||
@Inject(method = "setScreen", at = @At(value = "TAIL"))
|
||||
private void injectScreenOpeningEvent(Screen screen, CallbackInfo ci) {
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.hypherionmc.craterlib.util;
|
||||
|
||||
import com.hypherionmc.craterlib.core.abstraction.text.AbstractComponent;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
@@ -11,19 +10,19 @@ import net.minecraft.network.chat.Component;
|
||||
public class LangUtils {
|
||||
|
||||
public static Component getTooltipTitle(String key) {
|
||||
return AbstractComponent.literal(ChatFormatting.YELLOW + AbstractComponent.translatable(key).getString());
|
||||
return Component.literal(ChatFormatting.YELLOW + Component.translatable(key).getString());
|
||||
}
|
||||
|
||||
public static String resolveTranslation(String key) {
|
||||
return AbstractComponent.translatable(key).getString();
|
||||
return Component.translatable(key).getString();
|
||||
}
|
||||
|
||||
public static Component getTranslation(String key) {
|
||||
return AbstractComponent.translatable(key);
|
||||
return Component.translatable(key);
|
||||
}
|
||||
|
||||
public static Component makeComponent(String text) {
|
||||
return AbstractComponent.translatable(text);
|
||||
return Component.translatable(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,10 +1,9 @@
|
||||
package com.hypherionmc.craterlib.util;
|
||||
|
||||
import com.hypherionmc.craterlib.core.abstraction.text.AbstractComponent;
|
||||
import com.mojang.math.Vector4f;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@@ -27,7 +26,7 @@ public class RenderUtils {
|
||||
amount = amount / 81;
|
||||
capacity = capacity / 81;
|
||||
String text = String.valueOf((int) (((float) amount / capacity) * 100));
|
||||
return amount > 0 ? AbstractComponent.literal(ChatFormatting.AQUA + text + "%") : AbstractComponent.literal(text + "%");
|
||||
return amount > 0 ? Component.literal(ChatFormatting.AQUA + text + "%") : Component.literal(text + "%");
|
||||
}
|
||||
|
||||
public static Component getTimeDisplayString(double value) {
|
||||
@@ -36,12 +35,21 @@ public class RenderUtils {
|
||||
if (seconds >= 60) {
|
||||
String appendString = (minutes == 1) ? "Minute" : "Minutes";
|
||||
String doSeconds = ((seconds - (minutes * 60)) > 0) ? ", " + (seconds - (minutes * 60)) + " Seconds" : "";
|
||||
return AbstractComponent.literal(minutes + " " + appendString + doSeconds);
|
||||
return Component.literal(minutes + " " + appendString + doSeconds);
|
||||
} else {
|
||||
return AbstractComponent.literal(seconds + " Seconds");
|
||||
return Component.literal(seconds + " Seconds");
|
||||
}
|
||||
}
|
||||
|
||||
public static int renderColorFromDye(DyeColor color) {
|
||||
return color.getMapColor().col | 0xFF000000;
|
||||
}
|
||||
|
||||
public static int alphaColorFromDye(DyeColor color, float alpha) {
|
||||
float[] colors = color.getTextureDiffuseColors();
|
||||
return new Color(colors[0], colors[1], colors[2], alpha).getRGB();
|
||||
}
|
||||
|
||||
public static class ARGB32 {
|
||||
public static int alpha(int pPackedColor) {
|
||||
return pPackedColor >>> 24;
|
||||
@@ -59,13 +67,4 @@ public class RenderUtils {
|
||||
return pPackedColor & 255;
|
||||
}
|
||||
}
|
||||
|
||||
public static int renderColorFromDye(DyeColor color) {
|
||||
return color.getMaterialColor().col | 0xFF000000;
|
||||
}
|
||||
|
||||
public static int alphaColorFromDye(DyeColor color, float alpha) {
|
||||
float[] colors = color.getTextureDiffuseColors();
|
||||
return new Color(colors[0], colors[1], colors[2], alpha).getRGB();
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"description": "${mod_name}",
|
||||
"pack_format": 8
|
||||
"pack_format": 18
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ dependencies {
|
||||
shade "me.hypherionmc.moon-config:core:${moon_config}"
|
||||
shade "me.hypherionmc.moon-config:toml:${moon_config}"
|
||||
shade "com.hypherionmc:rpcsdk:1.0"
|
||||
shade ("me.hypherionmc.sdlink:mcdiscordformatter-1.18.1:2.0.0")
|
||||
shade ("me.hypherionmc.sdlink:mcdiscordformatter-1.19.1:2.0.0")
|
||||
|
||||
modImplementation("com.terraformersmc:modmenu:${mod_menu_version}") {
|
||||
exclude(group: "net.fabricmc.fabric-api")
|
||||
@@ -116,8 +116,8 @@ publisher {
|
||||
versionType = "release"
|
||||
changelog = "https://raw.githubusercontent.com/hypherionmc/changelogs/main/craterlib/changelog-fabric.md"
|
||||
version = "${minecraft_version}-${project.version}"
|
||||
displayName = "[FABRIC/QUILT 1.18.2] CraterLib - ${project.version}"
|
||||
gameVersions = ["1.18.2"]
|
||||
displayName = "[FABRIC/QUILT 1.20.1/2] CraterLib - ${project.version}"
|
||||
gameVersions = ["1.20", "1.20.1"]
|
||||
loaders = ["fabric", "quilt"]
|
||||
artifact = remapJar
|
||||
|
||||
|
@@ -4,16 +4,20 @@ import com.hypherionmc.craterlib.api.event.server.CraterRegisterCommandEvent;
|
||||
import com.hypherionmc.craterlib.api.event.server.CraterServerLifecycleEvent;
|
||||
import com.hypherionmc.craterlib.common.FabricCommonPlatform;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.core.networking.CraterPacketNetwork;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import com.hypherionmc.craterlib.network.CraterFabricNetworkHandler;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
|
||||
public class CraterLibInitializer implements ModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
new CraterPacketNetwork(new CraterFabricNetworkHandler(PacketSide.SERVER));
|
||||
CommandRegistrationCallback.EVENT.register(
|
||||
(dispatcher, registryAccess) -> CraterEventBus.INSTANCE.postEvent(new CraterRegisterCommandEvent(dispatcher)));
|
||||
(dispatcher, registryAccess, environment) -> CraterEventBus.INSTANCE.postEvent(new CraterRegisterCommandEvent(dispatcher)));
|
||||
|
||||
|
||||
ServerLifecycleEvents.SERVER_STARTING.register(server -> {
|
||||
|
@@ -2,6 +2,9 @@ package com.hypherionmc.craterlib.client;
|
||||
|
||||
import com.hypherionmc.craterlib.api.event.client.CraterClientTickEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.core.networking.CraterPacketNetwork;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import com.hypherionmc.craterlib.network.CraterFabricNetworkHandler;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
|
||||
@@ -9,6 +12,7 @@ public class CraterLibClientInitializer implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
new CraterPacketNetwork(new CraterFabricNetworkHandler(PacketSide.CLIENT));
|
||||
ClientTickEvents.START_CLIENT_TICK.register((listener) -> {
|
||||
CraterClientTickEvent event = new CraterClientTickEvent(listener.level);
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
|
@@ -0,0 +1,81 @@
|
||||
package com.hypherionmc.craterlib.network;
|
||||
|
||||
import com.hypherionmc.craterlib.CraterConstants;
|
||||
import com.hypherionmc.craterlib.core.networking.PacketRegistry;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
public class CraterFabricNetworkHandler extends PacketRegistry {
|
||||
|
||||
private final Map<Class<?>, Message<?>> CHANNELS = new HashMap();
|
||||
|
||||
public CraterFabricNetworkHandler(PacketSide side) {
|
||||
super(side);
|
||||
}
|
||||
|
||||
protected <T> void registerPacket(PacketHolder<T> holder) {
|
||||
if (CHANNELS.get(holder.messageType()) == null) {
|
||||
CHANNELS.put(holder.messageType(), new Message<>(holder.packetId(), holder.encoder()));
|
||||
|
||||
if (PacketSide.CLIENT.equals(this.side)) {
|
||||
ClientPlayNetworking.registerGlobalReceiver(holder.packetId(), ((client, listener, buf, responseSender) -> {
|
||||
buf.readByte();
|
||||
T message = holder.decoder().apply(buf);
|
||||
client.execute(() -> holder.handler().accept(new PacketContext<>(message, PacketSide.CLIENT)));
|
||||
}));
|
||||
} else {
|
||||
|
||||
ServerPlayNetworking.registerGlobalReceiver(holder.packetId(), ((server, player, listener, buf, responseSender) -> {
|
||||
buf.readByte();
|
||||
T message = holder.decoder().apply(buf);
|
||||
server.execute(() -> holder.handler().accept(new PacketContext<>(player, message, PacketSide.SERVER)));
|
||||
}));
|
||||
}
|
||||
|
||||
} else {
|
||||
CraterConstants.LOG.error("Trying to register duplicate packet for type {}", holder.messageType());
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void sendToServer(T packet) {
|
||||
this.sendToServer(packet, false);
|
||||
}
|
||||
|
||||
public <T> void sendToServer(T packet, boolean ignoreCheck) {
|
||||
Message<T> message = (Message<T>) CHANNELS.get(packet.getClass());
|
||||
|
||||
if (ClientPlayNetworking.canSend(message.id()) || ignoreCheck) {
|
||||
FriendlyByteBuf buf = PacketByteBufs.create();
|
||||
buf.writeByte(0);
|
||||
message.encoder().accept(packet, buf);
|
||||
ClientPlayNetworking.send(message.id(), buf);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void sendToClient(T packet, ServerPlayer player) {
|
||||
Message<T> message = (Message<T>) CHANNELS.get(packet.getClass());
|
||||
if (ServerPlayNetworking.canSend(player, message.id()))
|
||||
{
|
||||
FriendlyByteBuf buf = PacketByteBufs.create();
|
||||
buf.writeByte(0);
|
||||
message.encoder().accept(packet, buf);
|
||||
ServerPlayNetworking.send(player, message.id(), buf);
|
||||
}
|
||||
}
|
||||
|
||||
public record Message<T>(ResourceLocation id, BiConsumer<T, FriendlyByteBuf> encoder) { }
|
||||
}
|
@@ -23,6 +23,7 @@ import java.util.function.Supplier;
|
||||
* @author HypherionSA
|
||||
* @date 24/09/2022
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class FabricNetworkHandler implements CraterNetworkHandler {
|
||||
|
||||
private static final Map<String, FabricNetworkHandler> NETWORK_HANDLERS = Maps.newConcurrentMap();
|
||||
|
@@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public interface FabricNetworkHelper {
|
||||
|
||||
/* FABRIC ONLY */
|
||||
|
@@ -11,6 +11,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public class FabricClientNetworkHelper extends FabricServerNetworkHelper {
|
||||
|
||||
@Override
|
||||
|
@@ -13,6 +13,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public class FabricServerNetworkHelper implements FabricNetworkHelper {
|
||||
@Override
|
||||
public void registerClientReceiver(@NotNull ResourceLocation channelName, @NotNull Function<FriendlyByteBuf, @NotNull CraterPacket<?>> factory) {
|
||||
|
@@ -33,7 +33,7 @@
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.21",
|
||||
"fabric-api": "*",
|
||||
"minecraft": "1.18.2",
|
||||
"minecraft": ">=1.20",
|
||||
"java": ">=17"
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ dependencies {
|
||||
shade "me.hypherionmc.moon-config:core:${moon_config}"
|
||||
shade "me.hypherionmc.moon-config:toml:${moon_config}"
|
||||
shade "com.hypherionmc:rpcsdk:1.0"
|
||||
shade ("me.hypherionmc.sdlink:mcdiscordformatter-1.18.1:2.0.0")
|
||||
shade ("me.hypherionmc.sdlink:mcdiscordformatter-1.19.1:2.0.0")
|
||||
|
||||
// Do not edit or remove
|
||||
implementation project(":Common")
|
||||
@@ -111,8 +111,8 @@ publisher {
|
||||
versionType = "release"
|
||||
changelog = "https://raw.githubusercontent.com/hypherionmc/changelogs/main/craterlib/changelog-forge.md"
|
||||
version = "${minecraft_version}-${project.version}"
|
||||
displayName = "[FORGE 1.18.2] CraterLib - ${project.version}"
|
||||
gameVersions = ["1.18.2"]
|
||||
displayName = "[FORGE 1.20.1/2] CraterLib - ${project.version}"
|
||||
gameVersions = ["1.20", "1.20.1"]
|
||||
loaders = ["forge"]
|
||||
artifact = remapJar
|
||||
}
|
@@ -3,6 +3,9 @@ package com.hypherionmc.craterlib;
|
||||
import com.hypherionmc.craterlib.api.event.client.LateInitEvent;
|
||||
import com.hypherionmc.craterlib.common.ForgeServerEvents;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.core.networking.CraterPacketNetwork;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import com.hypherionmc.craterlib.network.CraterForgeNetworkHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@@ -10,6 +13,7 @@ import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
|
||||
@Mod(CraterConstants.MOD_ID)
|
||||
public class CraterLib {
|
||||
@@ -20,6 +24,7 @@ public class CraterLib {
|
||||
}
|
||||
|
||||
public void commonSetup(FMLCommonSetupEvent evt) {
|
||||
new CraterPacketNetwork(new CraterForgeNetworkHandler(FMLLoader.getDist().isClient() ? PacketSide.CLIENT : PacketSide.SERVER));
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
LateInitEvent event = new LateInitEvent(Minecraft.getInstance(), Minecraft.getInstance().options);
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
|
@@ -13,7 +13,7 @@ import net.minecraftforge.fml.common.Mod;
|
||||
public class ForgeClientEvents {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void clientTick(TickEvent.WorldTickEvent event) {
|
||||
public static void clientTick(TickEvent.LevelTickEvent event) {
|
||||
CraterClientTickEvent craterClientTickEvent = new CraterClientTickEvent(Minecraft.getInstance().level);
|
||||
CraterEventBus.INSTANCE.postEvent(craterClientTickEvent);
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ import com.hypherionmc.craterlib.core.config.ModuleConfig;
|
||||
import com.hypherionmc.craterlib.core.config.annotations.NoConfigScreen;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraftforge.client.ConfigGuiHandler;
|
||||
import net.minecraftforge.client.ConfigScreenHandler;
|
||||
import net.minecraftforge.forgespi.language.IModInfo;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -19,7 +19,7 @@ import java.util.function.BiFunction;
|
||||
/**
|
||||
* @author HypherionSA
|
||||
*/
|
||||
@Mixin(ConfigGuiHandler.class)
|
||||
@Mixin(ConfigScreenHandler.class)
|
||||
public class ConfigScreenHandlerMixin {
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ public class ConfigScreenHandlerMixin {
|
||||
* @param selectedMod
|
||||
* @param cir
|
||||
*/
|
||||
@Inject(at = @At("RETURN"), method = "getGuiFactoryFor", cancellable = true, remap = false)
|
||||
@Inject(at = @At("RETURN"), method = "getScreenFactoryFor", cancellable = true, remap = false)
|
||||
private static void injectConfigScreen(IModInfo selectedMod, CallbackInfoReturnable<Optional<BiFunction<Minecraft, Screen, Screen>>> cir) {
|
||||
ConfigController.getMonitoredConfigs().forEach((conf, watcher) -> {
|
||||
if (!conf.getClass().isAnnotationPresent(NoConfigScreen.class)) {
|
||||
|
@@ -0,0 +1,87 @@
|
||||
package com.hypherionmc.craterlib.network;
|
||||
|
||||
import com.hypherionmc.craterlib.CraterConstants;
|
||||
import com.hypherionmc.craterlib.core.networking.PacketRegistry;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketContext;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketHolder;
|
||||
import com.hypherionmc.craterlib.core.networking.data.PacketSide;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.network.simple.SimpleChannel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static net.minecraftforge.network.NetworkDirection.PLAY_TO_CLIENT;
|
||||
|
||||
/**
|
||||
* Based on https://github.com/mysticdrew/common-networking/tree/1.20.4
|
||||
*/
|
||||
public class CraterForgeNetworkHandler extends PacketRegistry {
|
||||
private final Map<Class<?>, SimpleChannel> CHANNELS = new HashMap<>();
|
||||
|
||||
public CraterForgeNetworkHandler(PacketSide side) {
|
||||
super(side);
|
||||
}
|
||||
|
||||
protected <T> void registerPacket(PacketHolder<T> holder) {
|
||||
if (CHANNELS.get(holder.messageType()) == null) {
|
||||
SimpleChannel channel = NetworkRegistry.ChannelBuilder
|
||||
.named(holder.packetId())
|
||||
.clientAcceptedVersions((a) -> true)
|
||||
.serverAcceptedVersions((a) -> true)
|
||||
.networkProtocolVersion(() -> "1")
|
||||
.simpleChannel();
|
||||
|
||||
channel.registerMessage(
|
||||
0,
|
||||
holder.messageType(),
|
||||
holder.encoder(),
|
||||
holder.decoder(),
|
||||
buildHandler(holder.handler())
|
||||
);
|
||||
|
||||
CHANNELS.put(holder.messageType(), channel);
|
||||
} else {
|
||||
CraterConstants.LOG.error("Trying to register duplicate packet for type {}", holder.messageType());
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void sendToServer(T packet) {
|
||||
this.sendToServer(packet, false);
|
||||
}
|
||||
|
||||
public <T> void sendToServer(T packet, boolean ignoreCheck) {
|
||||
SimpleChannel channel = CHANNELS.get(packet.getClass());
|
||||
Connection connection = Minecraft.getInstance().getConnection().getConnection();
|
||||
if (channel.isRemotePresent(connection) || ignoreCheck) {
|
||||
channel.sendToServer(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void sendToClient(T packet, ServerPlayer player) {
|
||||
SimpleChannel channel = CHANNELS.get(packet.getClass());
|
||||
Connection connection = player.connection.connection;
|
||||
if (channel.isRemotePresent(connection)) {
|
||||
channel.sendTo(packet, player.connection.connection, PLAY_TO_CLIENT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private <T> BiConsumer<T, Supplier<NetworkEvent.Context>> buildHandler(Consumer<PacketContext<T>> handler) {
|
||||
return (message, ctx) -> {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
PacketSide side = ctx.get().getDirection().getReceptionSide().isServer() ? PacketSide.SERVER : PacketSide.CLIENT;
|
||||
ServerPlayer player = ctx.get().getSender();
|
||||
handler.accept(new PacketContext<>(player, message, side));
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
};
|
||||
}
|
||||
}
|
@@ -26,6 +26,7 @@ import java.util.function.Supplier;
|
||||
* @author HypherionSA
|
||||
* Partly inspired by and based on <a href="https://github.com/Fuzss/puzzleslib/blob/1.19/Forge/src/main/java/fuzs/puzzleslib/network/ForgeNetworkHandler.java">...</a>
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class ForgeNetworkHandler implements CraterNetworkHandler {
|
||||
|
||||
private static final Map<String, ForgeNetworkHandler> NETWORK_HANDLERS = Maps.newConcurrentMap();
|
||||
|
@@ -1,5 +1,5 @@
|
||||
modLoader = "javafml"
|
||||
loaderVersion = "[40,)"
|
||||
loaderVersion = "[46,)"
|
||||
license = "MIT"
|
||||
issueTrackerURL = "https://github.com/firstdarkdev/craterLib/issues"
|
||||
|
||||
@@ -19,13 +19,13 @@ displayTest = "MATCH_VERSION"
|
||||
[[dependencies.${mod_id}]]
|
||||
modId = "forge"
|
||||
mandatory = true
|
||||
versionRange = "[40,)"
|
||||
versionRange = "[46,)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.${mod_id}]]
|
||||
modId = "minecraft"
|
||||
mandatory = true
|
||||
versionRange = "[1.18.2,1.19)"
|
||||
versionRange = "[1.20,1.20.2)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
|
@@ -7,7 +7,7 @@ plugins {
|
||||
}
|
||||
|
||||
ext {
|
||||
release=project.properties['release'] ?: false
|
||||
release = project.properties['release'] ?: false
|
||||
}
|
||||
|
||||
var base_version = "${version_major}.${version_minor}"
|
||||
@@ -68,7 +68,7 @@ subprojects {
|
||||
'Implementation-Version' : project.jar.archiveVersion,
|
||||
'Implementation-Vendor' : mod_author,
|
||||
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
|
||||
'Timestamp' : System.currentTimeMillis(),
|
||||
'Timestamp' : System.currentTimeMillis(),
|
||||
'Built-On-Java' : "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})",
|
||||
'Build-On-Minecraft' : minecraft_version
|
||||
])
|
||||
|
@@ -10,17 +10,17 @@ mod_id=craterlib
|
||||
mod_name=CraterLib
|
||||
|
||||
# Shared
|
||||
minecraft_version=1.18.2
|
||||
minecraft_version=1.20
|
||||
|
||||
# Fabric
|
||||
fabric_api=0.76.0+1.18.2
|
||||
fabric_loader=0.14.21
|
||||
fabric_api=0.83.0+1.20
|
||||
|
||||
# Forge
|
||||
forge_version=40.2.0
|
||||
forge_version=46.0.1
|
||||
|
||||
# Dependencies
|
||||
mod_menu_version=3.2.5
|
||||
mod_menu_version=7.0.0-beta.2
|
||||
moon_config=1.0.9
|
||||
|
||||
# Publishing
|
||||
|
Reference in New Issue
Block a user