Skip to content

Commit

Permalink
Add support for DelegateBakedModels with custom getQuads
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Jan 26, 2025
1 parent 194cb11 commit 8849419
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 22 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

object BuildConfig {
val MINECRAFT_VERSION: String = "1.21.4"
val NEOFORGE_VERSION: String = "21.4.30-beta"
val NEOFORGE_VERSION: String = "21.4.47-beta"
val FABRIC_LOADER_VERSION: String = "0.16.9"
val FABRIC_API_VERSION: String = "0.112.1+1.21.4"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.caffeinemc.mods.sodium.mixin.features.model;

import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.fabricmc.fabric.impl.renderer.VanillaModelEncoder;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.DelegateBakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import java.util.function.Predicate;
import java.util.function.Supplier;

@Mixin(value = DelegateBakedModel.class, priority = 1010)
public class DelegateBakedModelMixin implements FabricBakedModel {
@Shadow
@Final
protected BakedModel parent;

@Override
public void emitBlockQuads(QuadEmitter emitter, BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier<RandomSource> randomSupplier, Predicate<@Nullable Direction> cullTest) {
if (!this.parent.isVanillaAdapter()) {
this.parent.emitBlockQuads(emitter, blockView, state, pos, randomSupplier, cullTest);
} else {
VanillaModelEncoder.emitBlockQuads(emitter, (BakedModel)this, state, randomSupplier, cullTest);
}
}

@Override
public void emitItemQuads(QuadEmitter emitter, Supplier<RandomSource> randomSupplier) {
if (!this.parent.isVanillaAdapter()) {
this.parent.emitItemQuads(emitter, randomSupplier);
} else {
VanillaModelEncoder.emitItemQuads(emitter, ((BakedModel) this), null, randomSupplier);
}
}
}
13 changes: 7 additions & 6 deletions fabric/src/main/resources/sodium-fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
"conformVisibility": true
},
"client": [
"core.model.quad.BakedQuadMixin",
"features.model.MultiPartBakedModelMixin",
"features.model.WeightedBakedModelMixin",
"features.model.WeightedRandomListMixin",
"features.render.model.block.ModelBlockRendererMixin",
"features.world.biome.BiomeMixin"
"core.model.quad.BakedQuadMixin",
"features.model.DelegateBakedModelMixin",
"features.model.MultiPartBakedModelMixin",
"features.model.WeightedBakedModelMixin",
"features.model.WeightedRandomListMixin",
"features.render.model.block.ModelBlockRendererMixin",
"features.world.biome.BiomeMixin"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.caffeinemc.mods.sodium.mixin.features.model;

import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.fabricmc.fabric.impl.renderer.VanillaModelEncoder;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.DelegateBakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import java.util.function.Predicate;
import java.util.function.Supplier;

@Mixin(value = DelegateBakedModel.class, priority = 1010)
public class DelegateBakedModelMixin implements FabricBakedModel {
@Shadow
@Final
protected BakedModel parent;

@Override
public void emitBlockQuads(QuadEmitter emitter, BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier<RandomSource> randomSupplier, Predicate<@Nullable Direction> cullTest) {
if (!((FabricBakedModel) this.parent).isVanillaAdapter()) {
((FabricBakedModel) this.parent).emitBlockQuads(emitter, blockView, state, pos, randomSupplier, cullTest);
} else {
VanillaModelEncoder.emitBlockQuads(emitter, (BakedModel)this, state, randomSupplier, cullTest);
}
}

@Override
public void emitItemQuads(QuadEmitter emitter, Supplier<RandomSource> randomSupplier) {
if (!((FabricBakedModel) this.parent).isVanillaAdapter()) {
((FabricBakedModel) this.parent).emitItemQuads(emitter, randomSupplier);
} else {
VanillaModelEncoder.emitItemQuads(emitter, ((BakedModel) this), null, randomSupplier);
}
}
}
31 changes: 16 additions & 15 deletions neoforge/src/main/resources/sodium-neoforge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
"conformVisibility" : true
},
"client" : [
"core.model.quad.BakedQuadMixin",
"features.model.MultiPartBakedModelMixin",
"features.model.WeightedBakedModelMixin",
"features.model.WeightedRandomListMixin",
"features.render.model.block.ModelBlockRendererMixin",
"features.world.biome.BiomeMixin",
"platform.neoforge.AbstractBlockRenderContextMixin",
"platform.neoforge.AuxiliaryLightManagerMixin",
"platform.neoforge.ChunkRenderTypeSetAccessor",
"platform.neoforge.ClientHooksMixin",
"platform.neoforge.EntrypointMixin",
"platform.neoforge.LevelSliceMixin",
"platform.neoforge.ModelDataMixin",
"platform.neoforge.ResourcePackLoaderMixin",
"platform.neoforge.SimpleBakedModelAccessor"
"core.model.quad.BakedQuadMixin",
"features.model.DelegateBakedModelMixin",
"features.model.MultiPartBakedModelMixin",
"features.model.WeightedBakedModelMixin",
"features.model.WeightedRandomListMixin",
"features.render.model.block.ModelBlockRendererMixin",
"features.world.biome.BiomeMixin",
"platform.neoforge.AbstractBlockRenderContextMixin",
"platform.neoforge.AuxiliaryLightManagerMixin",
"platform.neoforge.ChunkRenderTypeSetAccessor",
"platform.neoforge.ClientHooksMixin",
"platform.neoforge.EntrypointMixin",
"platform.neoforge.LevelSliceMixin",
"platform.neoforge.ModelDataMixin",
"platform.neoforge.ResourcePackLoaderMixin",
"platform.neoforge.SimpleBakedModelAccessor"
]
}

0 comments on commit 8849419

Please sign in to comment.