feat: update to 1.20.5-rc2
This commit is contained in:
parent
f88996e8f3
commit
7a75c776e4
|
@ -29,11 +29,13 @@ allprojects {
|
|||
if (!rootProject.jfMod.isMod(this)) return@allprojects
|
||||
|
||||
dependencies {
|
||||
modLocalRuntime(libs.modmenu) {
|
||||
exclude("net.fabricmc") // required to work around duplicate fabric loaders
|
||||
}
|
||||
// modLocalRuntime(libs.modmenu) {
|
||||
// exclude("net.fabricmc") // required to work around duplicate fabric loaders
|
||||
// }
|
||||
modLocalRuntime("net.fabricmc.fabric-api:fabric-command-api-v2")
|
||||
modLocalRuntime("net.fabricmc.fabric-api:fabric-networking-api-v1")
|
||||
modLocalRuntime("net.fabricmc.fabric-api:fabric-resource-loader-v0")
|
||||
modLocalRuntime("net.fabricmc.fabric-api:fabric-lifecycle-events-v1")
|
||||
compileOnly(libs.bundles.commons)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# jf-scripts version is in settings.gradle.kts
|
||||
[versions]
|
||||
minecraft = "1.20.4"
|
||||
yarn = "build.3"
|
||||
fabric-loader = "0.15.7"
|
||||
fabric-api = "0.96.4+1.20.4"
|
||||
minecraft = "1.20.5-rc2"
|
||||
yarn = "build.1"
|
||||
fabric-loader = "0.15.10"
|
||||
fabric-api = "0.97.3+1.20.5"
|
||||
jf-commons = "1.7-SNAPSHOT"
|
||||
modmenu = "9.0.0"
|
||||
annotations = "24.1.0"
|
||||
|
|
|
@ -3,21 +3,24 @@ package io.gitlab.jfronny.libjf.config.impl.network.client;
|
|||
import io.gitlab.jfronny.libjf.config.impl.network.packet.ConfigurationCompletePacket;
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.packet.ConfigurationPacket;
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.RequestRouter;
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.packet.RequestPacket;
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.packet.ResponsePacket;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.*;
|
||||
|
||||
public class JfConfigNetworkClient {
|
||||
public static boolean isAvailable = false;
|
||||
public static void initialize() {
|
||||
RequestRouter.initialize();
|
||||
JfConfigNetworkCommands.initialize();
|
||||
ClientPlayNetworking.registerGlobalReceiver(RequestRouter.RESPONSE_ID, (client, handler, buf, responseSender) -> {
|
||||
RequestRouter.acceptResponse(buf, responseSender);
|
||||
ClientPlayNetworking.registerGlobalReceiver(ResponsePacket.ID, (payload, context) -> {
|
||||
RequestRouter.acceptResponse(payload, context.responseSender());
|
||||
});
|
||||
ClientPlayNetworking.registerGlobalReceiver(RequestRouter.REQUEST_ID, (client, handler, buf, responseSender) -> {
|
||||
RequestRouter.acceptRequest(buf, responseSender);
|
||||
ClientPlayNetworking.registerGlobalReceiver(RequestPacket.ID, (payload, context) -> {
|
||||
RequestRouter.acceptRequest(payload, context.responseSender());
|
||||
});
|
||||
ClientConfigurationNetworking.registerGlobalReceiver(ConfigurationPacket.PACKET_TYPE, (packet, responseSender) -> {
|
||||
isAvailable = packet.version() == RequestRouter.PROTOCOL_VERSION; // Handshake possible?
|
||||
responseSender.sendPacket(new ConfigurationCompletePacket());
|
||||
ClientConfigurationNetworking.registerGlobalReceiver(ConfigurationPacket.ID, (payload, context) -> {
|
||||
isAvailable = payload.version() == RequestRouter.PROTOCOL_VERSION; // Handshake possible?
|
||||
context.responseSender().sendPacket(new ConfigurationCompletePacket());
|
||||
});
|
||||
ClientConfigurationConnectionEvents.INIT.register((handler, client) -> {
|
||||
isAvailable = false; // Reset for new server connection
|
||||
|
|
|
@ -1,84 +1,93 @@
|
|||
package io.gitlab.jfronny.libjf.config.impl.network;
|
||||
|
||||
import io.gitlab.jfronny.libjf.LibJf;
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.packet.ConfigurationCompletePacket;
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.packet.ConfigurationPacket;
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.packet.RequestPacket;
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.packet.ResponsePacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class RequestRouter {
|
||||
public static final String MOD_ID = "libjf-config-network-v0";
|
||||
public static final Identifier RESPONSE_ID = new Identifier(MOD_ID, "response");
|
||||
public static final Identifier REQUEST_ID = new Identifier(MOD_ID, "request");
|
||||
public static int PROTOCOL_VERSION = 1;
|
||||
|
||||
private static final Map<String, RequestHandler> persistendHandlers = new HashMap<>();
|
||||
private static final Map<Long, Request> currentRequests = new HashMap<>(); //TODO implement timeout and prune old requests
|
||||
private static final Random random = new Random();
|
||||
|
||||
public static void acceptResponse(PacketByteBuf buf, PacketSender responseSender) {
|
||||
Request request = currentRequests.remove(buf.readLong());
|
||||
public static void initialize() {
|
||||
PayloadTypeRegistry.playC2S().register(RequestPacket.ID, RequestPacket.CODEC);
|
||||
PayloadTypeRegistry.playS2C().register(RequestPacket.ID, RequestPacket.CODEC);
|
||||
PayloadTypeRegistry.playC2S().register(ResponsePacket.ID, ResponsePacket.CODEC);
|
||||
PayloadTypeRegistry.playS2C().register(ResponsePacket.ID, ResponsePacket.CODEC);
|
||||
PayloadTypeRegistry.configurationS2C().register(ConfigurationPacket.ID, ConfigurationPacket.CODEC);
|
||||
PayloadTypeRegistry.configurationC2S().register(ConfigurationCompletePacket.ID, ConfigurationCompletePacket.CODEC);
|
||||
}
|
||||
|
||||
public static void acceptResponse(ResponsePacket response, PacketSender responseSender) {
|
||||
Request request = currentRequests.remove(response.request());
|
||||
if (request != null) {
|
||||
switch (buf.readInt()) {
|
||||
case 0 -> request.responseHandler.onSuccess(buf);
|
||||
switch (response.status()) {
|
||||
case 0 -> request.responseHandler.onSuccess(response.aux());
|
||||
case 1 -> request.responseHandler.onNotFound();
|
||||
case 2 -> request.responseHandler.onDeny();
|
||||
case 3 -> request.responseHandler.onFailure(buf.readString());
|
||||
case 3 -> request.responseHandler.onFailure(response.aux().readString());
|
||||
default -> request.responseHandler.onFailure("Unrecognized error received");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void acceptRequest(PacketByteBuf buf, PacketSender responseSender) {
|
||||
PacketByteBuf resp = PacketByteBufs.create();
|
||||
long id = buf.readLong();
|
||||
resp.writeLong(id);
|
||||
public static void acceptRequest(RequestPacket request, PacketSender responseSender) {
|
||||
long id = request.request();
|
||||
int mode = 3;
|
||||
PacketByteBuf aux = PacketByteBufs.create();
|
||||
try {
|
||||
if (buf.readBoolean()) {
|
||||
if (request.parent() == null) {
|
||||
// persistent
|
||||
handleRequest(resp, id, buf, persistendHandlers.get(buf.readString()));
|
||||
mode = handleRequest(aux, id, request.aux(), persistendHandlers.get(request.name()));
|
||||
} else {
|
||||
// followup
|
||||
Request parent = currentRequests.get(buf.readLong());
|
||||
Request parent = currentRequests.get(request.parent());
|
||||
if (parent == null) {
|
||||
resp.writeInt(1);
|
||||
mode = 1;
|
||||
} else {
|
||||
String key = buf.readString();
|
||||
String key = request.name();
|
||||
RequestHandler handler = parent.temporaryHandlers.get(key);
|
||||
if (handler == null) handler = persistendHandlers.get(key);
|
||||
handleRequest(resp, id, buf, handler);
|
||||
mode = handleRequest(aux, id, request.aux(), handler);
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
LibJf.LOGGER.error("Cannot complete request", t);
|
||||
resp.writeInt(3);
|
||||
resp.writeString(t.getMessage() == null ? "null" : t.getMessage());
|
||||
aux.clear();
|
||||
aux.writeString(t.getMessage() == null ? "null" : t.getMessage());
|
||||
} finally {
|
||||
responseSender.sendPacket(RESPONSE_ID, resp);
|
||||
responseSender.sendPacket(new ResponsePacket(id, mode, aux));
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleRequest(PacketByteBuf resp, long id, PacketByteBuf buf, RequestHandler handler) throws Throwable {
|
||||
private static int handleRequest(ByteBuf aux, long id, PacketByteBuf buf, RequestHandler handler) throws Throwable {
|
||||
if (handler == null) {
|
||||
resp.writeInt(1);
|
||||
return 1;
|
||||
} else {
|
||||
PacketByteBuf response = handler.handle(
|
||||
buf,
|
||||
(responseSender, name, body, responseHandler, temporaryHandlers) ->
|
||||
RequestRouter.sendRequest(responseSender, id, name, body, responseHandler, temporaryHandlers)
|
||||
);
|
||||
resp.writeInt(0);
|
||||
if (response != null) resp.writeBytes(response.copy());
|
||||
if (response != null) aux.writeBytes(response.copy());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void deny(PacketByteBuf buf, PacketSender responseSender) {
|
||||
PacketByteBuf resp = PacketByteBufs.create();
|
||||
resp.writeLong(buf.readLong());
|
||||
resp.writeInt(2);
|
||||
responseSender.sendPacket(RESPONSE_ID, resp);
|
||||
public static void deny(long id, PacketSender responseSender) {
|
||||
responseSender.sendPacket(new ResponsePacket(id, 2, PacketByteBufs.empty()));
|
||||
}
|
||||
|
||||
public static void registerHandler(String name, RequestHandler handler) {
|
||||
|
@ -98,15 +107,7 @@ public class RequestRouter {
|
|||
} while (keys.contains(id));
|
||||
currentRequests.put(id, new Request(temporaryHandlers, responseHandler));
|
||||
}
|
||||
PacketByteBuf req = PacketByteBufs.create();
|
||||
req.writeLong(id);
|
||||
req.writeBoolean(parent == null);
|
||||
if (parent != null) req.writeLong(parent);
|
||||
req.writeString(name);
|
||||
if (body != null) {
|
||||
req.writeBytes(body.copy());
|
||||
}
|
||||
responseSender.sendPacket(REQUEST_ID, req);
|
||||
responseSender.sendPacket(new RequestPacket(id, parent, name, PacketByteBufs.copy(body)));
|
||||
}
|
||||
|
||||
private record Request(Map<String, RequestHandler> temporaryHandlers, ResponseHandler responseHandler) {}
|
||||
|
|
|
@ -1,25 +1,26 @@
|
|||
package io.gitlab.jfronny.libjf.config.impl.network.packet;
|
||||
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.RequestRouter;
|
||||
import net.fabricmc.fabric.api.networking.v1.FabricPacket;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketType;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.Identifier;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.RegistryByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
|
||||
public record ConfigurationCompletePacket() implements FabricPacket {
|
||||
public static final Identifier ID = new Identifier(RequestRouter.MOD_ID, "handshake_complete");
|
||||
public static final PacketType<ConfigurationCompletePacket> PACKET_TYPE = PacketType.create(ID, ConfigurationCompletePacket::new);
|
||||
public record ConfigurationCompletePacket() implements CustomPayload {
|
||||
public static final CustomPayload.Id<ConfigurationCompletePacket> ID = CustomPayload.id(RequestRouter.MOD_ID + ":handshake_complete");
|
||||
public static final PacketCodec<ByteBuf, ConfigurationCompletePacket> CODEC = new PacketCodec<>() {
|
||||
@Override
|
||||
public ConfigurationCompletePacket decode(ByteBuf buf) {
|
||||
return new ConfigurationCompletePacket();
|
||||
}
|
||||
|
||||
public ConfigurationCompletePacket(PacketByteBuf buf) {
|
||||
this();
|
||||
}
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ConfigurationCompletePacket value) {
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void write(PacketByteBuf buf) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketType<?> getType() {
|
||||
return PACKET_TYPE;
|
||||
public Id<? extends CustomPayload> getId() {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,18 @@
|
|||
package io.gitlab.jfronny.libjf.config.impl.network.packet;
|
||||
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.RequestRouter;
|
||||
import net.fabricmc.fabric.api.networking.v1.FabricPacket;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketType;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.Identifier;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.RegistryByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.network.codec.PacketCodecs;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
|
||||
public record ConfigurationPacket(int version) implements FabricPacket {
|
||||
public static final Identifier ID = new Identifier(RequestRouter.MOD_ID, "handshake");
|
||||
public static final PacketType<ConfigurationPacket> PACKET_TYPE = PacketType.create(ID, ConfigurationPacket::new);
|
||||
|
||||
public ConfigurationPacket(PacketByteBuf buf) {
|
||||
this(buf.readInt());
|
||||
}
|
||||
public record ConfigurationPacket(int version) implements CustomPayload {
|
||||
public static final CustomPayload.Id<ConfigurationPacket> ID = CustomPayload.id(RequestRouter.MOD_ID + ":handshake");
|
||||
public static final PacketCodec<ByteBuf, ConfigurationPacket> CODEC = PacketCodecs.INTEGER.xmap(ConfigurationPacket::new, ConfigurationPacket::version);
|
||||
|
||||
@Override
|
||||
public void write(PacketByteBuf buf) {
|
||||
buf.writeInt(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketType<?> getType() {
|
||||
return PACKET_TYPE;
|
||||
public Id<? extends CustomPayload> getId() {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package io.gitlab.jfronny.libjf.config.impl.network.packet;
|
||||
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.RequestRouter;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public record RequestPacket(long request, @Nullable Long parent, String name, PacketByteBuf aux) implements CustomPayload {
|
||||
public static final Id<RequestPacket> ID = CustomPayload.id(RequestRouter.MOD_ID + ":request");
|
||||
public static final PacketCodec<PacketByteBuf, RequestPacket> CODEC = PacketCodec.of(
|
||||
(value, buf) -> {
|
||||
buf.writeLong(value.request);
|
||||
buf.writeBoolean(value.parent != null);
|
||||
if (value.parent != null) buf.writeLong(value.parent);
|
||||
buf.writeString(value.name);
|
||||
buf.writeBytes(value.aux);
|
||||
},
|
||||
buf -> {
|
||||
long request = buf.readLong();
|
||||
Long parent = buf.readBoolean() ? buf.readLong() : null;
|
||||
String name = buf.readString();
|
||||
PacketByteBuf aux = PacketByteBufs.copy(buf);
|
||||
return new RequestPacket(request, parent, name, aux);
|
||||
}
|
||||
);
|
||||
|
||||
@Override
|
||||
public Id<? extends CustomPayload> getId() {
|
||||
return ID;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package io.gitlab.jfronny.libjf.config.impl.network.packet;
|
||||
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.RequestRouter;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
|
||||
public record ResponsePacket(long request, int status, PacketByteBuf aux) implements CustomPayload {
|
||||
public static final CustomPayload.Id<ResponsePacket> ID = CustomPayload.id(RequestRouter.MOD_ID + ":response");
|
||||
public static final PacketCodec<PacketByteBuf, ResponsePacket> CODEC = PacketCodec.of(
|
||||
(value, buf) -> {
|
||||
buf.writeLong(value.request());
|
||||
buf.writeInt(value.status());
|
||||
buf.writeBytes(value.aux());
|
||||
},
|
||||
buf -> {
|
||||
long request = buf.readLong();
|
||||
int status = buf.readInt();
|
||||
return new ResponsePacket(request, status, PacketByteBufs.copy(buf));
|
||||
}
|
||||
);
|
||||
|
||||
@Override
|
||||
public Id<? extends CustomPayload> getId() {
|
||||
return ID;
|
||||
}
|
||||
}
|
|
@ -5,6 +5,8 @@ import io.gitlab.jfronny.libjf.config.api.v2.type.Type;
|
|||
import io.gitlab.jfronny.libjf.config.impl.network.packet.ConfigurationCompletePacket;
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.packet.ConfigurationPacket;
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.RequestRouter;
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.packet.RequestPacket;
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.packet.ResponsePacket;
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.rci.entry.Datatype;
|
||||
import io.gitlab.jfronny.libjf.config.impl.network.rci.entry.MirrorEntryInfo;
|
||||
import net.fabricmc.fabric.api.networking.v1.*;
|
||||
|
@ -18,19 +20,20 @@ import java.util.function.Consumer;
|
|||
|
||||
public class JfConfigNetworkServer {
|
||||
public static void initialize() {
|
||||
ServerPlayNetworking.registerGlobalReceiver(RequestRouter.REQUEST_ID, (server, player, handler, buf, responseSender) -> {
|
||||
if (authenticate(player)) RequestRouter.acceptRequest(buf, responseSender);
|
||||
else RequestRouter.deny(buf, responseSender);
|
||||
RequestRouter.initialize();
|
||||
ServerPlayNetworking.registerGlobalReceiver(RequestPacket.ID, (payload, context) -> {
|
||||
if (authenticate(context.player())) RequestRouter.acceptRequest(payload, context.responseSender());
|
||||
else RequestRouter.deny(payload.request(), context.responseSender());
|
||||
});
|
||||
ServerPlayNetworking.registerGlobalReceiver(RequestRouter.RESPONSE_ID, (server, player, handler, buf, responseSender) -> {
|
||||
if (authenticate(player)) RequestRouter.acceptResponse(buf, responseSender);
|
||||
else RequestRouter.deny(buf, responseSender);
|
||||
ServerPlayNetworking.registerGlobalReceiver(ResponsePacket.ID, (payload, context) -> {
|
||||
if (authenticate(context.player())) RequestRouter.acceptResponse(payload, context.responseSender());
|
||||
else RequestRouter.deny(payload.request(), context.responseSender());
|
||||
});
|
||||
ServerConfigurationNetworking.registerGlobalReceiver(ConfigurationCompletePacket.PACKET_TYPE, (packet, networkHandler, responseSender) -> {
|
||||
networkHandler.completeTask(JfConfigNetworkConfigurationTask.KEY);
|
||||
ServerConfigurationNetworking.registerGlobalReceiver(ConfigurationCompletePacket.ID, (payload, context) -> {
|
||||
context.networkHandler().completeTask(JfConfigNetworkConfigurationTask.KEY);
|
||||
});
|
||||
ServerConfigurationConnectionEvents.CONFIGURE.register((handler, server) -> {
|
||||
if (ServerConfigurationNetworking.canSend(handler, ConfigurationPacket.PACKET_TYPE)) {
|
||||
if (ServerConfigurationNetworking.canSend(handler, ConfigurationPacket.ID)) {
|
||||
handler.addTask(new JfConfigNetworkConfigurationTask());
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package io.gitlab.jfronny.libjf.config.impl.ui.tiny;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import io.gitlab.jfronny.commons.ref.R;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.client.font.TextHandler;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
|
@ -18,6 +15,7 @@ import net.minecraft.client.util.math.Rect2i;
|
|||
import net.minecraft.screen.ScreenTexts;
|
||||
import net.minecraft.text.*;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.StringHelper;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -161,7 +159,7 @@ public class EditorScreen extends ScreenWithSaveHook {
|
|||
if (super.charTyped(chr, modifiers)) {
|
||||
return true;
|
||||
}
|
||||
if (SharedConstants.isValidChar(chr)) {
|
||||
if (StringHelper.isValidChar(chr)) {
|
||||
this.currentPageSelectionManager.insert(Character.toString(chr));
|
||||
this.invalidatePageContent();
|
||||
return true;
|
||||
|
@ -296,12 +294,6 @@ public class EditorScreen extends ScreenWithSaveHook {
|
|||
final int maxScroll = this.getMaxScroll();
|
||||
final boolean showScrollbar = maxScroll > 0;
|
||||
|
||||
if (client.world == null) {
|
||||
RenderSystem.setShaderColor(0.125f, 0.125f, 0.125f, 1.0f);
|
||||
context.drawTexture(Screen.OPTIONS_BACKGROUND_TEXTURE, 0, HEADER_SIZE, showScrollbar ? width - SCROLLBAR_SIZE : width, height - FOOTER_SIZE + (int)scrollAmount, width - SCROLLBAR_SIZE, height - HEADER_SIZE - FOOTER_SIZE, 32, 32);
|
||||
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
context.enableScissor(0, HEADER_SIZE, width - SCROLLBAR_SIZE, height - FOOTER_SIZE);
|
||||
PageContent pageContent = this.getPageContent();
|
||||
for (Line line : pageContent.lines) {
|
||||
|
|
|
@ -19,18 +19,15 @@ import java.util.function.Supplier;
|
|||
@Environment(EnvType.CLIENT)
|
||||
public class EntryListWidget extends ElementListWidget<EntryListWidget.ConfigEntry> {
|
||||
private final TextRenderer textRenderer;
|
||||
private final boolean background;
|
||||
|
||||
public EntryListWidget(MinecraftClient client, TextRenderer tr, int width, int height, int top) {
|
||||
super(client, width, height, top, 25);
|
||||
this.centerListVertically = false;
|
||||
textRenderer = tr;
|
||||
background = client.world == null;
|
||||
setRenderBackground(background);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScrollbarPositionX() {
|
||||
public int getScrollbarX() {
|
||||
return this.width -7;
|
||||
}
|
||||
|
||||
|
@ -82,12 +79,6 @@ public class EntryListWidget extends ElementListWidget<EntryListWidget.ConfigEnt
|
|||
@Override
|
||||
protected void renderDecorations(DrawContext context, int mouseX, int mouseY) {
|
||||
super.renderDecorations(context, mouseX, mouseY);
|
||||
if (background) return;
|
||||
|
||||
// Background texture at the top of the screen
|
||||
context.setShaderColor(0.25f, 0.25f, 0.25f, 1.0f);
|
||||
context.drawTexture(Screen.OPTIONS_BACKGROUND_TEXTURE, getX(), 0, 0.0f, 0.0f, width, getY(), 32, 32);
|
||||
context.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
// Gradient at the top of the screen
|
||||
context.fillGradient(RenderLayer.getGuiOverlay(), getX(), getY(), getRight(), getY() + 4, 0xff000000, 0x00000000, 0);
|
||||
|
|
|
@ -11,7 +11,6 @@ import java.util.List;
|
|||
public class PresetListWidget extends ElementListWidget<PresetListWidget.PresetEntry> {
|
||||
public PresetListWidget(MinecraftClient client, int width, int height, int top, int itemHeight) {
|
||||
super(client, width, height, top, itemHeight);
|
||||
setRenderBackground(client.world == null);
|
||||
}
|
||||
|
||||
public void addButton(ClickableWidget button) {
|
||||
|
@ -19,8 +18,8 @@ public class PresetListWidget extends ElementListWidget<PresetListWidget.PresetE
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getScrollbarPositionX() {
|
||||
return this.width -7;
|
||||
protected int getScrollbarX() {
|
||||
return this.width - 7;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,6 +5,7 @@ import io.gitlab.jfronny.libjf.config.api.v2.ui.ConfigScreenFactory;
|
|||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.option.OptionsScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.DirectionalLayoutWidget;
|
||||
import net.minecraft.client.gui.widget.GridWidget;
|
||||
import net.minecraft.text.Text;
|
||||
import org.spongepowered.asm.mixin.*;
|
||||
|
@ -25,8 +26,8 @@ public abstract class OptionsScreenMixin extends Screen {
|
|||
super(title);
|
||||
}
|
||||
|
||||
@Inject(method = "init()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/GridWidget;refreshPositions()V"), locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
void injectButton(CallbackInfo ci, GridWidget gridWidget, GridWidget.Adder adder) {
|
||||
@Inject(method = "init()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/ThreePartsLayoutWidget;addBody(Lnet/minecraft/client/gui/widget/Widget;)Lnet/minecraft/client/gui/widget/Widget;"), locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
void injectButton(CallbackInfo ci, DirectionalLayoutWidget directionalLayoutWidget, DirectionalLayoutWidget directionalLayoutWidget2, GridWidget gridWidget, GridWidget.Adder adder) {
|
||||
ConfigHolder.getInstance().getRegistered().forEach((key, config) -> {
|
||||
adder.add(
|
||||
createButton(Text.translatable(key + ".jfconfig.title"), () -> ConfigScreenFactory.getInstance()
|
||||
|
|
|
@ -11,7 +11,7 @@ public class TestEntrypoint implements ModInitializer {
|
|||
// This should prevent resource packs from doing anything if my hooks are working and
|
||||
UserResourceEvents.OPEN.register((type, id, previous, pack) -> {
|
||||
if (pack instanceof DirectoryResourcePack) {
|
||||
LibJf.LOGGER.info(pack.getName() + " opened " + type.name() + "/" + id.toString());
|
||||
LibJf.LOGGER.info(pack.getInfo().title() + " opened " + type.name() + "/" + id.toString());
|
||||
return null;
|
||||
}
|
||||
return previous;
|
||||
|
|
|
@ -2,7 +2,9 @@ package io.gitlab.jfronny.libjf.data.mixin;
|
|||
|
||||
import io.gitlab.jfronny.libjf.data.Tags;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
@ -37,8 +39,9 @@ public class EntityMixin {
|
|||
|
||||
private boolean libjf$opArmor() {
|
||||
Entity entity = (Entity) (Object) this;
|
||||
if (!(entity instanceof LivingEntity le)) return false;
|
||||
AtomicInteger armorCount = new AtomicInteger();
|
||||
for (ItemStack s : entity.getArmorItems()) {
|
||||
for (ItemStack s : le.getArmorItems()) {
|
||||
if (s.isIn(Tags.OVERPOWERED))
|
||||
armorCount.getAndIncrement();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue