Skip to content

Commit

Permalink
change: Remove conversion format
Browse files Browse the repository at this point in the history
  • Loading branch information
FlashyReese committed May 31, 2024
1 parent 5475635 commit 31cef1a
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 661 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/self-hosted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
distribution: 'temurin'
java-version: 21
check-latest: true
- name: Build adn Publish with Gradle
- name: Build and Publish with Gradle
run: ./gradlew build publishAllPublicationsToFlashyReeseSnapshotsRepository
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
Expand Down
484 changes: 65 additions & 419 deletions common/src/main/java/me/flashyreese/mods/nuit_interop/NuitInterop.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class NuitInteropConfig {
.create();

public static final NuitInteropConfig INSTANCE = NuitInteropConfig.load(Minecraft.getInstance().gameDirectory.toPath().resolve("config").resolve("nuit-interop.json").toFile());
public NuitInteropMode mode = NuitInteropMode.NATIVE;
public boolean interoperability = true;
public boolean debugMode = true;
public boolean preferNuitNative = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package me.flashyreese.mods.nuit_interop.config;

import me.flashyreese.mods.nuit_interop.NuitInterop;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
Expand All @@ -12,11 +10,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.Supplier;

Expand Down Expand Up @@ -44,85 +37,11 @@ protected void init() {
addRenderableWidget(createBooleanOptionButton(this.width / 2 - 100 - 110, this.height / 2 - 10 - 60, 420, 20, "interoperability", value -> config.interoperability = value, () -> config.interoperability, () -> {
Minecraft.getInstance().reloadResourcePacks();
}));
addRenderableWidget(createNuitInteropModeOptionButton(this.width / 2 - 100 - 110, this.height / 2 - 10 - 36, 420, 20, "mode", value -> config.mode = value, () -> config.mode, () -> {
if (config.interoperability) {
Minecraft.getInstance().reloadResourcePacks();
}
}));
addRenderableWidget(createBooleanOptionButton(this.width / 2 - 100 - 110, this.height / 2 - 10 - 12, 200, 20, "prefer_nuit_native", value -> config.preferNuitNative = value, () -> config.preferNuitNative, this::reloadResourcesIfInterop));
addRenderableWidget(createBooleanOptionButton(this.width / 2 - 100 + 110, this.height / 2 - 10 - 12, 200, 20, "debug_mode", value -> config.debugMode = value, () -> config.debugMode, () -> {
}));
addRenderableWidget(createBooleanOptionButton(this.width / 2 - 100 - 110, this.height / 2 - 10 + 12, 200, 20, "process_optifine", value -> config.processOptiFine = value, () -> config.processOptiFine, this::reloadResourcesIfInterop));
addRenderableWidget(createBooleanOptionButton(this.width / 2 - 100 + 110, this.height / 2 - 10 + 12, 200, 20, "process_mcpatcher", value -> config.processMCPatcher = value, () -> config.processMCPatcher, this::reloadResourcesIfInterop));
addRenderableWidget(Button
.builder(
Component.translatable(getTranslationKey("dump_data")),
button -> {
Path path = Minecraft.getInstance().gameDirectory.toPath().resolve("nuit-interop-dump");

try {
// Delete the directory and its contents recursively
if (Files.exists(path)) {
if (NuitInteropConfig.INSTANCE.debugMode) {
this.logger.info("Existing dump directory detected. Recursively deleting the contents...");
}
Files.walk(path)
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.filter(File::delete)
.forEach(file -> {
if (NuitInteropConfig.INSTANCE.debugMode) {
this.logger.info("Deleted: {}", file.getAbsolutePath());
}
});
}
} catch (IOException e) {
this.logger.error("Error while deleting existing dump directory: {}", e.getMessage());
}

try {
// Create the directory if it doesn't exist
if (!Files.exists(path)) {
Files.createDirectories(path);
if (NuitInteropConfig.INSTANCE.debugMode) {
this.logger.info("Dump directory created: {}", path.toAbsolutePath());
}
}

NuitInterop.getInstance()
.getConvertedSkyMap()
.forEach((identifier, json) -> {
String filename = identifier.toString();
// Fixme: Replace all characters that are not allowed in file names with underscores
filename = filename.replaceAll("[^a-zA-Z0-9-_\\.]", "_");

// Write the JSON data to a file
Path output = path.resolve(filename + ".json");
try {
Files.write(output, json.getBytes());
if (NuitInteropConfig.INSTANCE.debugMode) {
this.logger.info("Successfully dumped {} to {}", identifier, output.toAbsolutePath());
}
} catch (IOException e) {
this.logger.error("Error while dumping {} to {}: {}", identifier, output.toAbsolutePath(), e.getMessage());
e.printStackTrace();
}
});

if (NuitInteropConfig.INSTANCE.debugMode) {
this.logger.info("Opening dump directory: {}", path.toAbsolutePath());
}
Util.getPlatform().openUri(path.toUri());
} catch (IOException e) {
this.logger.error("Error while creating dump directory: {}", e.getMessage());
e.printStackTrace();
}
}
)
.bounds(this.width / 2 - 100 - 110, this.height / 2 - 10 + 36, 420, 20)
.tooltip(Tooltip.create(Component.translatable(getTooltipKey(getTranslationKey("dump_data")))))
.build()
);

addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, button -> onClose()).bounds(this.width / 2 - 100, this.height - 40, 200, 20).build());
}
Expand Down Expand Up @@ -161,20 +80,4 @@ private Button createBooleanOptionButton(int x, int y, int width, int height, St
onChange.run();
}).bounds(x, y, width, height).tooltip(Tooltip.create(tooltipText)).build();
}

