Updated play time overlay so it uses world time and real days are tracked independently from the world time
parent
801429d27f
commit
2ab1a2ab8a
|
@ -6,13 +6,22 @@ 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 {
|
||||||
|
|
||||||
|
private static final Minecraft INSTANCE;
|
||||||
|
public static final String SPAWN_TIME_TAG = "SpawnTime";
|
||||||
|
public static final String PLAY_TIME_TAG = "PlayTime";
|
||||||
|
public static long playTime;
|
||||||
|
|
||||||
|
static {
|
||||||
|
INSTANCE = getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
public static Minecraft getInstance() {
|
public static Minecraft getInstance() {
|
||||||
|
if (INSTANCE != null) {
|
||||||
|
return INSTANCE;
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
Field f = Minecraft.class.getDeclaredField("instance");
|
Field f = Minecraft.class.getDeclaredField("instance");
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
|
@ -22,23 +31,15 @@ public class WyHelper {
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
@ -98,10 +99,10 @@ public class WyHelper {
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,7 +33,9 @@
|
||||||
"FenceTileMixin",
|
"FenceTileMixin",
|
||||||
"LevelMonsterSpawnerMixin",
|
"LevelMonsterSpawnerMixin",
|
||||||
"BedTileMixin",
|
"BedTileMixin",
|
||||||
"BoatMixin"
|
"BoatMixin",
|
||||||
|
"LevelPropertiesMixin",
|
||||||
|
"LevelMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": -1
|
"defaultRequire": -1
|
||||||
|
|
Loading…
Reference in New Issue