Skip to content

Commit 36a8437

Browse files
PTime Command, not tested on server build. Only on singleplayer Open to LAN
1 parent fa2408f commit 36a8437

6 files changed

Lines changed: 120 additions & 2 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package westeroscraft;
2+
3+
import net.fabricmc.api.ClientModInitializer;
4+
import westeroscraft.commands.PTimeCommand;
5+
6+
public class WesterosCraftEssentialsClient implements ClientModInitializer {
7+
public static WesterosCraftEssentialsClient INSTANCE;
8+
public long time;
9+
public boolean enabledTime = false;
10+
11+
@Override
12+
public void onInitializeClient() {
13+
PTimeCommand.register();
14+
INSTANCE = this;
15+
}
16+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package westeroscraft.commands;
2+
3+
import com.mojang.brigadier.arguments.IntegerArgumentType;
4+
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
5+
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
6+
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
7+
import net.minecraft.commands.arguments.TimeArgument;
8+
import westeroscraft.WesterosCraftEssentialsClient;
9+
10+
public class PTimeCommand {
11+
public static void register() {
12+
ClientCommandRegistrationCallback.EVENT.register((dispatcher, access) -> dispatcher.register(ClientCommandManager.literal("ptime")
13+
.then(ClientCommandManager.literal("reset").executes((context) -> resetTime(context.getSource())))
14+
.then(ClientCommandManager.literal("set")
15+
.then(ClientCommandManager.literal("normal").executes((context) -> resetTime(context.getSource())))
16+
.then(ClientCommandManager.literal("default").executes((context) -> resetTime(context.getSource())))
17+
.then(ClientCommandManager.literal("sunrise").executes((context) -> setTime(context.getSource(), Time.SUNRISE.time, false)))
18+
.then(ClientCommandManager.literal("day").executes((context) -> setTime(context.getSource(), Time.DAY.time, false)))
19+
.then(ClientCommandManager.literal("morning").executes((context) -> setTime(context.getSource(), Time.MORNING.time, false)))
20+
.then(ClientCommandManager.literal("noon").executes((context) -> setTime(context.getSource(), Time.NOON.time, false)))
21+
.then(ClientCommandManager.literal("afternoon").executes((context) -> setTime(context.getSource(), Time.AFTERNOON.time, false)))
22+
.then(ClientCommandManager.literal("sunset").executes((context) -> setTime(context.getSource(), Time.SUNSET.time, false)))
23+
.then(ClientCommandManager.literal("midnight").executes((context) -> setTime(context.getSource(), Time.MIDNIGHT.time, false)))
24+
.then(ClientCommandManager.argument("time", TimeArgument.time()).executes((context) -> setTime(context.getSource(), IntegerArgumentType.getInteger(context, "time"), false)))
25+
)
26+
.then(ClientCommandManager.literal("setrelative")
27+
.then(ClientCommandManager.literal("ahead")
28+
.then(ClientCommandManager.argument("time", TimeArgument.time()).executes((context) -> setTime(context.getSource(), IntegerArgumentType.getInteger(context, "time"), true)))
29+
)
30+
.then(ClientCommandManager.literal("behind")
31+
.then(ClientCommandManager.argument("time", TimeArgument.time()).executes((context) -> setTime(context.getSource(), -IntegerArgumentType.getInteger(context, "time"), true)))
32+
)
33+
)
34+
));
35+
}
36+
37+
public static int resetTime(FabricClientCommandSource source) {
38+
WesterosCraftEssentialsClient.INSTANCE.enabledTime = false;
39+
WesterosCraftEssentialsClient.INSTANCE.time = source.getWorld().getDayTime();
40+
return 1;
41+
}
42+
43+
public static int setTime(FabricClientCommandSource source, long time, boolean relative) {
44+
if(relative) {
45+
if(WesterosCraftEssentialsClient.INSTANCE.enabledTime) {
46+
WesterosCraftEssentialsClient.INSTANCE.time += time;
47+
} else {
48+
WesterosCraftEssentialsClient.INSTANCE.time = source.getWorld().getDayTime() + time;
49+
}
50+
} else {
51+
WesterosCraftEssentialsClient.INSTANCE.time = time;
52+
}
53+
WesterosCraftEssentialsClient.INSTANCE.enabledTime = true;
54+
return 1;
55+
}
56+
}
57+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package westeroscraft.commands;
2+
3+
public enum Time {
4+
SUNRISE(0),
5+
DAY(1000),
6+
MORNING(2000),
7+
NOON(6000),
8+
AFTERNOON(9000),
9+
SUNSET(12000),
10+
NIGHT(13000),
11+
MIDNIGHT(18000);
12+
13+
public final int time;
14+
15+
Time(int i) {
16+
this.time = i;
17+
}
18+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package westeroscraft.mixin;
2+
3+
import net.fabricmc.api.EnvType;
4+
import net.fabricmc.api.Environment;
5+
import net.minecraft.client.multiplayer.ClientLevel;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Inject;
9+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
10+
import westeroscraft.WesterosCraftEssentialsClient;
11+
12+
@Mixin(ClientLevel.ClientLevelData.class)
13+
public abstract class ClientLevelMixin {
14+
15+
@Inject(at = @At("RETURN"), method = "getDayTime", cancellable = true)
16+
@Environment(EnvType.CLIENT)
17+
public void getDayTime(CallbackInfoReturnable<Long> cir) {
18+
if(WesterosCraftEssentialsClient.INSTANCE.enabledTime) {
19+
cir.setReturnValue(WesterosCraftEssentialsClient.INSTANCE.time);
20+
} else cir.cancel();
21+
}
22+
}

src/main/resources/fabric.mod.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"description": "WesterosCraftCore is a custom Fabric mod that handles various requirements for the WesterosCraft server",
77
"authors": [
88
"geeberry",
9-
"mikeprimm"
9+
"mikeprimm",
10+
"earlofberkeley"
1011
],
1112
"contact": {
1213
"homepage": "https://westeroscraft.com/",
@@ -19,6 +20,9 @@
1920
"main": [
2021
"westeroscraft.WesterosCraftEssentials"
2122
],
23+
"client": [
24+
"westeroscraft.WesterosCraftEssentialsClient"
25+
],
2226
"fabric-datagen": [
2327
"westeroscraft.WesterosCraftEssentialsDataGenerator"
2428
]

src/main/resources/westeroscraft-essentials.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"DoorBlockMixin",
1616
"TrapDoorBlockMixin",
1717
"FenceGateBlockMixin",
18-
"ServerPlayerMixin"
18+
"ServerPlayerMixin",
19+
"ClientLevelMixin"
1920
],
2021
"injectors": {
2122
"defaultRequire": 1

0 commit comments

Comments
 (0)