Skip to content

Commit

Permalink
Rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Jan 9, 2025
1 parent 4437735 commit dc5c029
Show file tree
Hide file tree
Showing 15 changed files with 367 additions and 207 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {

toolkitLoomHelper {
useOneConfig {
version = "1.0.0-alpha.49"
version = "1.0.0-alpha.55"
loaderVersion = "1.1.0-alpha.35"

usePolyMixin = true
Expand Down Expand Up @@ -45,7 +45,7 @@ toolkitLoomHelper {
}

dependencies {
implementation(shade("org.shredzone.commons:commons-suncalc:3.5")!!)
implementation(shade("dev.deftu:commons-suncalc:0.1.0")!!)

// Add Fabric Language Kotlin and (Legacy) Fabric API as dependencies (these are both optional but are particularly useful).
if (mcData.isFabric) {
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/org/polyfrost/polytime/mixin/WorldInfoMixin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.polyfrost.polytime.mixin;

import org.polyfrost.polytime.config.ModConfig;
import org.polyfrost.polytime.PolyTime;
import org.polyfrost.polytime.client.PolyTimeClient;
import org.polyfrost.polytime.client.PolyTimeConfig;
import org.spongepowered.asm.mixin.*;

//#if MODERN==0
Expand All @@ -21,10 +21,16 @@ public class WorldInfoMixin {
@Shadow
private long worldTime;

/**
* @author Deftu
* @reason Replace the world time with the PolyTime time
*/
@Overwrite
public long getWorldTime() {
if (ModConfig.INSTANCE.getEnabled())
return PolyTime.INSTANCE.timeToTicks();
if (PolyTimeConfig.INSTANCE.getEnabled()) {
return PolyTimeClient.getCurrentTime();
}

return this.worldTime;
}
//#else
Expand All @@ -33,8 +39,10 @@ public long getWorldTime() {
//$$
//$$ @Overwrite
//$$ public long getDayTime() {
//$$ if (ModConfig.INSTANCE.getEnabled())
//$$ return PolyTime.INSTANCE.timeToTicks();
//$$ if (PolyTimeConfig.INSTANCE.getEnabled()) {
//$$ return PolyTimeClient.getCurrentTime();
//$$ }
//$$
//$$ return this.dayTime;
//$$ }
//#endif
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/org/polyfrost/polytime/mixin/WorldProviderMixin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.polyfrost.polytime.mixin;

import org.polyfrost.polytime.config.ModConfig;
import org.polyfrost.polytime.PolyTime;
import org.polyfrost.polytime.client.PolyTimeConfig;
import org.polyfrost.polytime.client.realtime.RealTimeHandler;
import org.spongepowered.asm.mixin.*;

//#if MODERN == 0
Expand All @@ -17,6 +17,10 @@
//#endif
public class WorldProviderMixin {

/**
* @author Deftu
* @reason Implements lunar phases
*/
@Overwrite
public int
//#if MODERN == 0
Expand All @@ -25,8 +29,10 @@ public class WorldProviderMixin {
//$$ moonPhase
//#endif
(long worldTime) {
if (ModConfig.INSTANCE.getEnabled() && ModConfig.INSTANCE.getIrlLunarPhases())
return PolyTime.INSTANCE.getLunarPhase();
if (PolyTimeConfig.INSTANCE.getEnabled() && PolyTimeConfig.INSTANCE.getIrlLunarPhases()) {
return RealTimeHandler.getCurrentLunarPhase();
}

return (int) (worldTime / 24000L % 8L + 8L) % 8;
}
}
141 changes: 0 additions & 141 deletions src/main/kotlin/org/polyfrost/polytime/PolyTime.kt

This file was deleted.

10 changes: 10 additions & 0 deletions src/main/kotlin/org/polyfrost/polytime/PolyTimeConstants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.polyfrost.polytime

object PolyTimeConstants {

// Sets the variables from `gradle.properties`. Depends on the `bloom` DGT plugin.
const val ID: String = "@MOD_ID@"
const val NAME: String = "@MOD_NAME@"
const val VERSION: String = "@MOD_VERSION@"

}
90 changes: 90 additions & 0 deletions src/main/kotlin/org/polyfrost/polytime/PolyTimeEntrypoint.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.polyfrost.polytime

//#if FABRIC
//$$ import net.fabricmc.api.ModInitializer
//$$ import net.fabricmc.api.ClientModInitializer
//$$ import net.fabricmc.api.DedicatedServerModInitializer
//#elseif FORGE
//#if MC >= 1.16.5
//$$ import net.minecraftforge.eventbus.api.IEventBus
//$$ import net.minecraftforge.fml.common.Mod
//$$ import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent
//$$ import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent
//$$ import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent
//$$ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext
//#else
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.Mod.EventHandler
import net.minecraftforge.fml.common.event.FMLInitializationEvent

//#endif
//#elseif NEOFORGE
//$$ import net.neoforged.bus.api.IEventBus
//$$ import net.neoforged.fml.common.Mod
//$$ import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent
//$$ import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent
//$$ import net.neoforged.fml.event.lifecycle.FMLDedicatedServerSetupEvent
//#endif

import org.polyfrost.polytime.client.PolyTimeClient

//#if FORGE-LIKE
//#if MC >= 1.16.5
//$$ @Mod(ExampleConstants.ID)
//#else
@Mod(modid = PolyTimeConstants.ID, version = PolyTimeConstants.VERSION)
//#endif
//#endif

class PolyTimeEntrypoint
//#if FABRIC
//$$ : ClientModInitializer
//#endif
{

//#if FORGE && MC >= 1.16.5
//$$ init {
//$$ setupForgeEvents(FMLJavaModLoadingContext.get().getModEventBus())
//$$ }
//#elseif NEOFORGE
//$$ constructor(modEventBus: IEventBus) {
//$$ setupForgeEvents(modEventBus)
//$$ }
//#endif

//#if FABRIC
//$$ @Override
//#elseif FORGE && MC <= 1.12.2
@EventHandler
//#endif
fun onInitializeClient(
//#if FORGE-LIKE
//#if MC >= 1.16.5
//$$ FMLClientSetupEvent event
//#else
event: FMLInitializationEvent
//#endif
//#endif
) {
//#if FORGE && MC <= 1.12.2
//$$ if (!event
//#if MC <= 1.8.9
//$$ .side.isClient
//#else
//$$ .getSide().isClient()
//#endif
//$$ ) {
//$$ return;
//$$ }
//#endif

PolyTimeClient.initialize()
}

//#if FORGE-LIKE && MC >= 1.16.5
//$$ private fun setupForgeEvents(modEventBus: IEventBus) {
//$$ modEventBus.addListener(this::onInitializeClient)
//$$ }
//#endif

}
13 changes: 0 additions & 13 deletions src/main/kotlin/org/polyfrost/polytime/PolyTimeFabric.kt

This file was deleted.

23 changes: 0 additions & 23 deletions src/main/kotlin/org/polyfrost/polytime/PolyTimeForge.kt

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/kotlin/org/polyfrost/polytime/client/PolyTimeClient.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.polyfrost.polytime.client

import org.polyfrost.oneconfig.api.commands.v1.CommandManager
import org.polyfrost.polytime.client.realtime.RealTimeHandler
import org.polyfrost.polytime.realTimeToGameTime

object PolyTimeClient {

@JvmStatic
val currentTime: Long
get() = (if (PolyTimeConfig.irlTime) RealTimeHandler.currentTime else PolyTimeConfig.time).realTimeToGameTime()

fun initialize() {
PolyTimeConfig.preload()
CommandManager.registerCommand(PolyTimeCommand())
}

}
Loading

0 comments on commit dc5c029

Please sign in to comment.