Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
1.19 upd
Browse files Browse the repository at this point in the history
  • Loading branch information
JustS-js committed Jul 16, 2022
1 parent c59e326 commit 5a64078
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 43 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.10-SNAPSHOT'
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -28,10 +28,10 @@ dependencies {

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modApi("me.shedaniel.cloth:cloth-config-fabric:6.1.48") {
modApi("me.shedaniel.cloth:cloth-config-fabric:7.0.73") {
exclude(group: "net.fabricmc.fabric-api")
}
modImplementation "com.terraformersmc:modmenu:3.0.0"
modImplementation "com.terraformersmc:modmenu:4.0.4"
}

processResources {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.18
yarn_mappings=1.18+build.1
loader_version=0.12.12
minecraft_version=1.19
yarn_mappings=1.19+build.1
loader_version=0.14.6

# Mod Properties
mod_version = 1.18-1.0.0
mod_version = 1.19-1.0.0
maven_group = com.just_s
archives_base_name = ctp-mod

# Dependencies
fabric_version=0.44.0+1.18
fabric_version=0.55.1+1.19
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
27 changes: 15 additions & 12 deletions src/main/java/net/just_s/ctpmod/CTPMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.network.MessageType;
import net.minecraft.text.LiteralText;
import net.minecraft.network.ClientConnection;
import net.minecraft.text.Text;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -128,17 +128,20 @@ public void rawTp(String[] args) {
}

public void startReconnect(Point point) {
Screen newScr = new DisconnectedScreen(
new MultiplayerScreen(new TitleScreen()),
Text.of("§8[§6CatTeleport§8]"),
Text.of("startReconnect"));

server = MC.getCurrentServerEntry();
Objects.requireNonNull(MC.getNetworkHandler()).getConnection().disconnect(
new LiteralText("§8[§6CatTeleport§8]"));
MC.disconnect();
ClientConnection con = Objects.requireNonNull(MC.getNetworkHandler()).getConnection();
//con.disconnect(new LiteralText("§8[§6CatTeleport§8]"));

reconnectThread = new ReconnectThread(server, point.getStartPeriod(), point.getEndPeriod());
reconnectThread.start();
Screen newScr = new DisconnectedScreen(
new MultiplayerScreen(new TitleScreen()),
new LiteralText("§8[§6CatTeleport§8]"),
new LiteralText("startReconnect"));
MC.setScreen(newScr);

newScr.init(MC, 0, 0);
MC.disconnect(newScr);
}

public void finishReconnect() {
Expand All @@ -151,7 +154,7 @@ public void cancelReconnect() {
} catch (InterruptedException | NullPointerException ignored) {
}
LOGGER.info("Reconnecting cancelled.");
MC.setScreen(new DisconnectedScreen(new MultiplayerScreen(new TitleScreen()), new LiteralText("§8[§6CatTeleport§8]"), new LiteralText("cancelReconnect")));
MC.setScreen(new DisconnectedScreen(new MultiplayerScreen(new TitleScreen()), Text.of("§8[§6CatTeleport§8]"), Text.of("cancelReconnect")));
}

public void connectToServer(ServerInfo targetInfo) {
Expand All @@ -167,6 +170,6 @@ public static void printInGame(String... msgargs) {
//§4 dark_red §c red §6 gold
//§5 dark_purple §d light_purple
String msg = String.join(", ", msgargs);
MC.inGameHud.addChatMessage(MessageType.SYSTEM, new LiteralText("§8[§6CatTeleport§8]§2 " + msg), MC.player.getUuid());
MC.inGameHud.getChatHud().addMessage(Text.of("§8[§6CatTeleport§8]§2 " + msg));
}
}
8 changes: 4 additions & 4 deletions src/main/java/net/just_s/ctpmod/config/ConfigParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.io.File;
import java.io.FileWriter;
import java.util.Objects;

public class ConfigParser {
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
protected static final JsonParser PARSER = new JsonParser();

public static final ConfigParser INSTANCE = new ConfigParser(FabricLoader.getInstance().getConfigDir().resolve("ctpmod.json").toFile());
static {
Expand Down Expand Up @@ -89,13 +87,15 @@ public void save() {

protected int deltaFromJson(String json_string) {
//CTPMod.LOGGER.error("fromJson: " + json_string );
JsonObject object = JsonParser.parseString(json_string).getAsJsonObject();
JsonParser jsparser = new JsonParser();
JsonObject object = jsparser.parse(json_string).getAsJsonObject();
return object.getAsJsonPrimitive("delta").getAsInt();
}

protected Point[] pointsFromJson(String json_string) {
//CTPMod.LOGGER.error("fromJson: " + json_string );
JsonObject object = JsonParser.parseString(json_string).getAsJsonObject();
JsonParser jsparser = new JsonParser();
JsonObject object = jsparser.parse(json_string).getAsJsonObject();
String newJSONString = object.getAsJsonArray("points").toString();
return GSON.fromJson(newJSONString, Point[].class);
}
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/net/just_s/ctpmod/config/ConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import me.shedaniel.clothconfig2.api.*;
import net.just_s.ctpmod.CTPMod;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -16,21 +16,21 @@ public class ConfigScreen {
public static Screen buildScreen (Screen currentScreen) {
ConfigBuilder builder = ConfigBuilder.create()
.setParentScreen(currentScreen)
.setTitle(new LiteralText("Point Menu"))
.setTitle(Text.of("Point Menu"))
.setTransparentBackground(true)
.setSavingRunnable(() -> {
// CTPMod.points = pass;
CTPMod.config.save(); // Сохранить CTP.points в json
});

// mainCategory - Это экран
mainCategory = builder.getOrCreateCategory(new LiteralText("Null"));
mainCategory = builder.getOrCreateCategory(Text.of("Null"));
// entryBuilder - это билдер значения в точке
entryBuilder = builder.entryBuilder();

mainCategory.addEntry(entryBuilder.startIntField(new LiteralText("Delta"), CTPMod.delta)
mainCategory.addEntry(entryBuilder.startIntField(Text.of("Delta"), CTPMod.delta)
.setDefaultValue(1)
.setTooltip(new LiteralText("Amount of seconds between server and client (can be negative)"))
.setTooltip(Text.of("Amount of seconds between server and client (can be negative)"))
.setSaveConsumer(newValue -> CTPMod.delta = newValue)
.build());
for(int i=0; i < CTPMod.points.length; i++) {
Expand All @@ -45,22 +45,22 @@ public static Screen buildScreen (Screen currentScreen) {

public static void createOption(int PointIndex) {
List<AbstractConfigListEntry> listOfEntries = new ArrayList<>();
listOfEntries.add(entryBuilder.startStrField(new LiteralText("Point Name"), CTPMod.points[PointIndex].getName())
listOfEntries.add(entryBuilder.startStrField(Text.of("Point Name"), CTPMod.points[PointIndex].getName())
.setDefaultValue(CTPMod.points[PointIndex].getName()) // Recommended: Used when user click "Reset"
.setTooltip(new LiteralText("The name of current Point")) // Optional: Shown when the user hover over this option
.setTooltip(Text.of("The name of current Point")) // Optional: Shown when the user hover over this option
.setSaveConsumer(newValue -> CTPMod.points[PointIndex].setName(newValue)) // Сохранить точку в CTPMod.points
.build());
listOfEntries.add(entryBuilder.startIntField(new LiteralText("Start Period Time"), CTPMod.points[PointIndex].getStartPeriod())
listOfEntries.add(entryBuilder.startIntField(Text.of("Start Period Time"), CTPMod.points[PointIndex].getStartPeriod())
.setDefaultValue(CTPMod.points[PointIndex].getStartPeriod())
.setTooltip(new LiteralText("Amount of seconds before rejoining server"))
.setTooltip(Text.of("Amount of seconds before rejoining server"))
.setSaveConsumer(newValue -> CTPMod.points[PointIndex].setStartPeriod(newValue))
.build());
listOfEntries.add(entryBuilder.startIntField(new LiteralText("End Period Time"), CTPMod.points[PointIndex].getEndPeriod())
listOfEntries.add(entryBuilder.startIntField(Text.of("End Period Time"), CTPMod.points[PointIndex].getEndPeriod())
.setDefaultValue(CTPMod.points[PointIndex].getEndPeriod())
.setTooltip(new LiteralText("Amount of seconds after rejoining should not be executed"))
.setTooltip(Text.of("Amount of seconds after rejoining should not be executed"))
.setSaveConsumer(newValue -> CTPMod.points[PointIndex].setEndPeriod(newValue))
.build());
// startSubCategory - одна точка
mainCategory.addEntry(entryBuilder.startSubCategory(new LiteralText(CTPMod.points[PointIndex].getName()), listOfEntries).build());
mainCategory.addEntry(entryBuilder.startSubCategory(Text.of(CTPMod.points[PointIndex].getName()), listOfEntries).build());
}
}
1 change: 0 additions & 1 deletion src/main/java/net/just_s/ctpmod/config/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class Point {
private int startPeriod;
private int endPeriod;

public Point() {}
public Point(String name, int startPeriod, int endPeriod) {
this.name = name;
this.startPeriod = startPeriod;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/net/just_s/ctpmod/mixin/CTPMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.network.message.ChatMessageSigner;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -13,8 +15,8 @@
@Environment(EnvType.CLIENT)
@Mixin(ClientPlayerEntity.class)
public class CTPMixin {
@Inject(at = @At("HEAD"), method = "sendChatMessage", cancellable = true)
private void sendCustomMessage(String message, CallbackInfo ci) {
@Inject(at = @At("HEAD"), method = "sendChatMessagePacket", cancellable = true)
private void sendCustomMessage(ChatMessageSigner signer, String message, Text preview, CallbackInfo ci) {
if (message.charAt(0) == '&') {
CMDHandler.cmdHandler(message.substring(1).split(" "));
ci.cancel();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/just_s/ctpmod/util/ReconnectThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public void run() {
try {
int[] s = {secondsToReconnect - CTPMod.delta, 0};
CTPMod.LOGGER.info("reconnect in " + Collections.max(Arrays.asList(ArrayUtils.toObject(s))) + " sec");
Thread.sleep(Collections.max(Arrays.asList(ArrayUtils.toObject(s))) * 1000L);

Thread.sleep((Collections.max(Arrays.asList(ArrayUtils.toObject(s)))) * 1000L);
for (int i1 = 0; i1 < 10; i1++) {
pingServer();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"depends": {
"fabricloader": ">=0.11.3",
"fabric": "*",
"minecraft": "1.18.x",
"java": ">=16"
"minecraft": "1.19.x",
"java": ">=17"
},
"suggests": {
"another-mod": "*"
Expand Down

0 comments on commit 5a64078

Please sign in to comment.