Skip to content

Commit

Permalink
fixes for 0.1.37, added require = 0 to logging mixins, added option t…
Browse files Browse the repository at this point in the history
…o disable data mods
  • Loading branch information
Nanobass committed Jun 23, 2024
1 parent e4d01d0 commit abf50c5
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ dependencies {
compileOnly("io.github.llamalad7:mixinextras-fabric:0.3.5")

// Modmenu
compileOnly("dev.crmodders:modmenu:${modmenu_version}")
gameMod("dev.crmodders:modmenu:${modmenu_version}")

// https://mvnrepository.com/artifact/org.greenrobot/eventbus
shadowMe("org.greenrobot:eventbus:${eventbus_version}")
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ flux_desc = The central modding API for Cosmic Reach Fabric/Quilt
group = dev.crmodders

# Game & Loader
cosmic_reach_version = 0.1.36
cosmic_reach_version = 0.1.37
cosmic_quilt_version = 2.1.1
fabric_loader_version = 0.15.7

# Extra mods
modmenu_version = 1.0.5
modmenu_version = 1.0.3

# Dependencies
eventbus_version = 3.1.1
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/crmodders/flux/FluxSettings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.crmodders.flux;

import dev.crmodders.flux.localization.Language;
import finalforeach.cosmicreach.settings.BooleanSetting;
import finalforeach.cosmicreach.settings.IntSetting;

/**
Expand All @@ -10,6 +11,7 @@
public class FluxSettings {

public static final IntSetting AntiAliasing = new IntSetting("msaa", 4);
public static final BooleanSetting EnabledVanillaMods = new BooleanSetting("enableVanillaMods", true);
public static Language SelectedLanguage;

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public <T> T loadSync(String fileName, Class<T> assetClass) {

public <T> T get(String fileName, Class<T> assetClass) {
if(!assetManager.isLoaded(fileName)) {
LOGGER.error("Asset not loaded {} ({})", fileName, assetClass.getSimpleName());
LOGGER.error("Asset not loaded {} ({}) loading now", fileName, assetClass.getSimpleName());
return loadSync(fileName, assetClass);
}
return assetManager.get(fileName);
}
Expand All @@ -84,7 +85,8 @@ public <T> T loadResourceSync(ResourceLocation location, Class<T> assetClass) {

public <T> T getResource(ResourceLocation location, Class<T> assetClass) {
if(!assetManager.isLoaded(location.toString())) {
LOGGER.error("Asset not loaded {} ({})", location, assetClass.getSimpleName());
LOGGER.error("Asset not loaded {} ({}) loading now", location, assetClass.getSimpleName());
return loadResourceSync(location, assetClass);
}
return assetManager.get(location.toString(), assetClass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public static List<ResourceLocation> getInternalFiles(String folder, String exte
return files;
}

public static FileHandle getModsFolder() {
return Gdx.files.absolute(SaveLocation.getSaveFolderLocation() + "/mods");
}

public static List<ResourceLocation> getVanillaModFiles(String folder, String extension) {
List<ResourceLocation> files = new ArrayList<>();
for(FileHandle f : Gdx.files.absolute(SaveLocation.getSaveFolderLocation() + "/mods/assets/" + folder).list()) {
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/dev/crmodders/flux/engine/GameLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class GameLoader extends GameState {
public static final Logger LOGGER = LoggerFactory.getLogger("FluxAPI / GameLoader");

private static final TranslationKey TEXT_RAM_USAGE = new TranslationKey("fluxapi:loading_menu.ram_usage");
private static final TranslationKey TEXT_TITLE = new TranslationKey("fluxapi:loading_menu.waiting_title");

public Stage gdxStage;
public OrthographicCamera gdxStageCamera;
Expand Down Expand Up @@ -179,13 +178,17 @@ public void create() {
}

@Override
public void render(float partTime) {
public void render() {
Runtime runtime = Runtime.getRuntime();
int ramValue = (int) ((runtime.totalMemory() - runtime.freeMemory()) / (1024 * 1024));
int ramRange = (int) (runtime.maxMemory() / (1024 * 1024));
ramUsageBar.setRange(0, ramRange);
ramUsageBar.setStepSize(1);
ramUsageBar.setValue(ramValue);
try {
ramUsageBar.setRange(0, ramRange);
ramUsageBar.setStepSize(1);
ramUsageBar.setValue(ramValue);
} catch (Exception e) {
LOGGER.warn("got ya you little bug", e);
}
LanguageManager.updateLabel(ramUsageText, (TranslationParameters) ramUsageText.getUserObject());

long endTime = System.currentTimeMillis() + 50;
Expand All @@ -200,10 +203,11 @@ public void render(float partTime) {
GameState.switchToGameState(new PrealphaPreamble());
}

super.render(partTime);
super.render();
Gdx.gl.glClearColor(background.r, background.g, background.b, background.a);
Gdx.gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
gdxStageViewport.apply(false);
gdxStage.act();
gdxStage.draw();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ public void registerFinalizers() {
/**
* This hooks the original block constants as those are not loaded statically
* anymore, this has to be called after all blocks from the vanilla game are loaded
* else it will try to load them here, crashing the game
*/
public void hookBlockManager() {
public void hookOriginalBlockConstants() {
BiConsumer<String, Block> setBlockStaticFinalField = (name, block) -> {
try {
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void initialize() {
if (this.textures != null) {
for (final BlockModelJsonTexture t : this.textures.values()) {
if (t.fileName != null) {
t.uv = ChunkShader.addToAllBlocksTexture(null, t);
t.uv = ChunkShader.addToAllBlocksTexture(t);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.crmodders.flux.engine.stages;

import dev.crmodders.flux.FluxRegistries;
import dev.crmodders.flux.FluxSettings;
import dev.crmodders.flux.assets.VanillaAssetLocations;
import dev.crmodders.flux.block.DataModBlock;
import dev.crmodders.flux.block.IModBlock;
Expand Down Expand Up @@ -38,9 +39,12 @@ public void onEvent(OnRegisterBlockEvent event) {
for(ResourceLocation internal : VanillaAssetLocations.getInternalFiles("blocks/", ".json")) {
blockNames.add(internal.name.replace("blocks/", "").replace(".json", ""));
}
for(ResourceLocation internal : VanillaAssetLocations.getVanillaModFiles("blocks/", ".json")) {
blockNames.add(internal.name.replace("blocks/", "").replace(".json", ""));
if(FluxSettings.EnabledVanillaMods.getValue()) {
for(ResourceLocation internal : VanillaAssetLocations.getVanillaModFiles("blocks/", ".json")) {
blockNames.add(internal.name.replace("blocks/", "").replace(".json", ""));
}
}

for(String blockName : blockNames) {
event.registerBlock(() -> new DataModBlock(blockName));
}
Expand Down Expand Up @@ -70,7 +74,7 @@ public void doStage() {
FluxRegistries.BLOCKS.freeze();

loader.blockLoader.registerFinalizers();
loader.blockLoader.hookBlockManager();
loader.blockLoader.hookOriginalBlockConstants();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AssetLoaderMixin {
@Shadow @Final public static HashMap<String, FileHandle> ALL_ASSETS;

/**
* @author written by replet, rewritten by Mr Zombii, edited by nanobass
* @author written by replet, rewritten by Mr Zombii, replaced by nanobass
* @reason Improves asset loading
**/
@Overwrite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
import dev.crmodders.flux.tags.Identifier;
import finalforeach.cosmicreach.GameAssetLoader;
import finalforeach.cosmicreach.rendering.blockmodels.BlockModelJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(BlockModelJson.class)
public class BlockModelJsonMixin {

private static final Logger LOGGER = LoggerFactory.getLogger("BlockModelJson");

@Redirect(method = "getInstance", at = @At(value = "INVOKE", target = "Lfinalforeach/cosmicreach/GameAssetLoader;loadAsset(Ljava/lang/String;)Lcom/badlogic/gdx/files/FileHandle;"))
private static FileHandle getModelFromModID(String fileName) {
LOGGER.warn("using broken BlockModelJson.getInstance, this could possible indicate a broken mod");
String noFolder = fileName.replace("models/blocks/","");
if (noFolder.contains(":")) {
Identifier id = Identifier.fromString(noFolder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ public class BlockGameMixin {
@Unique
private static final Logger logger = LoggerFactory.getLogger("CosmicReach / BlockGame");

@Redirect(method = "dispose", at = @At(value = "INVOKE", target = "Ljava/io/PrintStream;println(Ljava/lang/String;)V"))
@Redirect(method = "dispose", at = @At(value = "INVOKE", target = "Ljava/io/PrintStream;println(Ljava/lang/String;)V"), require = 0)
private void print1(PrintStream instance, String x) {
logger.info("\u001B[36m{}\u001B[37m", x);
}

@Redirect(method = "create", at = @At(value = "INVOKE", target = "Ljava/io/PrintStream;println(Ljava/lang/String;)V"))
@Redirect(method = "create", at = @At(value = "INVOKE", target = "Ljava/io/PrintStream;println(Ljava/lang/String;)V"), require = 0)
private void print2(PrintStream instance, String x) {
List<String> lines = x.lines().toList();
for(String line : lines) {
logger.info("\u001B[36m{}\u001B[37m", line);
}
}

@Inject(method = "dispose", at = @At(value = "INVOKE", target = "Ljava/lang/System;exit(I)V", shift = At.Shift.BEFORE))
@Inject(method = "dispose", at = @At(value = "INVOKE", target = "Ljava/lang/System;exit(I)V", shift = At.Shift.BEFORE), require = 0)
public void dispose(CallbackInfo ci) {
AssetManager manager = LOADER.getAssetManager();
manager.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public class GameShaderMixin {
@Unique
private static final Logger LOGGER = LoggerFactory.getLogger("CosmicReach / Shaders");

@Redirect(method = "reload", at = @At(value = "INVOKE", target = "Ljava/io/PrintStream;println(Ljava/lang/String;)V"))
@Redirect(method = "reload", at = @At(value = "INVOKE", target = "Ljava/io/PrintStream;println(Ljava/lang/String;)V"), require = 0)
private void print1(PrintStream instance, String x) {
if(!x.isBlank()) LOGGER.info(x);
}

@Redirect(method = "reloadAllShaders", at = @At(value = "INVOKE", target = "Ljava/io/PrintStream;println(Ljava/lang/String;)V"))
@Redirect(method = "reloadAllShaders", at = @At(value = "INVOKE", target = "Ljava/io/PrintStream;println(Ljava/lang/String;)V"), require = 0)
private static void print2(PrintStream instance, String x) {
LOGGER.info(x);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class GameStateMixin {
@Shadow public static GameState currentGameState;
@Unique private static final Logger LOGGER = LoggerFactory.getLogger("CosmicReach / GameState");

@Redirect(method = "switchToGameState", at = @At(value = "INVOKE", target = "Ljava/io/PrintStream;println(Ljava/lang/String;)V"))
@Redirect(method = "lambda$switchToGameState$0", at = @At(value = "INVOKE", target = "Ljava/io/PrintStream;println(Ljava/lang/String;)V"), require = 0)
private static void printCapture(PrintStream instance, String x, GameState gameState) {
if(currentGameState == null) {
LOGGER.info("Switched to GameState: \u001B[31m{}\u001B[37m", gameState.getClass().getSimpleName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
package dev.crmodders.flux.mixins.registry;

import finalforeach.cosmicreach.blocks.Block;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.asm.mixin.*;

import java.util.Map;

@Mixin(Block.class)
public class BlockRegisterer {

@Unique
private static final Logger LOGGER = LoggerFactory.getLogger("Block");

@Shadow @Final public static Map<String, Block> blocksByName;

@Shadow @Final public static Block AIR;

/**
* @author nanobass
* @reason is replaced by flux, allows for much more advanced features
* than data modding
*/
@Overwrite
public static Block getInstance(String blockName) {
return blocksByName.get(blockName);
Block block = blocksByName.get(blockName);
if(block == null && AIR != null) {
LOGGER.warn("null-block returned by Block.getInstance, please report", new Exception());
}
return block;
}

}

0 comments on commit abf50c5

Please sign in to comment.