Skip to content

Commit

Permalink
address review
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Oct 12, 2024
1 parent 93c1163 commit 178dd6c
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ class SubprojectPlugin: Plugin<Project> {
includeGroup("maven.modrinth")
}
}
flatDir {
dirs = setOf(project.rootProject.file("libs"))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public VertexConsumer setNormal(float x, float y, float z) {

public VertexConsumer endVertexIfNeeded() {
if (!filledPosition || !filledTexture || !filledNormal) {
// We do not throw here as that matched what vanilla does
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,5 +14,5 @@ public interface FlwImplXplat {

FlwConfig getConfig();

Supplier<Boolean> getModLoaded(String modId);
BooleanSupplier getModLoaded(String modId);
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ public BufferBuilder getBuffer(boolean shade) {
}

void prepareForGeometry(boolean shade) {
if (!((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding()) {
bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
} else if (shade != currentShade) {
bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);

if (((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding() && shade != currentShade) {
emit();
bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
}

currentShade = shade;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,7 +23,7 @@ public FlwConfig getConfig() {
}

@Override
public Supplier<Boolean> getModLoaded(String modId) {
return Suppliers.memoize(() -> FabricLoader.getInstance().isModLoaded(modId));
public BooleanSupplier getModLoaded(String modId) {
return () -> FabricLoader.getInstance().isModLoaded(modId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ public BufferBuilder unwrap(boolean shade) {
}

void prepareForGeometry(boolean shade) {
if (!((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding()) {
bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
} else if (shade != currentShade) {
bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);

if (((BufferBuilderAccessor) bufferBuilder).flywheel$getBuilding() && shade != currentShade) {
emit();
bufferBuilder = new BufferBuilder(byteBufferBuilder, VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
}

currentShade = shade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,39 @@
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@
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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,7 +15,7 @@ public void dispatchReloadLevelRendererEvent(ClientLevel level) {

@Override
public String getVersionStr() {
return FlywheelForge.version().toString();
return FlywheelNeoForge.version().toString();
}

@Override
Expand All @@ -26,7 +24,7 @@ public FlwConfig getConfig() {
}

@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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

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;

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;
Expand Down Expand Up @@ -53,17 +54,17 @@ public BlockRenderDispatcher createVanillaBlockRenderDispatcher() {

@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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -18,13 +16,12 @@
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;
Expand All @@ -34,14 +31,12 @@
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();
Expand All @@ -50,13 +45,6 @@ public FlywheelForge(IEventBus modEventBus, ModContainer 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);
registerLibEventListeners(forgeEventBus, modEventBus);
registerBackendEventListeners(forgeEventBus, modEventBus);
Expand All @@ -70,7 +58,7 @@ private static void registerImplEventListeners(IEventBus forgeEventBus, IEventBu

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());
}
});
Expand Down
Loading

0 comments on commit 178dd6c

Please sign in to comment.