diff --git a/.editorconfig b/.editorconfig index 6ddef3d3c..f37b585c9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -19,4 +19,4 @@ indent_style = tab ij_continuation_indent_size = 8 ij_java_class_count_to_use_import_on_demand = 99 ij_java_names_count_to_use_import_on_demand = 99 -ij_java_imports_layout = $*,|,java.**,|,javax.**,|,org.**,|,com.**,|,* +ij_java_imports_layout = $*, |, java.**, |, javax.**, |, org.**, |, com.**, |, * diff --git a/LICENCE.md b/LICENCE.md index e18c0483d..34859d7dd 100644 --- a/LICENCE.md +++ b/LICENCE.md @@ -2,99 +2,75 @@ Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. -Everyone is permitted to copy and distribute verbatim copies -of this license document, but changing it is not allowed. +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - -This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. +This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU +General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. -As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. +As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to +version 3 of the GNU General Public License. -"The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. +"The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined +below. -An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. +An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on +the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by +the Library. -A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". +A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of +the Library with which the Combined Work was made is also called the "Linked Version". -The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. +The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding +any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not +on the Linked Version. -The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. +The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, +including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the +System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. -You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. +You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. -If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: +If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied +by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may +convey a copy of the modified version: -a) under this License, provided that you make a good faith effort to -ensure that, in the event an Application does not supply the -function or data, the facility still operates, and performs -whatever part of its purpose remains meaningful, or +a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not +supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, +or -b) under the GNU GPL, with none of the additional permissions of -this License applicable to that copy. +b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. -The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates +The object code form of an Application may incorporate material from a header file that is part of the Library. You may +convey such object code under terms of your choice, provided that, if the incorporated material is not limited to +numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: -a) Give prominent notice with each copy of the object code that the -Library is used in it and that the Library and its use are -covered by this License. +a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its +use are covered by this License. -b) Accompany the object code with a copy of the GNU GPL and this license -document. +b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. -You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: +You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification +of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, +if you also do each of the following: -a) Give prominent notice with each copy of the Combined Work that -the Library is used in it and that the Library and its use are -covered by this License. +a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its +use are covered by this License. -b) Accompany the Combined Work with a copy of the GNU GPL and this license -document. +b) Accompany the Combined Work with a copy of the GNU GPL and this license document. -c) For a Combined Work that displays copyright notices during -execution, include the copyright notice for the Library among -these notices, as well as a reference directing the user to the -copies of the GNU GPL and this license document. +c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library +among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: @@ -113,53 +89,38 @@ d) Do one of the following: of the Library that is interface-compatible with the Linked Version. -e) Provide Installation Information, but only if you would otherwise -be required to provide such information under section 6 of the -GNU GPL, and only to the extent that such information is -necessary to install and execute a modified version of the -Combined Work produced by recombining or relinking the -Application with a modified version of the Linked Version. (If -you use option 4d0, the Installation Information must accompany -the Minimal Corresponding Source and Corresponding Application -Code. If you use option 4d1, you must provide the Installation -Information in the manner specified by section 6 of the GNU GPL -for conveying Corresponding Source.) +e) Provide Installation Information, but only if you would otherwise be required to provide such information under +section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified +version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked +Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and +Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner +specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. -You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: +You may place library facilities that are a work based on the Library side by side in a single library together with +other library facilities that are not Applications and are not covered by this License, and convey such a combined +library under terms of your choice, if you do both of the following: -a) Accompany the combined library with a copy of the same work based -on the Library, uncombined with any other library facilities, -conveyed under the terms of this License. +a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library +facilities, conveyed under the terms of this License. -b) Give prominent notice with the combined library that part of it -is a work based on the Library, and explaining where to find the -accompanying uncombined form of the same work. +b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where +to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. -The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. +The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time +to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new +problems or concerns. -Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. +Each version is given a distinguishing version number. If the Library as you received it specifies that a certain +numbered version of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and conditions either of that published version or of any +later version published by the Free Software Foundation. If the Library as you received it does not specify a version +number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License +ever published by the Free Software Foundation. -If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. +If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General +Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for +you to choose that version for the Library. diff --git a/README.md b/README.md index f741e6ba8..2cba2395b 100644 --- a/README.md +++ b/README.md @@ -9,28 +9,34 @@ ### About -The goal of this project is to provide tools for mod developers so they no longer have to worry about performance, or limitations of Minecraft's archaic rendering engine. -That said, this is primarily an outlet for me to have fun with graphics programming. +The goal of this project is to provide tools for mod developers so they no longer have to worry about performance, or +limitations of Minecraft's archaic rendering engine. That said, this is primarily an outlet for me to have fun with +graphics programming. ### Instancing -Flywheel provides an alternate, unified path for entity and tile entity rendering that takes advantage of GPU instancing. In doing so, Flywheel gives the developer the flexibility to define their own vertex and instance formats, and write custom shaders to ingest that data. +Flywheel provides an alternate, unified path for entity and tile entity rendering that takes advantage of GPU +instancing. In doing so, Flywheel gives the developer the flexibility to define their own vertex and instance formats, +and write custom shaders to ingest that data. ### Shaders -To accomodate the developer and leave more in the hands of the engine, Flywheel provides a custom shader loading and templating system to hide the details of the CPU/GPU interface. This system is a work in progress. There will be breaking changes, and I make no guarantees of backwards compatibility. +To accomodate the developer and leave more in the hands of the engine, Flywheel provides a custom shader loading and +templating system to hide the details of the CPU/GPU interface. This system is a work in progress. There will be +breaking changes, and I make no guarantees of backwards compatibility. ### Plans - - Vanilla performance improvements - - Compute shader particles - - Deferred rendering - - Different renderers for differently aged hardware +- Vanilla performance improvements +- Compute shader particles +- Deferred rendering +- Different renderers for differently aged hardware ### Getting Started (For Developers) Add the following repo to your `build.gradle`: + ```groovy repositories { maven { @@ -41,6 +47,7 @@ repositories { ``` Then add Flywheel as a dependency: + ```groovy dependencies { implementation fg.deobf("com.jozufozu.flywheel:Flywheel:1.16-0.0.2.9") diff --git a/build.gradle b/build.gradle index 743d79717..5d6daea06 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { maven { url = 'https://files.minecraftforge.net/maven' } jcenter() mavenCentral() - maven { url='https://repo.spongepowered.org/repository/maven-public/' } + maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } } dependencies { classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true @@ -11,7 +11,6 @@ buildscript { } } plugins { - id 'com.github.johnrengelman.shadow' version '5.2.0' id 'com.matthewprenger.cursegradle' version '1.4.0' } @@ -89,9 +88,6 @@ mixin { add sourceSets.main, "flywheel.refmap.json" } -// Include resources generated by data generators. -sourceSets.main.resources { srcDir 'src/generated/resources' } - repositories { maven { name "tterrag maven" diff --git a/gradle.properties b/gradle.properties index a65902625..b104f63f3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,18 +5,10 @@ org.gradle.daemon=false mod_version=0.0.3 mc_update_version=1.16 minecraft_version=1.16.5 + forge_version=36.0.42 mcp_mappings=20200920-mixed-1.16.3 -# dependency versions -registrate_version=1.0.4 -jei_version=7.6.1.71 - -# curseforge information -# projectId=486392 -# curse_type=beta - -# github information projectId=486392 curse_type=beta github_project=Jozufozu/Flywheel diff --git a/src/main/java/com/jozufozu/flywheel/Flywheel.java b/src/main/java/com/jozufozu/flywheel/Flywheel.java index 3832e458f..6dbfa058e 100644 --- a/src/main/java/com/jozufozu/flywheel/Flywheel.java +++ b/src/main/java/com/jozufozu/flywheel/Flywheel.java @@ -1,34 +1,35 @@ package com.jozufozu.flywheel; -import com.jozufozu.flywheel.config.FlwConfig; -import com.jozufozu.flywheel.config.FlwCommands; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import com.jozufozu.flywheel.config.FlwCommands; +import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.config.FlwPackets; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; @Mod("flywheel") public class Flywheel { - public static final String ID = "flywheel"; - private static final Logger LOGGER = LogManager.getLogger(); + public static final String ID = "flywheel"; + private static final Logger LOGGER = LogManager.getLogger(); - public Flywheel() { - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); + public Flywheel() { + FMLJavaModLoadingContext.get() + .getModEventBus() + .addListener(this::setup); MinecraftForge.EVENT_BUS.addListener(FlwCommands::onServerStarting); FlwConfig.init(); - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> Client::clientInit); + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> FlywheelClient::clientInit); } private void setup(final FMLCommonSetupEvent event) { diff --git a/src/main/java/com/jozufozu/flywheel/Client.java b/src/main/java/com/jozufozu/flywheel/FlywheelClient.java similarity index 83% rename from src/main/java/com/jozufozu/flywheel/Client.java rename to src/main/java/com/jozufozu/flywheel/FlywheelClient.java index bf0618b6c..068f6ea31 100644 --- a/src/main/java/com/jozufozu/flywheel/Client.java +++ b/src/main/java/com/jozufozu/flywheel/FlywheelClient.java @@ -2,20 +2,19 @@ package com.jozufozu.flywheel; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.core.AtlasStitcher; - import com.jozufozu.flywheel.core.Contexts; - import com.jozufozu.flywheel.core.Materials; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -public class Client { +public class FlywheelClient { public static void clientInit() { Backend.init(); - IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); + IEventBus modEventBus = FMLJavaModLoadingContext.get() + .getModEventBus(); modEventBus.addListener(AtlasStitcher.getInstance()::onTextureStitch); diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index d92636604..8c5da8088 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -6,7 +6,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.jozufozu.flywheel.config.FlwConfig; +import javax.annotation.Nullable; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -16,6 +16,7 @@ import org.lwjgl.opengl.GLCapabilities; import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.instancing.MaterialSpec; +import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; import net.minecraft.client.Minecraft; @@ -24,8 +25,6 @@ import net.minecraft.util.math.vector.Matrix4f; import net.minecraft.world.IWorld; import net.minecraft.world.World; -import javax.annotation.Nullable; - public class Backend { public static final Logger log = LogManager.getLogger(Backend.class); @@ -111,7 +110,9 @@ public class Backend { } materialRegistry.put(name, spec); - log.debug("registered material '" + name + "' with vertex size " + spec.getModelFormat().getStride() + " and instance size " + spec.getInstanceFormat().getStride()); + log.debug("registered material '" + name + "' with vertex size " + spec.getModelFormat() + .getStride() + " and instance size " + spec.getInstanceFormat() + .getStride()); return spec; } @@ -146,11 +147,10 @@ public class Backend { compat = new GlCompat(capabilities); - instancedArrays = compat.vertexArrayObjectsSupported() && - compat.drawInstancedSupported() && - compat.instancedArraysSupported(); + instancedArrays = compat.vertexArrayObjectsSupported() && compat.drawInstancedSupported() && compat.instancedArraysSupported(); - enabled = FlwConfig.get().enabled() && !OptifineHandler.usingShaders(); + enabled = FlwConfig.get() + .enabled() && !OptifineHandler.usingShaders(); } public boolean canUseInstancing(World world) { @@ -181,11 +181,9 @@ public class Backend { * Used to avoid calling Flywheel functions on (fake) worlds that don't specifically support it. */ public static boolean isFlywheelWorld(@Nullable IWorld world) { - if (world == null) - return false; + if (world == null) return false; - if (world instanceof IFlywheelWorld && ((IFlywheelWorld) world).supportsFlywheel()) - return true; + if (world instanceof IFlywheelWorld && ((IFlywheelWorld) world).supportsFlywheel()) return true; return world == Minecraft.getInstance().world; } @@ -198,5 +196,6 @@ public class Backend { RenderWork.enqueue(Minecraft.getInstance().worldRenderer::loadRenderers); } - public static void init() { } + public static void init() { + } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/IShaderContext.java b/src/main/java/com/jozufozu/flywheel/backend/IShaderContext.java index 733ed5739..181e40e84 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/IShaderContext.java +++ b/src/main/java/com/jozufozu/flywheel/backend/IShaderContext.java @@ -9,7 +9,8 @@ import net.minecraft.util.ResourceLocation; public interface IShaderContext

