Skip to content

Commit

Permalink
feat: use new dimension rendering api (#194)
Browse files Browse the repository at this point in the history
* feat: use new dimension rendering api

* fix: loading into worlds

* chore: remove debug mixin

* fix: sky angles
  • Loading branch information
marcus8448 committed Nov 6, 2021
1 parent e21c47d commit c683f64
Show file tree
Hide file tree
Showing 14 changed files with 372 additions and 310 deletions.
61 changes: 37 additions & 24 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ val gametestSourceSet = sourceSets.create("gametest") {

loom {
accessWidenerPath.set(project.file("src/main/resources/galacticraft.accesswidener"))
mixin {
add(sourceSets.main.get(), "galacticraft.refmap.json")
}
mixin.add(sourceSets.main.get(), "galacticraft.refmap.json")

runs {
register("gametest") {
Expand Down Expand Up @@ -138,25 +136,6 @@ repositories {
}
}

/**
* From:
* @see net.fabricmc.loom.configuration.FabricApiExtension.getDependencyNotation
*/
fun getFabricApiModule(moduleName: String): String {
return "net.fabricmc.fabric-api:${moduleName}:${fabricApi.moduleVersion(moduleName, fabricVersion)}"
}

fun DependencyHandler.optionalDependency(dependencyNotation: String, dependencyConfiguration: Action<ExternalModuleDependency>) {
modCompileOnly(dependencyNotation, dependencyConfiguration)
if (!net.fabricmc.loom.util.OperatingSystem.isCIBuild() && runtimeOptional) {
modRuntime(dependencyNotation, dependencyConfiguration)
}
}

fun DependencyHandler.includedDependency(dependencyNotation: String, dependencyConfiguration: Action<ExternalModuleDependency>) {
include(modApi(dependencyNotation, dependencyConfiguration), dependencyConfiguration)
}

dependencies {
// Minecraft, Mappings, Loader
minecraft("com.mojang:minecraft:$minecraftVersion")
Expand All @@ -172,6 +151,7 @@ dependencies {
"fabric-content-registries-v0",
"fabric-gametest-api-v1",
"fabric-item-groups-v0",
"fabric-mining-level-api-v1",
"fabric-models-v0",
"fabric-networking-blockentity-v0",
"fabric-networking-api-v1",
Expand Down Expand Up @@ -317,15 +297,32 @@ tasks.withType(JavaCompile::class) {
options.release.set(16)
}

tasks.getByName("gametestClasses").dependsOn("classes")
/**
* From:
* @see net.fabricmc.loom.configuration.FabricApiExtension.getDependencyNotation
*/
fun getFabricApiModule(moduleName: String): String {
return "net.fabricmc.fabric-api:${moduleName}:${fabricApi.moduleVersion(moduleName, fabricVersion)}"
}

fun DependencyHandler.optionalDependency(dependencyNotation: String, dependencyConfiguration: Action<ExternalModuleDependency>) {
modCompileOnly(dependencyNotation, dependencyConfiguration)
if (!net.fabricmc.loom.util.OperatingSystem.isCIBuild() && runtimeOptional) {
modRuntime(dependencyNotation, dependencyConfiguration)
}
}

fun DependencyHandler.includedDependency(dependencyNotation: String, dependencyConfiguration: Action<ExternalModuleDependency>) {
include(modApi(dependencyNotation, dependencyConfiguration), dependencyConfiguration)
}

// inspired by https://github.com/TerraformersMC/GradleScripts/blob/2.0/ferry.gradle
fun getVersionDecoration(): String {
if ((System.getenv("DISABLE_VERSION_DECORATION") ?: "false") == "true") return ""
if (project.hasProperty("release")) return ""

var version = "+build"
if ("git".exitValue() != 1) {
if (!"git".testForProcess()) {
version += ".unknown"
} else {
val branch = "git branch --show-current".execute()
Expand Down Expand Up @@ -358,6 +355,21 @@ fun String.execute(): String {
return String(output.toByteArray()).trim()
}

fun String.testForProcess(): Boolean {
return try {
rootProject.exec {
commandLine(split("\\s".toRegex()))
workingDir = rootProject.projectDir
isIgnoreExitValue = true
standardOutput = OutputStream.nullOutputStream()
errorOutput = OutputStream.nullOutputStream()
}
true;
} catch (ex: Exception) {
false;
}
}

fun String.exitValue(): Int {
return rootProject.exec {
commandLine(split("\\s".toRegex()))
Expand All @@ -368,5 +380,6 @@ fun String.exitValue(): Int {
}.exitValue
}

tasks.getByName("gametestClasses").dependsOn("classes")
gametestSourceSet.compileClasspath += sourceSets.main.get().compileClasspath + sourceSets.main.get().output
gametestSourceSet.runtimeClasspath += sourceSets.main.get().runtimeClasspath + sourceSets.main.get().output
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx4G

# Fabric Info
minecraft.version=1.17.1
yarn.build=61
yarn.build=63
loader.version=0.11.7

# Mod Info
Expand All @@ -12,15 +12,15 @@ mod.group=dev.galacticraft
mod.name=Galacticraft

# Dependencies
fabric.version=0.40.1+1.17
fabric.version=0.42.0+1.17
cloth.config.version=5.0.38
modmenu.version=2.0.11
lba.version=0.9.1-pre.1
modmenu.version=2.0.14
lba.version=0.9.2
energy.version=0.3.0
rei.version=6.0.279-alpha
rei.version=6.1.319
galacticraft.api.version=0.4.0-prealpha.19+1.17.1
myron.version=1.6.1-1.17.1
bannerpp.version=2.0.3+mc.1.17-rc1
wthit.version=3.9.0
wthit.version=3.10.1

optional_dependencies.enabled=true
17 changes: 14 additions & 3 deletions src/main/java/dev/galacticraft/mod/GalacticraftClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,35 @@
import dev.galacticraft.mod.client.gui.screen.ingame.*;
import dev.galacticraft.mod.client.model.*;
import dev.galacticraft.mod.client.network.GalacticraftClientPacketReceiver;
import dev.galacticraft.mod.client.render.MoonSkyProperties;
import dev.galacticraft.mod.client.render.block.entity.GalacticraftBlockEntityRenderer;
import dev.galacticraft.mod.client.render.dimension.EmptyCloudRenderer;
import dev.galacticraft.mod.client.render.dimension.EmptyWeatherRenderer;
import dev.galacticraft.mod.client.render.dimension.MoonDimensionEffects;
import dev.galacticraft.mod.client.render.dimension.MoonSkyRenderer;
import dev.galacticraft.mod.client.render.entity.*;
import dev.galacticraft.mod.client.render.entity.model.GalacticraftEntityModelLayer;
import dev.galacticraft.mod.client.resource.GalacticraftResourceReloadListener;
import dev.galacticraft.mod.entity.GalacticraftEntityType;
import dev.galacticraft.mod.misc.cape.CapesLoader;
import dev.galacticraft.mod.mixin.SkyPropertiesAccessor;
import dev.galacticraft.mod.particle.GalacticraftParticle;
import dev.galacticraft.mod.particle.fluid.DrippingCrudeOilParticle;
import dev.galacticraft.mod.particle.fluid.DrippingFuelParticle;
import dev.galacticraft.mod.screen.GalacticraftScreenHandlerType;
import dev.galacticraft.mod.world.dimension.GalacticraftDimension;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.DimensionRenderingRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry;
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.fluid.Fluids;
import net.minecraft.resource.ResourceType;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -164,7 +170,12 @@ public void onInitializeClient() {
return null;
});

SkyPropertiesAccessor.getBY_IDENTIFIER().put(new Identifier(Constant.MOD_ID, "moon"), new MoonSkyProperties());
DimensionRenderingRegistry.registerDimensionEffects(GalacticraftDimension.MOON.getValue(), MoonDimensionEffects.INSTANCE);
DimensionRenderingRegistry.registerCloudRenderer(GalacticraftDimension.MOON, EmptyCloudRenderer.INSTANCE);
DimensionRenderingRegistry.registerWeatherRenderer(GalacticraftDimension.MOON, EmptyWeatherRenderer.INSTANCE);
DimensionRenderingRegistry.registerSkyRenderer(GalacticraftDimension.MOON, MoonSkyRenderer.INSTANCE);

FluidRenderHandlerRegistry.INSTANCE.get(Fluids.WATER); // Workaround for classloading order bug

Galacticraft.LOGGER.info("Client initialization complete. (Took {}ms.)", System.currentTimeMillis() - startInitTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package dev.galacticraft.mod;

import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
Expand Down Expand Up @@ -59,7 +60,7 @@ public List<String> getMixins() {
if (FabricLoader.getInstance().isDevelopmentEnvironment()) {
optionalMixins.add(Constant.Mixin.STRUCTURE_POOL_DEBUG);
}
if (Galacticraft.CONFIG_MANAGER.get().areMoreMulticoloredStarsEnabled()) {
if (Galacticraft.CONFIG_MANAGER.get().areMoreMulticoloredStarsEnabled() && FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
optionalMixins.add(Constant.Mixin.OVERWORLD_SKY_OVERRIDE);
}
return optionalMixins;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2019-2021 Team Galacticraft
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package dev.galacticraft.mod.client.render.dimension;

import net.fabricmc.fabric.api.client.rendering.v1.DimensionRenderingRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;

public enum EmptyCloudRenderer implements DimensionRenderingRegistry.CloudRenderer {
INSTANCE;

@Override
public void render(WorldRenderContext context) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2019-2021 Team Galacticraft
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package dev.galacticraft.mod.client.render.dimension;

import net.fabricmc.fabric.api.client.rendering.v1.DimensionRenderingRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;

public enum EmptyWeatherRenderer implements DimensionRenderingRegistry.WeatherRenderer {
INSTANCE;

@Override
public void render(WorldRenderContext context) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@
* SOFTWARE.
*/

package dev.galacticraft.mod.client.render;
package dev.galacticraft.mod.client.render.dimension;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.render.SkyProperties;
import net.minecraft.client.render.DimensionEffects;
import net.minecraft.util.math.Vec3d;

/**
* @author <a href="https://github.com/TeamGalacticraft">TeamGalacticraft</a>
*/
@Environment(EnvType.CLIENT)
public class MoonSkyProperties extends SkyProperties {
public MoonSkyProperties() {
public class MoonDimensionEffects extends DimensionEffects {
private static final float[] FOG_COLOR = {0.0F, 0.0F, 0.0F, 0.0F};
public static final MoonDimensionEffects INSTANCE = new MoonDimensionEffects();

private MoonDimensionEffects() {
super(Float.NaN, false, SkyType.NORMAL, true, true);
}

Expand All @@ -48,6 +51,6 @@ public boolean useThickFog(int camX, int camY) {

@Override
public float[] getFogColorOverride(float skyAngle, float tickDelta) {
return new float[]{0.0F, 0.0F, 0.0F, 0.0F};
return FOG_COLOR;
}
}
Loading

0 comments on commit c683f64

Please sign in to comment.