address review

This commit is contained in:
IThundxr 2024-10-12 08:37:52 -04:00
parent 93c116384f
commit 178dd6c44e
No known key found for this signature in database
GPG Key ID: E291EC97BAF935E6
15 changed files with 58 additions and 82 deletions

View File

@ -89,9 +89,6 @@ class SubprojectPlugin: Plugin<Project> {
includeGroup("maven.modrinth") includeGroup("maven.modrinth")
} }
} }
flatDir {
dirs = setOf(project.rootProject.file("libs"))
}
} }
} }

View File

@ -76,6 +76,7 @@ class VertexWriter implements VertexConsumer {
public VertexConsumer endVertexIfNeeded() { public VertexConsumer endVertexIfNeeded() {
if (!filledPosition || !filledTexture || !filledNormal) { if (!filledPosition || !filledTexture || !filledNormal) {
// We do not throw here as that matched what vanilla does
return this; return this;
} }

View File

@ -1,6 +1,6 @@
package dev.engine_room.flywheel.impl; package dev.engine_room.flywheel.impl;
import java.util.function.Supplier; import java.util.function.BooleanSupplier;
import dev.engine_room.flywheel.api.internal.DependencyInjection; import dev.engine_room.flywheel.api.internal.DependencyInjection;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
@ -14,5 +14,5 @@ public interface FlwImplXplat {
FlwConfig getConfig(); FlwConfig getConfig();
Supplier<Boolean> getModLoaded(String modId); BooleanSupplier getModLoaded(String modId);
} }

View File

@ -1,22 +1,21 @@
package dev.engine_room.flywheel.impl.compat; package dev.engine_room.flywheel.impl.compat;
import java.util.Locale; import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
import dev.engine_room.flywheel.impl.FlwImplXplat; import dev.engine_room.flywheel.impl.FlwImplXplat;
public enum CompatMods { public enum CompatMods {
SODIUM, SODIUM("sodium"),
EMBEDDIUM, EMBEDDIUM("embeddium"),
IRIS; IRIS("iris");
private final Supplier<Boolean> isLoaded; private final BooleanSupplier isLoaded;
CompatMods() { CompatMods(String modid) {
isLoaded = FlwImplXplat.INSTANCE.getModLoaded(name().toLowerCase(Locale.ROOT)); isLoaded = FlwImplXplat.INSTANCE.getModLoaded(modid);
} }
public boolean isLoaded() { public boolean isLoaded() {
return isLoaded.get(); return isLoaded.getAsBoolean();
} }
} }

View File

@ -41,11 +41,10 @@ class MeshEmitter {
} }
void prepareForGeometry(boolean shade) { void prepareForGeometry(boolean shade) {
if (!((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding()) {
bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
} else if (shade != currentShade) {
if (((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding() && shade != currentShade) {
emit(); emit();
bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
} }
currentShade = shade; currentShade = shade;

View File

@ -1,8 +1,6 @@
package dev.engine_room.flywheel.impl; package dev.engine_room.flywheel.impl;
import java.util.function.Supplier; import java.util.function.BooleanSupplier;
import com.google.common.base.Suppliers;
import dev.engine_room.flywheel.api.event.ReloadLevelRendererCallback; import dev.engine_room.flywheel.api.event.ReloadLevelRendererCallback;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
@ -25,7 +23,7 @@ public class FlwImplXplatImpl implements FlwImplXplat {
} }
@Override @Override
public Supplier<Boolean> getModLoaded(String modId) { public BooleanSupplier getModLoaded(String modId) {
return Suppliers.memoize(() -> FabricLoader.getInstance().isModLoaded(modId)); return () -> FabricLoader.getInstance().isModLoaded(modId);
} }
} }

View File

@ -4,7 +4,7 @@ import net.minecraft.client.multiplayer.ClientLevel;
import net.neoforged.bus.api.Event; import net.neoforged.bus.api.Event;
/** /**
* This event is posted to the Forge event bus. * This event is posted to the NeoForge event bus.
*/ */
public final class ReloadLevelRendererEvent extends Event { public final class ReloadLevelRendererEvent extends Event {
private final ClientLevel level; private final ClientLevel level;

View File

@ -44,11 +44,10 @@ class MeshEmitter implements VertexConsumer {
} }
void prepareForGeometry(boolean shade) { void prepareForGeometry(boolean shade) {
if (!((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding()) {
bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK); bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
} else if (shade != currentShade) {
if (((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding() && shade != currentShade) {
emit(); emit();
bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
} }
currentShade = shade; currentShade = shade;

View File

@ -17,39 +17,39 @@ import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.client.model.data.ModelData; import net.neoforged.neoforge.client.model.data.ModelData;
public final class ForgeBakedModelBuilder extends BakedModelBuilder { public final class NeoForgeBakedModelBuilder extends BakedModelBuilder {
@Nullable @Nullable
private ModelData modelData; private ModelData modelData;
public ForgeBakedModelBuilder(BakedModel bakedModel) { public NeoForgeBakedModelBuilder(BakedModel bakedModel) {
super(bakedModel); super(bakedModel);
} }
@Override @Override
public ForgeBakedModelBuilder level(BlockAndTintGetter level) { public NeoForgeBakedModelBuilder level(BlockAndTintGetter level) {
super.level(level); super.level(level);
return this; return this;
} }
@Override @Override
public ForgeBakedModelBuilder blockState(BlockState blockState) { public NeoForgeBakedModelBuilder blockState(BlockState blockState) {
super.blockState(blockState); super.blockState(blockState);
return this; return this;
} }
@Override @Override
public ForgeBakedModelBuilder poseStack(PoseStack poseStack) { public NeoForgeBakedModelBuilder poseStack(PoseStack poseStack) {
super.poseStack(poseStack); super.poseStack(poseStack);
return this; return this;
} }
@Override @Override
public ForgeBakedModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material> materialFunc) { public NeoForgeBakedModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material> materialFunc) {
super.materialFunc(materialFunc); super.materialFunc(materialFunc);
return this; return this;
} }
public ForgeBakedModelBuilder modelData(ModelData modelData) { public NeoForgeBakedModelBuilder modelData(ModelData modelData) {
this.modelData = modelData; this.modelData = modelData;
return this; return this;
} }

View File

@ -16,33 +16,33 @@ import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.client.model.data.ModelData; import net.neoforged.neoforge.client.model.data.ModelData;
public final class ForgeBlockModelBuilder extends BlockModelBuilder { public final class NeoForgeBlockModelBuilder extends BlockModelBuilder {
@Nullable @Nullable
private ModelData modelData; private ModelData modelData;
public ForgeBlockModelBuilder(BlockState state) { public NeoForgeBlockModelBuilder(BlockState state) {
super(state); super(state);
} }
@Override @Override
public ForgeBlockModelBuilder level(BlockAndTintGetter level) { public NeoForgeBlockModelBuilder level(BlockAndTintGetter level) {
super.level(level); super.level(level);
return this; return this;
} }
@Override @Override
public ForgeBlockModelBuilder poseStack(PoseStack poseStack) { public NeoForgeBlockModelBuilder poseStack(PoseStack poseStack) {
super.poseStack(poseStack); super.poseStack(poseStack);
return this; return this;
} }
@Override @Override
public ForgeBlockModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material> materialFunc) { public NeoForgeBlockModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material> materialFunc) {
super.materialFunc(materialFunc); super.materialFunc(materialFunc);
return this; return this;
} }
public ForgeBlockModelBuilder modelData(ModelData modelData) { public NeoForgeBlockModelBuilder modelData(ModelData modelData) {
this.modelData = modelData; this.modelData = modelData;
return this; return this;
} }

View File

@ -17,33 +17,33 @@ import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.BlockAndTintGetter;
import net.neoforged.neoforge.client.model.data.ModelData; import net.neoforged.neoforge.client.model.data.ModelData;
public final class ForgeMultiBlockModelBuilder extends MultiBlockModelBuilder { public final class NeoForgeMultiBlockModelBuilder extends MultiBlockModelBuilder {
@Nullable @Nullable
private Function<BlockPos, ModelData> modelDataLookup; private Function<BlockPos, ModelData> modelDataLookup;
public ForgeMultiBlockModelBuilder(BlockAndTintGetter level, Iterable<BlockPos> positions) { public NeoForgeMultiBlockModelBuilder(BlockAndTintGetter level, Iterable<BlockPos> positions) {
super(level, positions); super(level, positions);
} }
@Override @Override
public ForgeMultiBlockModelBuilder poseStack(PoseStack poseStack) { public NeoForgeMultiBlockModelBuilder poseStack(PoseStack poseStack) {
super.poseStack(poseStack); super.poseStack(poseStack);
return this; return this;
} }
@Override @Override
public ForgeMultiBlockModelBuilder enableFluidRendering() { public NeoForgeMultiBlockModelBuilder enableFluidRendering() {
super.enableFluidRendering(); super.enableFluidRendering();
return this; return this;
} }
@Override @Override
public ForgeMultiBlockModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material> materialFunc) { public NeoForgeMultiBlockModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material> materialFunc) {
super.materialFunc(materialFunc); super.materialFunc(materialFunc);
return this; return this;
} }
public ForgeMultiBlockModelBuilder modelDataLookup(Function<BlockPos, ModelData> modelDataLookup) { public NeoForgeMultiBlockModelBuilder modelDataLookup(Function<BlockPos, ModelData> modelDataLookup) {
this.modelDataLookup = modelDataLookup; this.modelDataLookup = modelDataLookup;
return this; return this;
} }

View File

@ -1,8 +1,6 @@
package dev.engine_room.flywheel.impl; package dev.engine_room.flywheel.impl;
import java.util.function.Supplier; import java.util.function.BooleanSupplier;
import com.google.common.base.Suppliers;
import dev.engine_room.flywheel.api.event.ReloadLevelRendererEvent; import dev.engine_room.flywheel.api.event.ReloadLevelRendererEvent;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
@ -17,7 +15,7 @@ public class FlwImplXplatImpl implements FlwImplXplat {
@Override @Override
public String getVersionStr() { public String getVersionStr() {
return FlywheelForge.version().toString(); return FlywheelNeoForge.version().toString();
} }
@Override @Override
@ -26,7 +24,7 @@ public class FlwImplXplatImpl implements FlwImplXplat {
} }
@Override @Override
public Supplier<Boolean> getModLoaded(String modId) { public BooleanSupplier getModLoaded(String modId) {
return Suppliers.memoize(() -> LoadingModList.get().getModFileById(modId) != null); return () -> LoadingModList.get().getModFileById(modId) != null;
} }
} }

View File

@ -2,6 +2,9 @@ package dev.engine_room.flywheel.impl;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import dev.engine_room.flywheel.lib.model.baked.NeoForgeBlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.NeoForgeMultiBlockModelBuilder;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnknownNullability; import org.jetbrains.annotations.UnknownNullability;
@ -9,9 +12,7 @@ import dev.engine_room.flywheel.impl.compat.CompatMods;
import dev.engine_room.flywheel.lib.internal.FlwLibXplat; import dev.engine_room.flywheel.lib.internal.FlwLibXplat;
import dev.engine_room.flywheel.lib.model.baked.BakedModelBuilder; import dev.engine_room.flywheel.lib.model.baked.BakedModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.BlockModelBuilder; import dev.engine_room.flywheel.lib.model.baked.BlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.ForgeBakedModelBuilder; import dev.engine_room.flywheel.lib.model.baked.NeoForgeBakedModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.ForgeBlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.ForgeMultiBlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.MultiBlockModelBuilder; import dev.engine_room.flywheel.lib.model.baked.MultiBlockModelBuilder;
import dev.engine_room.flywheel.lib.util.ShadersModHandler; import dev.engine_room.flywheel.lib.util.ShadersModHandler;
import net.irisshaders.iris.api.v0.IrisApi; import net.irisshaders.iris.api.v0.IrisApi;
@ -53,17 +54,17 @@ public class FlwLibXplatImpl implements FlwLibXplat {
@Override @Override
public BakedModelBuilder createBakedModelBuilder(BakedModel bakedModel) { public BakedModelBuilder createBakedModelBuilder(BakedModel bakedModel) {
return new ForgeBakedModelBuilder(bakedModel); return new NeoForgeBakedModelBuilder(bakedModel);
} }
@Override @Override
public BlockModelBuilder createBlockModelBuilder(BlockState state) { public BlockModelBuilder createBlockModelBuilder(BlockState state) {
return new ForgeBlockModelBuilder(state); return new NeoForgeBlockModelBuilder(state);
} }
@Override @Override
public MultiBlockModelBuilder createMultiBlockModelBuilder(BlockAndTintGetter level, Iterable<BlockPos> positions) { public MultiBlockModelBuilder createMultiBlockModelBuilder(BlockAndTintGetter level, Iterable<BlockPos> positions) {
return new ForgeMultiBlockModelBuilder(level, positions); return new NeoForgeMultiBlockModelBuilder(level, positions);
} }
@Override @Override

View File

@ -1,7 +1,5 @@
package dev.engine_room.flywheel.impl; package dev.engine_room.flywheel.impl;
import java.util.function.Supplier;
import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.jetbrains.annotations.UnknownNullability; import org.jetbrains.annotations.UnknownNullability;
@ -18,13 +16,12 @@ import dev.engine_room.flywheel.lib.util.ResourceReloadHolder;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.commands.synchronization.ArgumentTypeInfos; import net.minecraft.commands.synchronization.ArgumentTypeInfos;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus; import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.CrashReportCallables; import net.neoforged.fml.CrashReportCallables;
import net.neoforged.fml.ModContainer; import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod; import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.fml.loading.FMLLoader;
import net.neoforged.neoforge.client.event.CustomizeGuiOverlayEvent; import net.neoforged.neoforge.client.event.CustomizeGuiOverlayEvent;
import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent; import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent;
import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.common.NeoForge;
@ -34,14 +31,12 @@ import net.neoforged.neoforge.event.level.LevelEvent;
import net.neoforged.neoforge.event.tick.LevelTickEvent; import net.neoforged.neoforge.event.tick.LevelTickEvent;
import net.neoforged.neoforge.registries.RegisterEvent; import net.neoforged.neoforge.registries.RegisterEvent;
@Mod(Flywheel.ID) @Mod(value = Flywheel.ID, dist = Dist.CLIENT)
public final class FlywheelForge { public final class FlywheelNeoForge {
@UnknownNullability @UnknownNullability
private static ArtifactVersion version; private static ArtifactVersion version;
public FlywheelForge(IEventBus modEventBus, ModContainer modContainer) { public FlywheelNeoForge(IEventBus modEventBus, ModContainer modContainer) {
ModLoadingContext modLoadingContext = ModLoadingContext.get();
version = modContainer version = modContainer
.getModInfo() .getModInfo()
.getVersion(); .getVersion();
@ -50,13 +45,6 @@ public final class FlywheelForge {
ForgeFlwConfig.INSTANCE.registerSpecs(modContainer); ForgeFlwConfig.INSTANCE.registerSpecs(modContainer);
if (FMLLoader.getDist().isClient()) {
Supplier<Runnable> toRun = () -> () -> FlywheelForge.clientInit(forgeEventBus, modEventBus);
toRun.get().run();
}
}
private static void clientInit(IEventBus forgeEventBus, IEventBus modEventBus) {
registerImplEventListeners(forgeEventBus, modEventBus); registerImplEventListeners(forgeEventBus, modEventBus);
registerLibEventListeners(forgeEventBus, modEventBus); registerLibEventListeners(forgeEventBus, modEventBus);
registerBackendEventListeners(forgeEventBus, modEventBus); registerBackendEventListeners(forgeEventBus, modEventBus);
@ -70,7 +58,7 @@ public final class FlywheelForge {
forgeEventBus.addListener((LevelTickEvent.Post e) -> { forgeEventBus.addListener((LevelTickEvent.Post e) -> {
// Make sure we don't tick on the server somehow. // Make sure we don't tick on the server somehow.
if (FMLLoader.getDist().isClient()) { if (e.getLevel().isClientSide()) {
VisualizationEventHandler.onClientTick(Minecraft.getInstance(), e.getLevel()); VisualizationEventHandler.onClientTick(Minecraft.getInstance(), e.getLevel());
} }
}); });

View File

@ -2,7 +2,6 @@ package dev.engine_room.flywheel.impl.mixin;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@ -10,7 +9,6 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Coerce; import org.spongepowered.asm.mixin.injection.Coerce;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import dev.engine_room.flywheel.api.event.EndClientResourceReloadEvent; import dev.engine_room.flywheel.api.event.EndClientResourceReloadEvent;
@ -25,11 +23,9 @@ abstract class MinecraftMixin {
@Final @Final
private ReloadableResourceManager resourceManager; private ReloadableResourceManager resourceManager;
// Inject at invoke cannot be used in constructors in vanilla Mixin, so use ModifyArg instead. @Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/packs/resources/ReloadableResourceManager;createReload(Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/concurrent/CompletableFuture;Ljava/util/List;)Lnet/minecraft/server/packs/resources/ReloadInstance;"))
@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/packs/resources/ReloadableResourceManager;createReload(Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/concurrent/CompletableFuture;Ljava/util/List;)Lnet/minecraft/server/packs/resources/ReloadInstance;"), index = 0) private void flywheel$onBeginInitialResourceReload(CallbackInfo ci) {
private Executor flywheel$onBeginInitialResourceReload(Executor arg0) {
FlwImpl.freezeRegistries(); FlwImpl.freezeRegistries();
return arg0;
} }
@Inject(method = "lambda$new$8", at = @At("HEAD"), remap = false) @Inject(method = "lambda$new$8", at = @At("HEAD"), remap = false)