Skip to content

Commit

Permalink
1.17.1
Browse files Browse the repository at this point in the history
  • Loading branch information
CmdrJane committed Aug 30, 2021
1 parent 2b1f8e8 commit a7b6665
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 105 deletions.
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
repositories {
maven { url "https://maven.shedaniel.me/" }
maven { url "https://repo.maven.apache.org"}
maven { url 'https://masa.dy.fi/maven' }
mavenCentral()
maven {
url "https://www.cursemaven.com"
Expand All @@ -27,8 +28,12 @@ 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 "curse.maven:charm-318872:3358030"

modApi("me.sargunvohra.mcmods:autoconfig1u:3.3.1")

modImplementation "curse.maven:charm-318872:3393290"
modImplementation "curse.maven:simple-utilities-356722:3349846"
modImplementation "curse.maven:litematica-308892:3387062"
implementation "com.moandjiezana.toml:toml4j:0.7.2"
implementation "com.electronwill.night-config:core:3.6.2"
implementation "com.electronwill.night-config:toml:3.6.2"
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.17
yarn_mappings=1.17+build.13
minecraft_version=1.17.1
yarn_mappings=1.17.1+build.46
loader_version=0.11.6

# Mod Properties
mod_version = 1.4.1
mod_version = 1.4.2
maven_group = net.fabricmc
archives_base_name = time-and-wind

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.36.0+1.17
fabric_version=0.39.2+1.17


10 changes: 10 additions & 0 deletions src/main/java/ru/aiefu/timeandwind/LitematicaIntegration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ru.aiefu.timeandwind;

import fi.dy.masa.litematica.world.WorldSchematic;
import net.minecraft.world.World;

public class LitematicaIntegration {
public static boolean checkInstance(World instance){
return instance instanceof WorldSchematic;
}
}
61 changes: 57 additions & 4 deletions src/main/java/ru/aiefu/timeandwind/TAWCommands.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
package ru.aiefu.timeandwind;

import com.google.gson.GsonBuilder;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Identifier;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class TAWCommands {
public static void reloadCfgReg(CommandDispatcher<ServerCommandSource> dispatcher){
public static void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher){
dispatcher.register(CommandManager.literal("taw").then(CommandManager.literal("reload").executes(context -> reloadCfg(context.getSource()))));
dispatcher.register(CommandManager.literal("taw").then(CommandManager.literal("get-current-world-id").executes(context -> printCurrentWorldId(context.getSource()))));

dispatcher.register(CommandManager.literal("taw").then(CommandManager.literal("parse-worlds-ids").executes(context -> parseWorldsIds(context.getSource()))));

dispatcher.register(CommandManager.literal("taw").then(CommandManager.literal("get-ambient-darkness").executes(context -> printAmbientDarkness(context.getSource()))));
dispatcher.register(CommandManager.literal("taw").then(CommandManager.literal("get-light-level").executes(context -> getLightLevel(context.getSource()))));

dispatcher.register(CommandManager.literal("taw").then(CommandManager.literal("get-time-data").executes(context -> getTimeConfig(context.getSource()))));
}

public static int reloadCfg(ServerCommandSource source) throws CommandSyntaxException {
if(source.hasPermissionLevel(4) || source.getMinecraftServer().isHost(source.getPlayer().getGameProfile())) {
MinecraftServer server = source.getMinecraftServer();
if(source.hasPermissionLevel(4) || source.getServer().isHost(source.getPlayer().getGameProfile())) {
MinecraftServer server = source.getServer();
IOManager.readTimeData();
source.getMinecraftServer().getWorlds().forEach(serverWorld -> {
source.getServer().getWorlds().forEach(serverWorld -> {
String id = serverWorld.getRegistryKey().getValue().toString();
if (TimeAndWind.timeDataMap.containsKey(id)) {
((IDimType) serverWorld.getDimension()).setCycleDuration(TimeAndWind.timeDataMap.get(id).dayDuration, TimeAndWind.timeDataMap.get(id).nightDuration);
Expand All @@ -44,5 +59,43 @@ public static int reloadCfg(ServerCommandSource source) throws CommandSyntaxExce
}
return 0;
}
public static int printCurrentWorldId(ServerCommandSource source) throws CommandSyntaxException {
String id = source.getPlayer().world.getRegistryKey().getValue().toString();
source.sendFeedback(new LiteralText(id), false);
ServerPlayNetworking.send(source.getPlayer(), new Identifier(TimeAndWind.MOD_ID, "world_id_clipboard"), new PacketByteBuf(Unpooled.buffer()).writeString(id));
return 0;
}
public static int printAmbientDarkness(ServerCommandSource source) throws CommandSyntaxException {
source.sendFeedback(new LiteralText("Ambient Darkness: " + source.getPlayer().world.getAmbientDarkness()), false);
return 0;
}
public static int parseWorldsIds(ServerCommandSource source) throws CommandSyntaxException {
if(source.hasPermissionLevel(4) || source.getServer().isHost(source.getPlayer().getGameProfile())) {
List<String> ids = new ArrayList<>();
source.getServer().getWorlds().forEach(serverWorld -> ids.add(serverWorld.getRegistryKey().getValue().toString()));
File file = new File("taw-worlds-ids.json");
new IOManager().fileWriter(file, new GsonBuilder().setPrettyPrinting().create().toJson(ids));
source.sendFeedback(new LiteralText("Saved to " + file.getAbsolutePath()), false);
} else source.sendError(new LiteralText("[Time & Wind] Permission level of 4 is required to run this command"));
return 0;
}
public static int getLightLevel(ServerCommandSource source) throws CommandSyntaxException {
source.sendFeedback(new LiteralText("Light Level: " + source.getPlayer().world.getLightLevel(source.getPlayer().getBlockPos())), false);
return 0;
}

public static int getTimeConfig(ServerCommandSource source) throws CommandSyntaxException {
ServerPlayerEntity player = source.getPlayer();
String worldId = player.world.getRegistryKey().getValue().toString();
if(player.world.getDimension().hasFixedTime()){
source.sendFeedback(new LiteralText("Current dimension has fixed time, custom configuration is useless"), false);
} else source.sendFeedback(new LiteralText("Current dimension does not has fixed time, custom configuration should work fine"), false);
if(TimeAndWind.timeDataMap.containsKey(worldId)) {
TimeDataStorage storage = TimeAndWind.timeDataMap.get(worldId);
source.sendFeedback(new LiteralText("Server config for current world: Day Duration: " + storage.dayDuration + " Night Duration: " + storage.nightDuration), true);
ServerPlayNetworking.send(player, new Identifier(TimeAndWind.MOD_ID, "cfg_debug_info"), new PacketByteBuf(Unpooled.buffer()));
} else source.sendError(new LiteralText("No Data found for current world on server side"));
return 0;
}

}
23 changes: 16 additions & 7 deletions src/main/java/ru/aiefu/timeandwind/TimeAndWind.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -20,17 +22,17 @@

public class TimeAndWind implements ModInitializer {
public static final String MOD_ID = "timeandwind";
public static final Logger LOGGER = LogManager.getLogger();
public static HashMap<String, TimeDataStorage> timeDataMap;

@Override
public void onInitialize() {
LOGGER.info("[Time & Wind] Initializing...");
craftPaths();
ServerLifecycleEvents.SERVER_STARTING.register(server -> {
IOManager.readTimeData();
});
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
TAWCommands.reloadCfgReg(dispatcher);
});
registerReceivers();
ServerLifecycleEvents.SERVER_STARTING.register(server -> IOManager.readTimeData());
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> TAWCommands.registerCommands(dispatcher));
LOGGER.info("[Time & Wind] I'm in time control now!");
}

public void craftPaths(){
Expand Down Expand Up @@ -67,6 +69,7 @@ public static void sendConfigSyncPacket(ServerPlayerEntity player){
NbtCompound tag = new NbtCompound();
tag.put("tawConfig", listTag);
ServerPlayNetworking.send(player, new Identifier(MOD_ID, "sync_config"), new PacketByteBuf(Unpooled.buffer()).writeNbt(tag));
LOGGER.info("[Time & Wind] Sending config to player");
}
}
public static String get24TimeFormat(World world){
Expand Down Expand Up @@ -104,5 +107,11 @@ public static String get24TimeFormat(World world){
}
return new int[]{0,0};
}

private void registerReceivers(){
ServerPlayNetworking.registerGlobalReceiver(new Identifier(TimeAndWind.MOD_ID, "request_resync"), (server, player, handler, buf, responseSender) -> {
sendConfigSyncPacket(player);
LOGGER.warn("[Time & Wind] Player requested config resync, this shouldn't happen");
LOGGER.info("[Time & Wind] Sending resync packet");
});
}
}
64 changes: 50 additions & 14 deletions src/main/java/ru/aiefu/timeandwind/TimeAndWindClient.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package ru.aiefu.timeandwind;

import io.netty.buffer.Unpooled;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;

import java.util.HashMap;

Expand All @@ -26,21 +30,53 @@ public void onInitializeClient() {
}
});
ClientPlayNetworking.registerGlobalReceiver(new Identifier(TimeAndWind.MOD_ID, "sync_config"), (client, handler, buf, responseSender) -> {
NbtList list = buf.readNbt().getList("tawConfig", 10);
TimeAndWind.timeDataMap = new HashMap<>();
for (int i = 0; i < list.size(); ++i) {
NbtCompound tag = list.getCompound(i);
String id = tag.getString("id");
long dayD = tag.getLong("dayD");
long nightD = tag.getLong("nightD");
TimeDataStorage storage = new TimeDataStorage(dayD, nightD);
TimeAndWind.timeDataMap.put(id, storage);
if(buf.readableBytes() > 0 ){
NbtCompound nbtCMP = buf.readNbt();
if(nbtCMP != null) {
NbtList list = nbtCMP.getList("tawConfig", 10);
TimeAndWind.timeDataMap = new HashMap<>();
for (int i = 0; i < list.size(); ++i) {
NbtCompound tag = list.getCompound(i);
String id = tag.getString("id");
long dayD = tag.getLong("dayD");
long nightD = tag.getLong("nightD");
TimeDataStorage storage = new TimeDataStorage(dayD, nightD);
TimeAndWind.timeDataMap.put(id, storage);
}
ClientWorld clientWorld = MinecraftClient.getInstance().world;
if (clientWorld != null) {
IDimType dim = (IDimType) clientWorld.getDimension();
TimeDataStorage storage = TimeAndWind.timeDataMap.get(clientWorld.getRegistryKey().getValue().toString());
dim.setCycleDuration(storage.dayDuration, storage.nightDuration);
}
TimeAndWind.LOGGER.info("[Time & Wind] Configuration synchronized");
return;
}
}
ClientWorld clientWorld = MinecraftClient.getInstance().world;
if(clientWorld != null) {
IDimType dim = (IDimType) clientWorld.getDimension();
TimeDataStorage storage = TimeAndWind.timeDataMap.get(clientWorld.getRegistryKey().getValue().toString());
dim.setCycleDuration(storage.dayDuration, storage.nightDuration);
TimeAndWind.LOGGER.warn("[Time & Wind] Sync failed, requesting resync");
ClientPlayNetworking.send(new Identifier(TimeAndWind.MOD_ID, "request_resync"), new PacketByteBuf(Unpooled.buffer()));
});
ClientPlayNetworking.registerGlobalReceiver(new Identifier(TimeAndWind.MOD_ID, "cfg_debug_info"), (client, handler, buf, responseSender) -> {
try {
String worldId = client.world.getRegistryKey().getValue().toString();
if (TimeAndWind.timeDataMap.containsKey(worldId)) {
TimeDataStorage storage = TimeAndWind.timeDataMap.get(worldId);
client.player.sendSystemMessage(new LiteralText("Client config for current world: Day Duration: " + storage.dayDuration + " Night Duration: " + storage.nightDuration), Util.NIL_UUID);
} else
client.player.sendSystemMessage(new LiteralText("No Data found for current world on client side"), Util.NIL_UUID);
} catch (NullPointerException e){
e.printStackTrace();
}
});
ClientPlayNetworking.registerGlobalReceiver(new Identifier(TimeAndWind.MOD_ID, "world_id_clipboard"), (client, handler, buf, responseSender) -> {
try{
if(buf.readableBytes() > 0) {
String string = buf.readString();
client.keyboard.setClipboard(string);
client.player.sendMessage(new LiteralText("Also copied this to clipboard"), false);
}
} catch (Exception e){
e.printStackTrace();
}
});
}
Expand Down

This file was deleted.

33 changes: 0 additions & 33 deletions src/main/java/ru/aiefu/timeandwind/mixin/MinecraftClientMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.aiefu.timeandwind.mixin;


import net.johnvictorfs.simple_utilities.hud.GameInfoHud;
import net.minecraft.client.MinecraftClient;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -11,7 +12,7 @@

@Pseudo
@Mixin(GameInfoHud.class)
public class SimpleUtilsGIHMixins {
public class SimpleUtilsMixins {
@Inject(method = "parseTime", at =@At("HEAD"), cancellable = true, remap = false)
private static void patchTimeParserTAW(long time, CallbackInfoReturnable<String> cir){
cir.setReturnValue(TimeAndWind.get24TimeFormat(MinecraftClient.getInstance().world));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void craftPacthedTaskBaby(Brain brain, Schedule schedule){


@ModifyConstant(method = "hasRecentlySlept", constant = @Constant(longValue = 24000L))
private long hasRecentlyWorkedAndSleptPatchTAW(long l){
return 24000L;
private long hasRecentlySleptPatchTAW(long l){
return ((IDimType)this.world.getDimension()).getCycleDuration();
}
}
Loading

0 comments on commit a7b6665

Please sign in to comment.