Updated play time overlay so it uses world time and real days are tracked independently from the world time

master
Wynd 2024-01-07 13:29:03 +02:00
parent 801429d27f
commit 2ab1a2ab8a
5 changed files with 88 additions and 34 deletions

View File

@ -6,39 +6,40 @@ import java.time.Duration;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.Player; import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemInstance;
import net.minecraft.item.ItemType;
import net.minecraft.stat.Stats;
public class WyHelper { public class WyHelper {
public static Minecraft getInstance() { private static final Minecraft INSTANCE;
try { public static final String SPAWN_TIME_TAG = "SpawnTime";
Field f = Minecraft.class.getDeclaredField("instance"); public static final String PLAY_TIME_TAG = "PlayTime";
f.setAccessible(true); public static long playTime;
return (Minecraft) f.get(null);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { static {
e.printStackTrace(); INSTANCE = getInstance();
}
public static Minecraft getInstance() {
if (INSTANCE != null) {
return INSTANCE;
} else {
try {
Field f = Minecraft.class.getDeclaredField("instance");
f.setAccessible(true);
return (Minecraft) f.get(null);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
return null;
} }
return null;
} }
public static boolean isTimeBehind() {
// int currentPlayTime = WyHelper.getInstance().statManager.getStatAmount(Stats.playOneMinute)
return false;
}
public static long getTicksPlayed() {
return WyHelper.getInstance().statManager.getStatAmount(Stats.playOneMinute);
}
public static long getRealDaysPlayed() { public static long getRealDaysPlayed() {
int seconds = WyHelper.getInstance().statManager.getStatAmount(Stats.playOneMinute) / 20; long seconds = WyHelper.playTime / 20;
return Duration.ofSeconds(seconds).toDays(); return Duration.ofSeconds(seconds).toDays();
} }
public static long getGameDaysPlayed() { public static long getGameDaysPlayed() {
int seconds = WyHelper.getInstance().statManager.getStatAmount(Stats.playOneMinute) / 20; long seconds = WyHelper.getInstance().level.getLevelTime() / 20;
return Duration.ofSeconds(seconds).toMinutes() / 20; return Duration.ofSeconds(seconds).toMinutes() / 20;
} }
@ -56,7 +57,7 @@ public class WyHelper {
public static void cheatCommand(Player player) { public static void cheatCommand(Player player) {
player.dropItem(new ItemInstance(ItemType.boat, 1)); // player.dropItem(new ItemInstance(ItemType.boat, 1));
// int x = MathsHelper.floor(player.x); // int x = MathsHelper.floor(player.x);
// int y = MathsHelper.floor(player.boundingBox.minY); // int y = MathsHelper.floor(player.boundingBox.minY);
@ -97,11 +98,11 @@ public class WyHelper {
// Pig animal = new Pig(player.level); // Pig animal = new Pig(player.level);
// animal.setPositionAndAngles(player.x + 2, player.y, player.z, 0.0f, 0.0f); // animal.setPositionAndAngles(player.x + 2, player.y, player.z, 0.0f, 0.0f);
// player.level.spawnEntity(animal); // player.level.spawnEntity(animal);
player.level.setLevelTime(0); // player.level.setLevelTime(0);
player.level.getProperties().setRaining(false); // player.level.getProperties().setRaining(false);
player.level.getProperties().setRainTime(0); // player.level.getProperties().setRainTime(0);
player.level.getProperties().setThundering(false); // player.level.getProperties().setThundering(false);
player.level.getProperties().setThunderTime(0); // player.level.getProperties().setThunderTime(0);
} }
} }

View File

@ -27,12 +27,12 @@ public class ClientPlayerMixin {
Minecraft mc = WyHelper.getInstance(); Minecraft mc = WyHelper.getInstance();
Player player = (Player) (Object) this; Player player = (Player) (Object) this;
if (player.vehicle != null && key == Keyboard.KEY_LSHIFT) { if (player.vehicle != null && key == Keyboard.KEY_LSHIFT && state) {
player.startRiding(null); player.startRiding(null);
return; return;
} }
if (ModConfig.STACK_DROP.get() && key == mc.options.dropKey.key && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { if (ModConfig.STACK_DROP.get() && key == mc.options.dropKey.key && state && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
ItemInstance heldItem = player.inventory.getHeldItem(); ItemInstance heldItem = player.inventory.getHeldItem();
if (heldItem != null && heldItem.count > 0) { if (heldItem != null && heldItem.count > 0) {
player.dropItem(player.inventory.takeInvItem(player.inventory.selectedHotbarSlot, heldItem.count), false); player.dropItem(player.inventory.takeInvItem(player.inventory.selectedHotbarSlot, heldItem.count), false);

View File

@ -0,0 +1,19 @@
package xyz.pixelatedw.finalbeta.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.level.Level;
import xyz.pixelatedw.finalbeta.WyHelper;
@Mixin(Level.class)
public class LevelMixin {
@Inject(method = "method_242", at = @At(value = "INVOKE", target = "Lnet/minecraft/level/LevelMonsterSpawner;method_1870"))
public void tick(CallbackInfo ci) {
WyHelper.playTime++;
}
}

View File

@ -0,0 +1,32 @@
package xyz.pixelatedw.finalbeta.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.level.LevelProperties;
import net.minecraft.util.io.CompoundTag;
import xyz.pixelatedw.finalbeta.WyHelper;
@Mixin(LevelProperties.class)
public class LevelPropertiesMixin {
private long spawnTime;
@Inject(method = "<init>", at = @At("TAIL"))
public void settingSpawnTime(CompoundTag nbt, CallbackInfo ci) {
if (!nbt.containsKey(WyHelper.SPAWN_TIME_TAG)) {
this.spawnTime = System.currentTimeMillis();
} else {
this.spawnTime = nbt.getLong(WyHelper.SPAWN_TIME_TAG);
}
WyHelper.playTime = nbt.getLong(WyHelper.PLAY_TIME_TAG);
}
@Inject(method = "updateProperties", at = @At("TAIL"))
public void updateSpawnTime(CompoundTag worldNbt, CompoundTag playerNbt, CallbackInfo ci) {
worldNbt.put(WyHelper.SPAWN_TIME_TAG, this.spawnTime);
worldNbt.put(WyHelper.PLAY_TIME_TAG, WyHelper.playTime);
}
}

View File

@ -33,7 +33,9 @@
"FenceTileMixin", "FenceTileMixin",
"LevelMonsterSpawnerMixin", "LevelMonsterSpawnerMixin",
"BedTileMixin", "BedTileMixin",
"BoatMixin" "BoatMixin",
"LevelPropertiesMixin",
"LevelMixin"
], ],
"injectors": { "injectors": {
"defaultRequire": -1 "defaultRequire": -1