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")
}
}
flatDir {
dirs = setOf(project.rootProject.file("libs"))
}
}
}

View File

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

View File

@ -1,6 +1,6 @@
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 net.minecraft.client.multiplayer.ClientLevel;
@ -14,5 +14,5 @@ public interface FlwImplXplat {
FlwConfig getConfig();
Supplier<Boolean> getModLoaded(String modId);
BooleanSupplier getModLoaded(String modId);
}

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ import net.minecraft.client.multiplayer.ClientLevel;
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 {
private final ClientLevel level;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,6 +2,9 @@ package dev.engine_room.flywheel.impl;
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.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.model.baked.BakedModelBuilder;
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.ForgeBlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.ForgeMultiBlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.NeoForgeBakedModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.MultiBlockModelBuilder;
import dev.engine_room.flywheel.lib.util.ShadersModHandler;
import net.irisshaders.iris.api.v0.IrisApi;
@ -53,17 +54,17 @@ public class FlwLibXplatImpl implements FlwLibXplat {
@Override
public BakedModelBuilder createBakedModelBuilder(BakedModel bakedModel) {
return new ForgeBakedModelBuilder(bakedModel);
return new NeoForgeBakedModelBuilder(bakedModel);
}
@Override
public BlockModelBuilder createBlockModelBuilder(BlockState state) {
return new ForgeBlockModelBuilder(state);
return new NeoForgeBlockModelBuilder(state);
}
@Override
public MultiBlockModelBuilder createMultiBlockModelBuilder(BlockAndTintGetter level, Iterable<BlockPos> positions) {
return new ForgeMultiBlockModelBuilder(level, positions);
return new NeoForgeMultiBlockModelBuilder(level, positions);
}
@Override

View File

@ -1,7 +1,5 @@
package dev.engine_room.flywheel.impl;
import java.util.function.Supplier;
import org.apache.maven.artifact.versioning.ArtifactVersion;
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.commands.synchronization.ArgumentTypeInfos;
import net.minecraft.core.registries.Registries;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.CrashReportCallables;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod;
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.RegisterClientReloadListenersEvent;
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.registries.RegisterEvent;
@Mod(Flywheel.ID)
public final class FlywheelForge {
@Mod(value = Flywheel.ID, dist = Dist.CLIENT)
public final class FlywheelNeoForge {
@UnknownNullability
private static ArtifactVersion version;
public FlywheelForge(IEventBus modEventBus, ModContainer modContainer) {
ModLoadingContext modLoadingContext = ModLoadingContext.get();
public FlywheelNeoForge(IEventBus modEventBus, ModContainer modContainer) {
version = modContainer
.getModInfo()
.getVersion();
@ -50,13 +45,6 @@ public final class FlywheelForge {
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);
registerLibEventListeners(forgeEventBus, modEventBus);
registerBackendEventListeners(forgeEventBus, modEventBus);
@ -70,7 +58,7 @@ public final class FlywheelForge {
forgeEventBus.addListener((LevelTickEvent.Post e) -> {
// Make sure we don't tick on the server somehow.
if (FMLLoader.getDist().isClient()) {
if (e.getLevel().isClientSide()) {
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.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import org.spongepowered.asm.mixin.Final;
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.Coerce;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import dev.engine_room.flywheel.api.event.EndClientResourceReloadEvent;
@ -25,11 +23,9 @@ abstract class MinecraftMixin {
@Final
private ReloadableResourceManager resourceManager;
// Inject at invoke cannot be used in constructors in vanilla Mixin, so use ModifyArg instead.
@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 Executor flywheel$onBeginInitialResourceReload(Executor arg0) {
@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;"))
private void flywheel$onBeginInitialResourceReload(CallbackInfo ci) {
FlwImpl.freezeRegistries();
return arg0;
}
@Inject(method = "lambda$new$8", at = @At("HEAD"), remap = false)