private Button createNuitInteropModeOptionButton(int x, int y, int width, int height, String key, Consumer<NuitInteropMode> consumer, Supplier<NuitInteropMode> supplier, Runnable onChange) {
String translationKey = getTranslationKey(key);
Component text = Component.translatable(translationKey);
Component tooltipText = Component.translatable(getTooltipKey(translationKey));
return Button.builder(CommonComponents.optionNameValue(text, Component.translatable(getTranslationKey(supplier.get().getTranslationKey()))), button -> {
NuitInteropMode currentMode = supplier.get();
NuitInteropMode[] modes = NuitInteropMode.values();
int currentIndex = currentMode.ordinal();
int nextIndex = (currentIndex + 1) % modes.length; // Wrap around to the beginning if reached the end
NuitInteropMode newValue = modes[nextIndex];
button.setMessage(CommonComponents.optionNameValue(text, Component.translatable(getTranslationKey(newValue.getTranslationKey()))));
consumer.accept(newValue);
onChange.run();
}).bounds(x, y, width, height).tooltip(Tooltip.create(tooltipText)).build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.google.common.collect.Lists;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.amerebagatelle.mods.nuit.skybox.MinMaxEntry;
import io.github.amerebagatelle.mods.nuit.components.MinMaxEntry;
import io.github.amerebagatelle.mods.nuit.util.CodecUtils;

import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public enum OptiFineBlend {
this.blendFunc = blendFunc;
}

public static OptiFineBlend fromString(String name) {
return Objects.requireNonNull(VALUES.get(name));
}

public String getName() {
return name;
}
Expand All @@ -82,10 +86,6 @@ public Consumer<Float> getBlendFunc() {
return blendFunc;
}

public static OptiFineBlend fromString(String name) {
return Objects.requireNonNull(VALUES.get(name));
}

@Override
public String toString() {
return this.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public void renderSky(LevelRendererAccessor worldRendererAccess, PoseStack matri
this.renderEndSky(matrices);
} else if (this.client.level.effects().skyType() == DimensionSpecialEffects.SkyType.NORMAL) {
Vec3 vec3d = this.world.getSkyColor(this.client.gameRenderer.getMainCamera().getPosition(), tickDelta);
float f = (float)vec3d.x;
float g = (float)vec3d.y;
float h = (float)vec3d.z;
float f = (float) vec3d.x;
float g = (float) vec3d.y;
float h = (float) vec3d.z;
FogRenderer.levelFogColor();
BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder();
RenderSystem.depthMask(false);
Expand All @@ -130,8 +130,8 @@ public void renderSky(LevelRendererAccessor worldRendererAccess, PoseStack matri
bufferBuilder.vertex(matrix4f, 0.0F, 100.0F, 0.0F).color(j, k, l, fs[3]).endVertex();
int m = 16;

for(int n = 0; n <= 16; ++n) {
float o = (float)n * (float) (Math.PI * 2) / 16.0F;
for (int n = 0; n <= 16; ++n) {
float o = (float) n * (float) (Math.PI * 2) / 16.0F;
float p = Mth.sin(o);
float q = Mth.cos(o);
bufferBuilder.vertex(matrix4f, p * 120.0F, q * 120.0F, -q * 40.0F * fs[3]).color(fs[0], fs[1], fs[2], 0.0F).endVertex();
Expand Down Expand Up @@ -165,10 +165,10 @@ public void renderSky(LevelRendererAccessor worldRendererAccess, PoseStack matri
int r = this.world.getMoonPhase();
int s = r % 4;
int m = r / 4 % 2;
float t = (float)(s + 0) / 4.0F;
float o = (float)(m + 0) / 2.0F;
float p = (float)(s + 1) / 4.0F;
float q = (float)(m + 1) / 2.0F;
float t = (float) (s + 0) / 4.0F;
float o = (float) (m + 0) / 2.0F;
float p = (float) (s + 1) / 4.0F;
float q = (float) (m + 1) / 2.0F;
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
bufferBuilder.vertex(matrix4f2, -k, -100.0F, k).uv(p, q).endVertex();
bufferBuilder.vertex(matrix4f2, k, -100.0F, k).uv(t, q).endVertex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.amerebagatelle.mods.nuit.skybox.MinMaxEntry;
import io.github.amerebagatelle.mods.nuit.skybox.Weather;
import io.github.amerebagatelle.mods.nuit.components.Condition;
import io.github.amerebagatelle.mods.nuit.components.MinMaxEntry;
import io.github.amerebagatelle.mods.nuit.components.Weather;
import io.github.amerebagatelle.mods.nuit.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
Expand Down Expand Up @@ -38,8 +39,7 @@ public class OptiFineSkyLayer {

public static final Codec<OptiFineSkyLayer> CODEC = RecordCodecBuilder.create(instance -> instance.group(
ResourceLocation.CODEC.fieldOf("source").forGetter(OptiFineSkyLayer::getSource),
Codec.BOOL.optionalFieldOf("biomeInclusion", true).forGetter(OptiFineSkyLayer::isBiomeInclusion),
ResourceLocation.CODEC.listOf().optionalFieldOf("biomes", ImmutableList.of()).forGetter(OptiFineSkyLayer::getBiomes),
Condition.create(ResourceLocation.CODEC).optionalFieldOf("biomes", Condition.of()).forGetter(OptiFineSkyLayer::getBiomes),
MinMaxEntry.CODEC.listOf().optionalFieldOf("heights", ImmutableList.of()).forGetter(OptiFineSkyLayer::getHeights),
OptiFineBlend.CODEC.optionalFieldOf("blend", OptiFineBlend.ADD).forGetter(OptiFineSkyLayer::getBlend),
LegacyFade.CODEC.optionalFieldOf("fade", OPTIFINE_FADE).forGetter(OptiFineSkyLayer::getFade),
Expand All @@ -52,8 +52,7 @@ public class OptiFineSkyLayer {
).apply(instance, OptiFineSkyLayer::new));

private final ResourceLocation source;
private final boolean biomeInclusion;
private final List<ResourceLocation> biomes;
private final Condition<ResourceLocation> biomes;
private final List<MinMaxEntry> heights;
private final OptiFineBlend blend;
private final LegacyFade fade;
Expand All @@ -65,9 +64,8 @@ public class OptiFineSkyLayer {
private final List<Weather> weathers;
public float conditionAlpha = -1;

public OptiFineSkyLayer(ResourceLocation source, boolean biomeInclusion, List<ResourceLocation> biomes, List<MinMaxEntry> heights, OptiFineBlend blend, LegacyFade fade, boolean rotate, float speed, Vector3f axis, Loop loop, float transition, List<Weather> weathers) {
public OptiFineSkyLayer(ResourceLocation source, Condition<ResourceLocation> biomes, List<MinMaxEntry> heights, OptiFineBlend blend, LegacyFade fade, boolean rotate, float speed, Vector3f axis, Loop loop, float transition, List<Weather> weathers) {
this.source = source;
this.biomeInclusion = biomeInclusion;
this.biomes = biomes;
this.heights = heights;
this.blend = blend;
Expand Down Expand Up @@ -166,23 +164,19 @@ private boolean getConditionCheck(Level world) {

BlockPos entityPos = cameraEntity.blockPosition();

if (!this.biomes.isEmpty()) {
if (!this.biomes.getEntries().isEmpty()) {
Biome currentBiome = world.getBiome(entityPos).value();

if (currentBiome == null) {
return false;
}

if (!(this.biomeInclusion && this.biomes.contains(world.registryAccess().registryOrThrow(Registries.BIOME).getKey(currentBiome)))) {
if (this.biomes.isExcludes() == this.biomes.getEntries().contains(world.registryAccess().registryOrThrow(Registries.BIOME).getKey(currentBiome))) {
return false;
}
}

return this.heights == null || Utils.checkRanges(entityPos.getY(), this.heights);
return this.heights == null || Utils.checkRanges(entityPos.getY(), this.heights, false);
}

private float getPositionBrightness(Level world) {
if (this.biomes.isEmpty() && this.heights.isEmpty()) {
if (this.biomes.getEntries().isEmpty() && this.heights.isEmpty()) {
return 1.0F;
}

Expand Down Expand Up @@ -236,7 +230,7 @@ public boolean isActive(int timeOfDay) {
int daysPassed = (int) (adjustedTime / 24000L);
int currentDay = daysPassed % (int) this.loop.getDays();

return Utils.checkRanges(currentDay, this.loop.getRanges());
return Utils.checkRanges(currentDay, this.loop.getRanges(), false);
}

return true;
Expand All @@ -247,11 +241,7 @@ public ResourceLocation getSource() {
return source;
}

public boolean isBiomeInclusion() {
return biomeInclusion;
}

public List<ResourceLocation> getBiomes() {
public Condition<ResourceLocation> getBiomes() {
return biomes;
}

Expand Down
Loading

0 comments on commit 31cef1a

Please sign in to comment.