Skip to content

Commit

Permalink
Fixed neo blockstate culling with sodium
Browse files Browse the repository at this point in the history
  • Loading branch information
1foxy2 committed Oct 28, 2024
1 parent 7b9f10e commit 17fd225
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package ca.fxco.moreculling.mixin.blocks.cullshape;

import ca.fxco.moreculling.api.block.MoreBlockCulling;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.BrewingStandBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -27,4 +30,9 @@ protected BrewingStandBlock_voxelMixin(Properties settings) {
public VoxelShape getOcclusionShape(BlockState state) {
return moreculling$occlusionShape;
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return moreculling$occlusionShape;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.fxco.moreculling.api.block.MoreBlockCulling;
import ca.fxco.moreculling.api.model.BakedOpacity;
import ca.fxco.moreculling.platform.Services;
import ca.fxco.moreculling.utils.CullingUtils;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Direction;
Expand All @@ -27,7 +28,7 @@ public class Block_drawSideMixin implements MoreBlockCulling {
@Override
public boolean moreculling$shouldAttemptToCull(BlockState state, Direction side) {
BakedModel model = blockRenderManager.getBlockModel(state);
model.getQuads(state, side, CullingUtils.random);
Services.PLATFORM.getQuads(model, state, side, CullingUtils.random);
return !((BakedOpacity) model).moreculling$hasTextureTranslucency(state, side);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package ca.fxco.moreculling.platform.services;

import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;

import java.util.List;

public interface IPlatformHelper {

/**
Expand Down Expand Up @@ -34,4 +42,6 @@ default String getEnvironmentName() {
}

String getModName(String modId);

List<BakedQuad> getQuads(BakedModel model, BlockState state, Direction direction, RandomSource source);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import ca.fxco.moreculling.api.quad.QuadOpacity;
import ca.fxco.moreculling.utils.BitUtils;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.MultiPartBakedModel;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -22,7 +20,6 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;
import java.util.function.Predicate;

@Mixin(value = MultiPartBakedModel.class, priority = 1010)
public abstract class MultiPartBakedModel_cacheMixin implements BakedOpacity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
import ca.fxco.moreculling.platform.services.IPlatformHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;

import java.util.List;

public class FabricPlatformHelper implements IPlatformHelper {

Expand All @@ -28,4 +35,9 @@ public String getModName(String modId) {

return container == null ? modId : container.getMetadata().getName();
}

@Override
public List<BakedQuad> getQuads(BakedModel model, BlockState state, Direction direction, RandomSource source) {
return model.getQuads(state, direction, source);
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ modmenu_version=12.0.0-beta.1
fabric_version=0.106.1+1.21.3

# Sodium Compatibility
sodium_version=mc1.21.2-0.6.0-beta.3
sodium_version=mc1.21.3-0.6.0-beta.4

# Conditional Mixins - Needs to be changed in fabric.mod.json also
conditional_mixins_version=0.6.3
Expand Down
2 changes: 1 addition & 1 deletion neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ neoForge {
}

dependencies {
compileOnly "maven.modrinth:sodium:${project.sodium_version}-neoforge"
implementation "maven.modrinth:sodium:${project.sodium_version}-neoforge"
runtimeOnly "me.shedaniel.cloth:cloth-config-neoforge:${project.cloth_config_version}"

implementation(jarJar("me.fallenbreath:conditional-mixin-neoforge:${project.conditional_mixins_version}"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import ca.fxco.moreculling.utils.BitUtils;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.MultiPartBakedModel;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.neoforge.client.model.data.ModelData;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -24,7 +22,6 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;
import java.util.function.Predicate;

@Mixin(value = MultiPartBakedModel.class, priority = 1010)
public abstract class MultiPartBakedModel_cacheMixin implements BakedOpacity {
Expand Down Expand Up @@ -54,9 +51,9 @@ public abstract class MultiPartBakedModel_cacheMixin implements BakedOpacity {
@Override
public @Nullable VoxelShape moreculling$getCullingShape(BlockState state) {
VoxelShape cachedShape = null;
for (MultiPartBakedModel.Selector pair : this.selectors) {
if ((pair.condition()).test(state)) {
VoxelShape shape = ((BakedOpacity) pair.model()).moreculling$getCullingShape(state);
for (MultiPartBakedModel.Selector selector : this.selectors) {
if ((selector.condition()).test(state)) {
VoxelShape shape = ((BakedOpacity) selector.model()).moreculling$getCullingShape(state);
if (shape != null) {
if (cachedShape == null) {
cachedShape = shape;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package ca.fxco.moreculling.platform;

import ca.fxco.moreculling.platform.services.IPlatformHelper;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModList;
import net.neoforged.fml.loading.FMLLoader;
import net.neoforged.neoforge.client.model.data.ModelData;

import java.util.List;

public class NeoForgePlatformHelper implements IPlatformHelper {

Expand All @@ -30,4 +38,9 @@ public String getModName(String modId) {

return container == null ? modId : container.getModInfo().getDisplayName();
}

@Override
public List<BakedQuad> getQuads(BakedModel model, BlockState state, Direction direction, RandomSource source) {
return model.getQuads(state, direction, source, ModelData.EMPTY, null);
}
}

0 comments on commit 17fd225

Please sign in to comment.