Compare commits
6 Commits
828cf88518
...
2.2.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 4b15e51d33 | |||
| 4f98cc0267 | |||
| d7c9759d27 | |||
| 67f979a051 | |||
| 3a26248296 | |||
| a317773d85 |
27
build.gradle
27
build.gradle
@ -1,11 +1,8 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '1.0-SNAPSHOT'
|
||||
id 'fabric-loom' version '1.10.1'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
@ -18,6 +15,7 @@ dependencies {
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
}
|
||||
|
||||
loom {
|
||||
@ -32,8 +30,27 @@ processResources {
|
||||
}
|
||||
}
|
||||
|
||||
def targetJavaVersion = 21
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
it.options.release = 17
|
||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||
// this fixes some edge cases with special characters not displaying correctly
|
||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
// If Javadoc is generated, this must be specified in that task too.
|
||||
it.options.encoding = "UTF-8"
|
||||
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
|
||||
it.options.release.set(targetJavaVersion)
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||
if (JavaVersion.current() < javaVersion) {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||
}
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this line, sources will not be generated.
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
jar {
|
||||
|
||||
@ -3,12 +3,17 @@ org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.parallel=true
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/develop
|
||||
minecraft_version=1.19.3
|
||||
yarn_mappings=1.19.3+build.1
|
||||
loader_version=0.14.11
|
||||
# check these on https://fabricmc.net/develop
|
||||
|
||||
minecraft_version=1.21.6
|
||||
yarn_mappings=1.21.6+build.1
|
||||
loader_version=0.17.2
|
||||
loom_version=1.11-SNAPSHOT
|
||||
|
||||
# Fabric API
|
||||
fabric_version=0.128.2+1.21.6
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 2.0.0
|
||||
maven_group = de.zonlykroks
|
||||
archives_base_name = AdvancedScripts
|
||||
mod_version = 2.2.3
|
||||
maven_group = de.steamwar
|
||||
archives_base_name = AdvancedScripts
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
|
||||
networkTimeout=10000
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@ -4,7 +4,6 @@ pluginManagement {
|
||||
name = 'Fabric'
|
||||
url = 'https://maven.fabricmc.net/'
|
||||
}
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,10 +20,12 @@
|
||||
package de.steamwar.advancedscripts;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||
|
||||
public class AdvancedScripts implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
PayloadTypeRegistry.playC2S().register(KeyAction.ID, KeyAction.CODEC);
|
||||
}
|
||||
}
|
||||
|
||||
19
src/main/java/de/steamwar/advancedscripts/KeyAction.java
Normal file
19
src/main/java/de/steamwar/advancedscripts/KeyAction.java
Normal file
@ -0,0 +1,19 @@
|
||||
package de.steamwar.advancedscripts;
|
||||
|
||||
import net.minecraft.network.RegistryByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.network.codec.PacketCodecs;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public record KeyAction(int key, byte action, int modifiers) implements CustomPayload {
|
||||
private static final Identifier channel = Identifier.of("sw:hotkeys");
|
||||
|
||||
public static final CustomPayload.Id<KeyAction> ID = new CustomPayload.Id<>(channel);
|
||||
public static final PacketCodec<RegistryByteBuf, KeyAction> CODEC = PacketCodec.tuple(PacketCodecs.INTEGER, KeyAction::key, PacketCodecs.BYTE, KeyAction::action, PacketCodecs.INTEGER, KeyAction::modifiers, KeyAction::new);
|
||||
|
||||
@Override
|
||||
public Id<? extends CustomPayload> getId() {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
@ -33,9 +33,9 @@ public class TokenTypeColors {
|
||||
|
||||
public static final int VARIABLE = 0xFFFFFFFF;
|
||||
public static final int COMMENT = 0xFF656565;
|
||||
public static final int CONSTANT = 0x3F6EC6;
|
||||
public static final int CONSTANT = 0xFF3F6EC6;
|
||||
|
||||
public static final int NUMBER = 0xFF61839F;
|
||||
public static final int BOOLEAN = 0xFF925F35;
|
||||
public static final int STRING = 0x6a8759;
|
||||
public static final int STRING = 0xFF6a8759;
|
||||
}
|
||||
|
||||
@ -19,35 +19,22 @@
|
||||
|
||||
package de.steamwar.advancedscripts.mixin;
|
||||
|
||||
import io.netty.buffer.Unpooled;
|
||||
import de.steamwar.advancedscripts.KeyAction;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.minecraft.client.Keyboard;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Keyboard.class)
|
||||
public class KeyboardMixin {
|
||||
|
||||
@Unique
|
||||
private static final Identifier channel = new Identifier("sw:hotkeys");
|
||||
|
||||
@Inject(method = "onKey", at = @At("HEAD"))
|
||||
public void sendKeyPress(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) {
|
||||
MinecraftClient client = ((Keyboard) (Object)this).client;
|
||||
if(client.currentScreen == null && action != 2) {
|
||||
PacketByteBuf byteBuf = new PacketByteBuf(Unpooled.buffer());
|
||||
byteBuf.writeInt(key);
|
||||
byteBuf.writeByte(action);
|
||||
byteBuf.writeInt(modifiers);
|
||||
CustomPayloadC2SPacket customPayloadC2SPacket = new CustomPayloadC2SPacket(channel,byteBuf);
|
||||
client.getNetworkHandler().sendPacket(customPayloadC2SPacket);
|
||||
ClientPlayNetworking.send(new KeyAction(key, (byte) action, modifiers));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,33 +19,34 @@
|
||||
|
||||
package de.steamwar.advancedscripts.screen;
|
||||
|
||||
import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import de.steamwar.advancedscripts.lexer.TokenTypeColors;
|
||||
import de.steamwar.advancedscripts.lexer.ScriptColorizer;
|
||||
import de.steamwar.advancedscripts.lexer.Token;
|
||||
import de.steamwar.advancedscripts.lexer.TokenTypeColors;
|
||||
import net.minecraft.client.font.TextHandler;
|
||||
import net.minecraft.client.gui.DrawableHelper;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.ingame.BookEditScreen;
|
||||
import net.minecraft.client.gui.screen.ingame.BookScreen;
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
||||
import net.minecraft.client.gui.widget.PressableWidget;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import net.minecraft.client.util.NarratorManager;
|
||||
import net.minecraft.client.util.SelectionManager;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.WritableBookContentComponent;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket;
|
||||
import net.minecraft.text.RawFilteredPair;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Hand;
|
||||
import org.apache.commons.lang3.mutable.MutableInt;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ScriptEditScreen extends Screen {
|
||||
@ -73,19 +74,17 @@ public class ScriptEditScreen extends Screen {
|
||||
this.itemStack = itemStack;
|
||||
this.hand = hand;
|
||||
|
||||
NbtCompound nbtCompound = itemStack.getNbt();
|
||||
if (nbtCompound != null) {
|
||||
BookScreen.filterPages(nbtCompound, s -> {
|
||||
String[] split = s.split("\n");
|
||||
for (String s1 : split) {
|
||||
if (s1.equals(" ")) {
|
||||
lines.add("");
|
||||
} else {
|
||||
lines.add(s1);
|
||||
}
|
||||
List<RawFilteredPair<String>> pages = itemStack.get(DataComponentTypes.WRITABLE_BOOK_CONTENT).pages();
|
||||
pages.forEach(stringRawFilteredPair -> {
|
||||
for (String s : stringRawFilteredPair.raw().split("\n")) {
|
||||
if (s.isEmpty()) {
|
||||
lines.add("");
|
||||
} else {
|
||||
lines.add(s);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (lines.isEmpty()) {
|
||||
lines.add("");
|
||||
}
|
||||
@ -105,7 +104,7 @@ public class ScriptEditScreen extends Screen {
|
||||
this.addDrawableChild(
|
||||
new Button(BOOK, this.width - 98 - 5, height - 20 - 5, () -> {
|
||||
finalizeBook();
|
||||
this.client.setScreen(new BookEditScreen(player, itemStack, hand));
|
||||
this.client.setScreen(new BookEditScreen(player, itemStack, hand, toContent(toPages())));
|
||||
})
|
||||
);
|
||||
}
|
||||
@ -159,12 +158,9 @@ public class ScriptEditScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
setFocused(null);
|
||||
this.renderBackground(matrices);
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
fill(matrices, 23, 23, this.width - 23, this.height - 63, TokenTypeColors.BACKGROUND);
|
||||
context.fill(23, 23, this.width - 23, this.height - 63, TokenTypeColors.BACKGROUND);
|
||||
|
||||
int lineNumberLength = textRenderer.getWidth(lines.size() + "");
|
||||
|
||||
@ -185,15 +181,15 @@ public class ScriptEditScreen extends Screen {
|
||||
}
|
||||
|
||||
if (s.isEmpty() && i == cursorY) {
|
||||
drawCursor(matrices, 25 + lineNumberLength + 5, lineNumber.getValue() * 9 + 25, true);
|
||||
drawCursor(context, 25 + lineNumberLength + 5, lineNumber.getValue() * 9 + 25, true);
|
||||
}
|
||||
|
||||
// Line number
|
||||
int height = this.textRenderer.getWrappedLinesHeight(s, this.width - 50 - lineNumberLength - 5);
|
||||
if (lineTooLong(s)) {
|
||||
fill(matrices, 25 + lineNumberLength + 2, 25 + lineNumber.getValue() * 9, 25 + lineNumberLength + 3, 25 + lineNumber.getValue() * 9 + height, TokenTypeColors.ERROR);
|
||||
context.fill(25 + lineNumberLength + 2, 25 + lineNumber.getValue() * 9, 25 + lineNumberLength + 3, 25 + lineNumber.getValue() * 9 + height, TokenTypeColors.ERROR);
|
||||
}
|
||||
this.textRenderer.draw(matrices, String.valueOf(lineNumberText), 25f + lineNumberLength - textRenderer.getWidth(String.valueOf(lineNumberText)), 25f + lineNumber.getValue() * 9f, 0xFFFFFF);
|
||||
context.drawText(textRenderer, String.valueOf(lineNumberText), (int) (25f + lineNumberLength - textRenderer.getWidth(String.valueOf(lineNumberText))), (int) (25f + lineNumber.getValue() * 9f), 0xFFFFFFFF, false);
|
||||
lineNumberText++;
|
||||
|
||||
// Line text
|
||||
@ -234,15 +230,15 @@ public class ScriptEditScreen extends Screen {
|
||||
}
|
||||
|
||||
if (finalI >= minSelectionY && finalI <= maxSelectionY && x2 > x1) {
|
||||
fill(matrices, x1, y + 25, x2, y + 25 + 9, TokenTypeColors.SELECTION);
|
||||
context.fill(x1, y + 25, x2, y + 25 + 9, TokenTypeColors.SELECTION);
|
||||
}
|
||||
}
|
||||
|
||||
if (finalI == cursorY && currentXIndex.get() >= cursorX && previousXIndex <= cursorX) {
|
||||
drawCursor(matrices, x.get() + textRenderer.getWidth(line.substring(0, cursorX - previousXIndex)) - 1, 25 + y, isAtEndOfLine());
|
||||
drawCursor(context, x.get() + textRenderer.getWidth(line.substring(0, cursorX - previousXIndex)) - 1, 25 + y, isAtEndOfLine());
|
||||
}
|
||||
|
||||
this.textRenderer.draw(matrices, line, x.get(), 25 + y, token.color);
|
||||
context.drawText(this.textRenderer, line, x.get(), 25 + y, token.color, false);
|
||||
x.addAndGet(textRenderer.getWidth(line));
|
||||
if (x.get() > this.width - 50 - lineNumberLength - 5) {
|
||||
x.set(25 + lineNumberLength + 5);
|
||||
@ -253,7 +249,7 @@ public class ScriptEditScreen extends Screen {
|
||||
lineNumber.increment();
|
||||
}
|
||||
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
private boolean lineTooLong(String s) {
|
||||
@ -263,13 +259,13 @@ public class ScriptEditScreen extends Screen {
|
||||
return textRenderer.getWrappedLinesHeight(s, 114) > 128;
|
||||
}
|
||||
|
||||
private void drawCursor(MatrixStack matrices, int x, int y, boolean atEnd) {
|
||||
private void drawCursor(DrawContext context, int x, int y, boolean atEnd) {
|
||||
if (this.tickCounter / 6 % 2 == 0) {
|
||||
if (!atEnd) {
|
||||
Objects.requireNonNull(this.textRenderer);
|
||||
DrawableHelper.fill(matrices, x, y - 1, x + 1, y + 9, 0xFFFFFFFF);
|
||||
context.fill(x, y - 1, x + 1, y + 9, 0xFFFFFFFF);
|
||||
} else {
|
||||
this.textRenderer.draw(matrices, "_", (float) x, (float) y, 0xFFFFFFFF);
|
||||
context.drawText(this.textRenderer, "_", x, y, 0xFFFFFFFF, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -586,8 +582,8 @@ public class ScriptEditScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
|
||||
scroll -= Math.signum(amount);
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
|
||||
scroll -= (int) Math.signum(verticalAmount);
|
||||
if (scroll > lines.size() - 1) {
|
||||
scroll = lines.size() - 1;
|
||||
}
|
||||
@ -633,15 +629,17 @@ public class ScriptEditScreen extends Screen {
|
||||
private void finalizeBook() {
|
||||
List<String> pages = toPages();
|
||||
this.writeNbtData(pages);
|
||||
int i = this.hand == Hand.MAIN_HAND ? this.player.getInventory().selectedSlot : 40;
|
||||
int i = this.hand == Hand.MAIN_HAND ? this.player.getInventory().getSelectedSlot() : 40;
|
||||
this.client.getNetworkHandler().sendPacket(new BookUpdateC2SPacket(i, pages, Optional.empty()));
|
||||
}
|
||||
|
||||
private WritableBookContentComponent toContent(List<String> pages) {
|
||||
return new WritableBookContentComponent(pages.stream().map(string -> new RawFilteredPair<String>(string, Optional.empty())).toList());
|
||||
}
|
||||
|
||||
private void writeNbtData(List<String> pages) {
|
||||
NbtList nbtList = new NbtList();
|
||||
pages.stream().map(NbtString::of).forEach(nbtList::add);
|
||||
if (!pages.isEmpty()) {
|
||||
this.itemStack.setSubNbt("pages", nbtList);
|
||||
this.itemStack.set(DataComponentTypes.WRITABLE_BOOK_CONTENT, toContent(pages));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
accessWidener v1 named
|
||||
|
||||
accessible field net/minecraft/client/network/ClientPlayNetworkHandler serverInfo Lnet/minecraft/client/network/ServerInfo;
|
||||
accessible field net/minecraft/client/Keyboard client Lnet/minecraft/client/MinecraftClient;
|
||||
@ -22,8 +22,9 @@
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.11",
|
||||
"minecraft": ">=1.19.3",
|
||||
"java": ">=17"
|
||||
"minecraft": ">=1.20.6",
|
||||
"java": ">=21",
|
||||
"fabric-api": "*"
|
||||
},
|
||||
"accessWidener" : "advancedscripts.accesswidener"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user