{ default P getProgram(ResourceLocation loc) { - return this.getProgramSupplier(loc).get(); + return this.getProgramSupplier(loc) + .get(); } Supplier

getProgramSupplier(ResourceLocation loc); diff --git a/src/main/java/com/jozufozu/flywheel/backend/OptifineHandler.java b/src/main/java/com/jozufozu/flywheel/backend/OptifineHandler.java index c4d825c90..50f4c1ba6 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/OptifineHandler.java +++ b/src/main/java/com/jozufozu/flywheel/backend/OptifineHandler.java @@ -45,7 +45,8 @@ public class OptifineHandler { if (optifine == null) { Backend.log.info("Optifine not detected."); - } else { + } + else { Backend.log.info("Optifine detected."); refresh(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/RenderWork.java b/src/main/java/com/jozufozu/flywheel/backend/RenderWork.java index 37b72652f..b73eef7f1 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/RenderWork.java +++ b/src/main/java/com/jozufozu/flywheel/backend/RenderWork.java @@ -17,7 +17,8 @@ public class RenderWork { @SubscribeEvent(priority = EventPriority.LOWEST) public static void onRenderWorldLast(RenderWorldLastEvent event) { while (!runs.isEmpty()) { - runs.remove().run(); + runs.remove() + .run(); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/ResourceUtil.java b/src/main/java/com/jozufozu/flywheel/backend/ResourceUtil.java index a8294d3d1..874e429b4 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/ResourceUtil.java +++ b/src/main/java/com/jozufozu/flywheel/backend/ResourceUtil.java @@ -9,7 +9,8 @@ public class ResourceUtil { } public static ResourceLocation removePrefixUnchecked(ResourceLocation full, String root) { - return new ResourceLocation(full.getNamespace(), full.getPath().substring(root.length())); + return new ResourceLocation(full.getNamespace(), full.getPath() + .substring(root.length())); } public static ResourceLocation trim(ResourceLocation loc, String prefix, String suffix) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java b/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java index 086169c72..4f8595c64 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java +++ b/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java @@ -57,7 +57,8 @@ public abstract class ShaderContext

implements IShaderConte @Override public void delete() { - programs.values().forEach(IMultiProgram::delete); + programs.values() + .forEach(IMultiProgram::delete); programs.clear(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/ShaderSources.java b/src/main/java/com/jozufozu/flywheel/backend/ShaderSources.java index d4af509c9..6f99c2590 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/ShaderSources.java +++ b/src/main/java/com/jozufozu/flywheel/backend/ShaderSources.java @@ -19,15 +19,6 @@ import java.util.stream.Stream; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; -import com.jozufozu.flywheel.event.ForgeEvents; - -import net.minecraft.client.Minecraft; - -import net.minecraft.client.world.ClientWorld; - -import net.minecraftforge.event.world.WorldEvent; - import org.lwjgl.system.MemoryUtil; import com.google.common.collect.Lists; @@ -35,6 +26,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.jozufozu.flywheel.backend.gl.shader.ShaderType; +import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.jozufozu.flywheel.backend.loading.Shader; import com.jozufozu.flywheel.backend.loading.ShaderLoadingException; import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; @@ -44,6 +36,8 @@ import com.mojang.datafixers.util.Pair; import com.mojang.serialization.DataResult; import com.mojang.serialization.JsonOps; +import net.minecraft.client.Minecraft; +import net.minecraft.client.world.ClientWorld; import net.minecraft.resources.IReloadableResourceManager; import net.minecraft.resources.IResource; import net.minecraft.resources.IResourceManager; @@ -84,7 +78,8 @@ public class ShaderSources implements ISelectiveResourceReloadListener { shouldCrash = false; backend.clearContexts(); - ModLoader.get().postEvent(new GatherContextEvent(backend)); + ModLoader.get() + .postEvent(new GatherContextEvent(backend)); loadProgramSpecs(manager); loadShaderSources(manager); @@ -123,7 +118,9 @@ public class ShaderSources implements ISelectiveResourceReloadListener { DataResult> result = ProgramSpec.CODEC.decode(JsonOps.INSTANCE, GSON.fromJson(s, JsonElement.class)); - ProgramSpec spec = result.get().orThrow().getFirst(); + ProgramSpec spec = result.get() + .orThrow() + .getFirst(); spec.setName(specName); @@ -210,7 +207,8 @@ public class ShaderSources implements ISelectiveResourceReloadListener { while (filechannel.read(bytebuffer) != -1) { } - } else { + } + else { bytebuffer = MemoryUtil.memAlloc(8192); ReadableByteChannel readablebytechannel = Channels.newChannel(is); diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/GlNumericType.java b/src/main/java/com/jozufozu/flywheel/backend/gl/GlNumericType.java index 29baffd7f..8679a376d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/GlNumericType.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/GlNumericType.java @@ -53,9 +53,11 @@ public enum GlNumericType { public void castAndBuffer(ByteBuffer buf, int val) { if (this == UBYTE || this == BYTE) { buf.put((byte) val); - } else if (this == USHORT || this == SHORT) { + } + else if (this == USHORT || this == SHORT) { buf.putShort((short) val); - } else if (this == UINT || this == INT) { + } + else if (this == UINT || this == INT) { buf.putInt(val); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBuffer.java index d52804652..a9bca56ef 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBuffer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/GlBuffer.java @@ -56,7 +56,8 @@ public class GlBuffer extends GlObject { public MappedBuffer getBuffer(int offset, int length) { if (Backend.getInstance().compat.mapBufferRange != MapBufferRange.UNSUPPORTED) { return new MappedBufferRange(this, offset, length, GL30.GL_MAP_WRITE_BIT); - } else { + } + else { MappedFullBuffer fullBuffer = new MappedFullBuffer(this, MappedBufferUsage.WRITE_ONLY); fullBuffer.position(offset); return fullBuffer; diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java index 03540e7fb..5291cb324 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/buffer/VecBuffer.java @@ -39,8 +39,8 @@ public class VecBuffer { for (float f : floats) { internal.putFloat(f); } -// internal.asFloatBuffer().put(floats); -// internal.position(internal.position() + floats.length * 4); + // internal.asFloatBuffer().put(floats); + // internal.position(internal.position() + floats.length * 4); return this; } diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/GlCompat.java b/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/GlCompat.java index 438fbb734..aaebb3625 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/GlCompat.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/versioned/GlCompat.java @@ -79,7 +79,10 @@ public class GlCompat { throw new IllegalStateException(""); } - return Arrays.stream(constants).filter(it -> it.supported(caps)).findFirst().get(); + return Arrays.stream(constants) + .filter(it -> it.supported(caps)) + .findFirst() + .get(); } /** diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java index 5f42395ff..2aa92094d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java @@ -61,8 +61,7 @@ public abstract class InstanceManager implements MaterialManager.OriginShiftL int dY = pos.getY() - cY; int dZ = pos.getZ() - cZ; - if ((tick % getUpdateDivisor(dX, dY, dZ)) == 0) - instance.tick(); + if ((tick % getUpdateDivisor(dX, dY, dZ)) == 0) instance.tick(); } } @@ -88,16 +87,18 @@ public abstract class InstanceManager implements MaterialManager.OriginShiftL int cZ = (int) info.getProjectedView().z; if (dynamicInstances.size() > 0) { - dynamicInstances.object2ObjectEntrySet().fastForEach(e -> { - IDynamicInstance dyn = e.getValue(); - if (!dyn.decreaseFramerateWithDistance() || shouldFrameUpdate(dyn.getWorldPosition(), lookX, lookY, lookZ, cX, cY, cZ)) - dyn.beginFrame(); - }); + dynamicInstances.object2ObjectEntrySet() + .fastForEach(e -> { + IDynamicInstance dyn = e.getValue(); + if (!dyn.decreaseFramerateWithDistance() || shouldFrameUpdate(dyn.getWorldPosition(), lookX, lookY, lookZ, cX, cY, cZ)) + dyn.beginFrame(); + }); } } public void add(T obj) { - if (!Backend.getInstance().canUseInstancing()) return; + if (!Backend.getInstance() + .canUseInstancing()) return; if (obj instanceof IInstanceRendered) { addInternal(obj); @@ -105,13 +106,15 @@ public abstract class InstanceManager implements MaterialManager.OriginShiftL } public synchronized void queueAdd(T obj) { - if (!Backend.getInstance().canUseInstancing()) return; + if (!Backend.getInstance() + .canUseInstancing()) return; queuedAdditions.add(obj); } public void update(T obj) { - if (!Backend.getInstance().canUseInstancing()) return; + if (!Backend.getInstance() + .canUseInstancing()) return; if (obj instanceof IInstanceRendered) { IInstance instance = getInstance(obj, false); @@ -122,7 +125,8 @@ public abstract class InstanceManager implements MaterialManager.OriginShiftL removeInternal(obj, instance); createInternal(obj); - } else { + } + else { instance.update(); } } @@ -130,29 +134,30 @@ public abstract class InstanceManager implements MaterialManager.OriginShiftL } public synchronized void queueUpdate(T obj) { - if (!Backend.getInstance().canUseInstancing()) return; + if (!Backend.getInstance() + .canUseInstancing()) return; queuedUpdates.add(obj); } public void onLightUpdate(T obj) { - if (!Backend.getInstance().canUseInstancing()) return; + if (!Backend.getInstance() + .canUseInstancing()) return; if (obj instanceof IInstanceRendered) { IInstance instance = getInstance(obj, false); - if (instance != null) - instance.updateLight(); + if (instance != null) instance.updateLight(); } } public void remove(T obj) { - if (!Backend.getInstance().canUseInstancing()) return; + if (!Backend.getInstance() + .canUseInstancing()) return; if (obj instanceof IInstanceRendered) { IInstance instance = getInstance(obj, false); - if (instance != null) - removeInternal(obj, instance); + if (instance != null) removeInternal(obj, instance); } } @@ -165,15 +170,18 @@ public abstract class InstanceManager implements MaterialManager.OriginShiftL @SuppressWarnings("unchecked") @Nullable protected IInstance getInstance(I obj, boolean create) { - if (!Backend.getInstance().canUseInstancing()) return null; + if (!Backend.getInstance() + .canUseInstancing()) return null; IInstance instance = instances.get(obj); if (instance != null) { return instance; - } else if (create && canCreateInstance(obj)) { + } + else if (create && canCreateInstance(obj)) { return createInternal(obj); - } else { + } + else { return null; } } @@ -222,11 +230,9 @@ public abstract class InstanceManager implements MaterialManager.OriginShiftL renderer.updateLight(); instances.put(obj, renderer); - if (renderer instanceof IDynamicInstance) - dynamicInstances.put(obj, (IDynamicInstance) renderer); + if (renderer instanceof IDynamicInstance) dynamicInstances.put(obj, (IDynamicInstance) renderer); - if (renderer instanceof ITickableInstance) - tickableInstances.put(obj, ((ITickableInstance) renderer)); + if (renderer instanceof ITickableInstance) tickableInstances.put(obj, ((ITickableInstance) renderer)); } return renderer; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceMaterial.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceMaterial.java index 6f1a1a63e..608af6c89 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceMaterial.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceMaterial.java @@ -55,7 +55,10 @@ public class InstanceMaterial { } public boolean nothingToRender() { - return models.size() > 0 && models.asMap().values().stream().allMatch(Instancer::empty); + return models.size() > 0 && models.asMap() + .values() + .stream() + .allMatch(Instancer::empty); } public void delete() { @@ -66,11 +69,14 @@ public class InstanceMaterial { * Clear all instance data without freeing resources. */ public void clear() { - models.asMap().values().forEach(Instancer::clear); + models.asMap() + .values() + .forEach(Instancer::clear); } public void forEachInstancer(Consumer> f) { - for (Instancer model : models.asMap().values()) { + for (Instancer model : models.asMap() + .values()) { f.accept(model); } } @@ -84,8 +90,7 @@ public class InstanceMaterial { } public Instancer getModel(PartialModel partial, BlockState referenceState, Direction dir, Supplier modelTransform) { - return get(Pair.of(dir, partial), - () -> buildModel(partial.get(), referenceState, modelTransform.get())); + return get(Pair.of(dir, partial), () -> buildModel(partial.get(), referenceState, modelTransform.get())); } public Instancer getModel(BlockState toRender) { @@ -102,7 +107,8 @@ public class InstanceMaterial { } private BufferedModel buildModel(BlockState renderedState) { - BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher(); + BlockRendererDispatcher dispatcher = Minecraft.getInstance() + .getBlockRendererDispatcher(); return buildModel(dispatcher.getModelForState(renderedState), renderedState); } @@ -153,16 +159,15 @@ public class InstanceMaterial { BlockModelRenderer blockRenderer = dispatcher.getBlockModelRenderer(); BufferBuilder builder = new BufferBuilder(512); -// BakedQuadWrapper quadReader = new BakedQuadWrapper(); -// -// IModelData modelData = model.getModelData(mc.world, BlockPos.ZERO.up(255), referenceState, VirtualEmptyModelData.INSTANCE); -// List quads = Arrays.stream(dirs) -// .flatMap(dir -> model.getQuads(referenceState, dir, mc.world.rand, modelData).stream()) -// .collect(Collectors.toList()); + // BakedQuadWrapper quadReader = new BakedQuadWrapper(); + // + // IModelData modelData = model.getModelData(mc.world, BlockPos.ZERO.up(255), referenceState, VirtualEmptyModelData.INSTANCE); + // List quads = Arrays.stream(dirs) + // .flatMap(dir -> model.getQuads(referenceState, dir, mc.world.rand, modelData).stream()) + // .collect(Collectors.toList()); builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); - blockRenderer.renderModel(mc.world, model, referenceState, BlockPos.ZERO.up(255), ms, builder, true, - mc.world.rand, 42, OverlayTexture.DEFAULT_UV, VirtualEmptyModelData.INSTANCE); + blockRenderer.renderModel(mc.world, model, referenceState, BlockPos.ZERO.up(255), ms, builder, true, mc.world.rand, 42, OverlayTexture.DEFAULT_UV, VirtualEmptyModelData.INSTANCE); builder.finishDrawing(); return builder; } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java index e1c7bab74..e39363f04 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java @@ -109,7 +109,8 @@ public class InstancedRenderDispatcher { @SubscribeEvent public static void renderLayer(RenderLayerEvent event) { ClientWorld world = event.getWorld(); - if (!Backend.getInstance().canUseInstancing(world)) return; + if (!Backend.getInstance() + .canUseInstancing(world)) return; event.type.startDrawing(); @@ -122,7 +123,8 @@ public class InstancedRenderDispatcher { @SubscribeEvent public static void onReloadRenderers(ReloadRenderersEvent event) { ClientWorld world = event.getWorld(); - if (Backend.getInstance().canUseInstancing() && world != null) { + if (Backend.getInstance() + .canUseInstancing() && world != null) { loadAllInWorld(world); } } @@ -130,7 +132,8 @@ public class InstancedRenderDispatcher { private static final RenderType crumblingLayer = ModelBakery.BLOCK_DESTRUCTION_RENDER_LAYERS.get(0); public static void renderBreaking(ClientWorld world, Matrix4f viewProjection, double cameraX, double cameraY, double cameraZ) { - if (!Backend.getInstance().canUseInstancing(world)) return; + if (!Backend.getInstance() + .canUseInstancing(world)) return; WorldRenderer worldRenderer = Minecraft.getInstance().worldRenderer; Long2ObjectMap> breakingProgressions = worldRenderer.blockBreakingProgressions; @@ -145,9 +148,11 @@ public class InstancedRenderDispatcher { SortedSet progresses = entry.getValue(); if (progresses != null && !progresses.isEmpty()) { - int blockDamage = progresses.last().getPartialBlockDamage(); + int blockDamage = progresses.last() + .getPartialBlockDamage(); bitSet.set(blockDamage); - renderers.get(blockDamage).add(world.getTileEntity(breakingPos)); + renderers.get(blockDamage) + .add(world.getTileEntity(breakingPos)); } } @@ -155,38 +160,41 @@ public class InstancedRenderDispatcher { ActiveRenderInfo info = Minecraft.getInstance().gameRenderer.getActiveRenderInfo(); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, textureManager.getTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE).getGlTextureId()); + glBindTexture(GL_TEXTURE_2D, textureManager.getTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE) + .getGlTextureId()); glActiveTexture(GL_TEXTURE4); crumblingLayer.startDrawing(); - bitSet.stream().forEach(i -> { - Texture breaking = textureManager.getTexture(ModelBakery.BLOCK_DESTRUCTION_STAGE_TEXTURES.get(i)); - CrumblingInstanceManager renderer = renderers.get(i); - renderer.beginFrame(info); + bitSet.stream() + .forEach(i -> { + Texture breaking = textureManager.getTexture(ModelBakery.BLOCK_DESTRUCTION_STAGE_TEXTURES.get(i)); + CrumblingInstanceManager renderer = renderers.get(i); + renderer.beginFrame(info); - if (breaking != null) { - glBindTexture(GL_TEXTURE_2D, breaking.getGlTextureId()); - renderer.materialManager.render(RenderType.getCutoutMipped(), viewProjection, cameraX, cameraY, cameraZ); - } + if (breaking != null) { + glBindTexture(GL_TEXTURE_2D, breaking.getGlTextureId()); + renderer.materialManager.render(RenderType.getCutoutMipped(), viewProjection, cameraX, cameraY, cameraZ); + } - renderer.invalidate(); - }); + renderer.invalidate(); + }); crumblingLayer.endDrawing(); glActiveTexture(GL_TEXTURE0); Texture breaking = textureManager.getTexture(ModelBakery.BLOCK_DESTRUCTION_STAGE_TEXTURES.get(0)); - if (breaking != null) - glBindTexture(GL_TEXTURE_2D, breaking.getGlTextureId()); + if (breaking != null) glBindTexture(GL_TEXTURE_2D, breaking.getGlTextureId()); } public static void loadAllInWorld(ClientWorld world) { - Contexts.WORLD.getMaterialManager(world).delete(); + Contexts.WORLD.getMaterialManager(world) + .delete(); TileInstanceManager tiles = tileInstanceManager.replace(world); world.loadedTileEntityList.forEach(tiles::add); EntityInstanceManager entities = entityInstanceManager.replace(world); - world.getAllEntities().forEach(entities::add); + world.getAllEntities() + .forEach(entities::add); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java index 7cb3fafc5..e18c6cefc 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java @@ -65,8 +65,7 @@ public class Instancer { vao.bind(); renderSetup(); - if (glInstanceCount > 0) - model.drawInstances(glInstanceCount); + if (glInstanceCount > 0) model.drawInstances(glInstanceCount); vao.unbind(); } @@ -160,12 +159,13 @@ public class Instancer { if (length > 0) { MappedBuffer mapped = instanceVBO.getBuffer(offset, length); - dirtySet.stream().forEach(i -> { - final D d = data.get(i); + dirtySet.stream() + .forEach(i -> { + final D d = data.get(i); - mapped.position(i * stride); - d.write(mapped); - }); + mapped.position(i * stride); + d.write(mapped); + }); mapped.flush(); } } @@ -236,7 +236,8 @@ public class Instancer { anyToUpdate = true; - data.subList(newSize, oldSize).clear(); + data.subList(newSize, oldSize) + .clear(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java index dcaaa1b12..dc912edc7 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java @@ -42,7 +42,9 @@ public class MaterialManager

{ this.context = context; this.atlasMaterials = new HashMap<>(); - this.atlasRenderers = new ArrayList<>(Backend.getInstance().allMaterials().size()); + this.atlasRenderers = new ArrayList<>(Backend.getInstance() + .allMaterials() + .size()); this.materials = new HashMap<>(); this.renderers = new HashMap<>(); @@ -90,8 +92,13 @@ public class MaterialManager

{ } public void delete() { - atlasMaterials.values().forEach(InstanceMaterial::delete); - materials.values().stream().flatMap(m -> m.values().stream()).forEach(InstanceMaterial::delete); + atlasMaterials.values() + .forEach(InstanceMaterial::delete); + materials.values() + .stream() + .flatMap(m -> m.values() + .stream()) + .forEach(InstanceMaterial::delete); atlasMaterials.clear(); atlasRenderers.clear(); @@ -151,8 +158,13 @@ public class MaterialManager

{ originCoordinate = new BlockPos(cX, cY, cZ); - materials.values().stream().flatMap(m -> m.values().stream()).forEach(InstanceMaterial::clear); - atlasMaterials.values().forEach(InstanceMaterial::clear); + materials.values() + .stream() + .flatMap(m -> m.values() + .stream()) + .forEach(InstanceMaterial::clear); + atlasMaterials.values() + .forEach(InstanceMaterial::clear); listeners.forEach(OriginShiftListener::onOriginShift); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java index 2500ac960..4dd4134c5 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java @@ -24,7 +24,7 @@ import net.minecraft.world.World; /** * The layer between a {@link TileEntity} and the Flywheel backend. - ** + * * *

There are a few additional features that overriding classes can opt in to: *