Skip to content

Commit

Permalink
Neoforge 21.4.84 support, add breaks with sodium 0.6.6 or below to mo…
Browse files Browse the repository at this point in the history
…ds file

Fixes: #337
  • Loading branch information
1foxy2 committed Feb 12, 2025
1 parent 96df50f commit e438d94
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 34 deletions.
5 changes: 4 additions & 1 deletion common/src/main/java/ca/fxco/moreculling/MoreCulling.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public class MoreCulling {
public static BlockRenderDispatcher blockRenderManager = null;

public static final String MOD_ID = "moreculling";
public static final TagKey<Block> DONT_CULL = TagKey.create(BuiltInRegistries.BLOCK.key(), ResourceLocation.fromNamespaceAndPath(MOD_ID, "dont_cull"));
public static final TagKey<Block> DONT_CULL = TagKey.create(BuiltInRegistries.BLOCK.key(),
ResourceLocation.fromNamespaceAndPath(MOD_ID, "dont_cull"));
public static final ResourceLocation RELOAD_LISTENER_ID = ResourceLocation
.fromNamespaceAndPath(MoreCulling.MOD_ID, "init_blockstate_culling_cache");

public static Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static MoreCullingConfig CONFIG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ public class Minecraft_managersMixin {
@Final
private ModelManager modelManager;

@Shadow
@Final
private ReloadableResourceManager resourceManager;

@Inject(
method = "<init>",
at = @At(
Expand All @@ -58,15 +54,5 @@ public class Minecraft_managersMixin {
)
private void moreculling$onBlockRenderManagerInitialized(GameConfig args, CallbackInfo ci) {
MoreCulling.blockRenderManager = this.blockRenderer;

// Make sure to reload block states on resource reload
this.resourceManager.registerReloadListener((ResourceManagerReloadListener) manager ->
Block.BLOCK_STATE_REGISTRY.forEach(BlockBehaviour.BlockStateBase::initCache));

this.resourceManager.registerReloadListener((ResourceManagerReloadListener) manager -> {
((BlockModelShaperAccessor) blockRenderManager.getBlockModelShaper()).getModels()
.forEach((state, model) ->
((BakedOpacity) model).moreculling$resetTranslucencyCache(state));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,9 @@ public interface IPlatformHelper {
*/
boolean isDevelopmentEnvironment();

/**
* Gets the name of the environment type as a string.
*
* @return The name of the environment type.
*/
default String getEnvironmentName() {
return isDevelopmentEnvironment() ? "development" : "production";
}

String getModName(String modId);

List<BakedQuad> getQuads(BakedModel model, BlockState state, Direction direction,
RandomSource source, BlockGetter level, BlockPos pos);

}
41 changes: 41 additions & 0 deletions fabric/src/main/java/ca/fxco/moreculling/MoreCullingFabric.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
package ca.fxco.moreculling;

import ca.fxco.moreculling.api.model.BakedOpacity;
import ca.fxco.moreculling.mixin.accessors.BlockModelShaperAccessor;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.Unit;
import net.minecraft.util.profiling.Profiler;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

import static ca.fxco.moreculling.MoreCulling.blockRenderManager;

public class MoreCullingFabric implements ClientModInitializer {
@Override
public void onInitializeClient() {
MoreCulling.init();

ResourceManagerHelper.get(PackType.CLIENT_RESOURCES)
.registerReloadListener(new IdentifiableResourceReloadListener() {
@Override
public ResourceLocation getFabricId() {
return MoreCulling.RELOAD_LISTENER_ID;
}

@Override
public CompletableFuture<Void> reload(PreparationBarrier barrier, ResourceManager manager, Executor backgroundExecutor, Executor gameExecutor) {
return barrier.wait(Unit.INSTANCE).thenRunAsync(() -> {
ProfilerFiller profilerfiller = Profiler.get();
profilerfiller.push("listener");

Block.BLOCK_STATE_REGISTRY.forEach(BlockBehaviour.BlockStateBase::initCache);

((BlockModelShaperAccessor) blockRenderManager.getBlockModelShaper()).getModels()
.forEach((state, model) ->
((BakedOpacity) model).moreculling$resetTranslucencyCache(state));

profilerfiller.pop();
}, gameExecutor);
}
});
}
}
4 changes: 2 additions & 2 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"cloth-config": ">=16.0.0"
},
"suggests": {
"sodium": ">=0.6.0"
"sodium": ">=0.6.7"
},
"breaks": {
"sodium": "<=0.5.11"
"sodium": "<=0.6.6"
},
"custom": {
"modmenu": {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ parchment_minecraft=1.21.4
parchment_version=2025.01.05

# NeoForge
neoforge_version=21.4.0-beta
neoforge_loader_version_range=[21.0.0-beta,)
neoforge_version=21.4.89-beta
neoforge_loader_version_range=[21.4.84-beta,)

# Fabric version
fabric_loader_version=0.16.9

# Mod Properties
mod_version=1.2.4
mod_version=1.2.5
maven_group=ca.fxco.moreculling
archives_base_name=moreculling
license=GPL-3.0-only
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
package ca.fxco.moreculling;

import ca.fxco.moreculling.api.model.BakedOpacity;
import ca.fxco.moreculling.config.ModMenuConfig;
import ca.fxco.moreculling.mixin.accessors.BlockModelShaperAccessor;
import net.minecraft.util.Unit;
import net.minecraft.util.profiling.Profiler;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.client.event.AddClientReloadListenersEvent;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;

import static ca.fxco.moreculling.MoreCulling.blockRenderManager;

@Mod(value = MoreCulling.MOD_ID, dist = Dist.CLIENT)
public class MoreCullingNeoforge {
public MoreCullingNeoforge(ModContainer container) {
public MoreCullingNeoforge(ModContainer container, IEventBus bus) {
MoreCulling.init();

container.registerExtensionPoint(IConfigScreenFactory.class, (con, screen) -> ModMenuConfig.createConfigScreen(screen));
container.registerExtensionPoint(IConfigScreenFactory.class,
(con, screen) -> ModMenuConfig.createConfigScreen(screen));

bus.addListener(this::registerReloadListener);
}

public void registerReloadListener(AddClientReloadListenersEvent event) {
event.addListener(MoreCulling.RELOAD_LISTENER_ID, (barrier,
resourceManager,
executor, gameExecutor) ->
barrier.wait(Unit.INSTANCE).thenRunAsync(() -> {
ProfilerFiller profilerfiller = Profiler.get();
profilerfiller.push("listener");

Block.BLOCK_STATE_REGISTRY.forEach(BlockBehaviour.BlockStateBase::initCache);

((BlockModelShaperAccessor) blockRenderManager.getBlockModelShaper()).getModels()
.forEach((state, model) ->
((BakedOpacity) model).moreculling$resetTranslucencyCache(state));

profilerfiller.pop();
}, gameExecutor));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ public List<BakedQuad> getQuads(BakedModel model, BlockState state, Direction di
RandomSource source, BlockGetter level, BlockPos pos) {
return model.getQuads(state, direction, source, level.getModelData(pos), null);
}

}
6 changes: 3 additions & 3 deletions neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ config = "${mod_id}.neoforge.mixins.json"
side="BOTH"

[[dependencies.${mod_id}]]
modId="cloth_config"
type="required"
versionRange="[15.0.0, )"
modId="sodium"
type="incompatible"
versionRange="[, 0.6.7)"
ordering="AFTER"
side="BOTH"

Expand Down

0 comments on commit e438d94

Please sign in to comment.