Skip to content

Commit

Permalink
Port to 24w36a
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Sep 5, 2024
1 parent a5685bb commit b655ae8
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 32 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ plugins {
id("fabric-loom") version ("1.7.3") apply (false)
}

val MINECRAFT_VERSION by extra { "24w34a" }
val MINECRAFT_VERSION by extra { "24w36a" }
val NEOFORGE_VERSION by extra { "21.0.163" }
val FABRIC_LOADER_VERSION by extra { "0.16.2" }
val FABRIC_API_VERSION by extra { "0.102.3+1.21.2" }
val FABRIC_LOADER_VERSION by extra { "0.16.4" }
val FABRIC_API_VERSION by extra { "0.103.2+1.21.2" }

// This value can be set to null to disable Parchment.
val PARCHMENT_VERSION by extra { null }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.caffeinemc.mods.sodium.client.util;

import net.minecraft.util.RandomSource;

public interface WeightedRandomListExtension<T> {
T sodium$getQuick(RandomSource random);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public void update(ClientLevel level, ChunkRenderContext context) {

private void copyBiomeData(Level level, ChunkRenderContext context) {
var defaultValue = level.registryAccess()
.registryOrThrow(Registries.BIOME)
.getHolderOrThrow(Biomes.PLAINS);
.lookupOrThrow(Registries.BIOME)
.getOrThrow(Biomes.PLAINS);

for (int sectionX = 0; sectionX < 3; sectionX++) {
for (int sectionY = 0; sectionY < 3; sectionY++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package net.caffeinemc.mods.sodium.mixin.fabric.features.model;

import net.caffeinemc.mods.sodium.client.util.WeightedRandomListExtension;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.WeightedBakedModel;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.util.random.SimpleWeightedRandomList;
import net.minecraft.util.random.WeightedEntry;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
Expand All @@ -17,41 +19,18 @@
public class WeightedBakedModelMixin {
@Shadow
@Final
private List<WeightedEntry.Wrapper<BakedModel>> list;

@Shadow
@Final
private int totalWeight;

@Unique
private static <T extends WeightedEntry> T getAt(List<T> pool, int totalWeight) {
int i = 0;
int len = pool.size();

T weighted;

do {
if (i >= len) {
return null;
}

weighted = pool.get(i++);
totalWeight -= weighted.getWeight().asInt();
} while (totalWeight >= 0);

return weighted;
}
private SimpleWeightedRandomList<BakedModel> list;

/**
* @author JellySquid
* @reason Avoid excessive object allocations
*/
@Overwrite
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction face, RandomSource random) {
WeightedEntry.Wrapper<BakedModel> quad = getAt(this.list, Math.abs((int) random.nextLong()) % this.totalWeight);
WeightedEntry.Wrapper<BakedModel> model = ((WeightedRandomListExtension<WeightedEntry.Wrapper<BakedModel>>) list).sodium$getQuick(random);

if (quad != null) {
return quad.data()
if (model != null) {
return model.data()
.getQuads(state, face, random);
}

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

import com.google.common.collect.ImmutableList;
import net.caffeinemc.mods.sodium.client.util.WeightedRandomListExtension;
import net.minecraft.util.RandomSource;
import net.minecraft.util.random.WeightedEntry;
import net.minecraft.util.random.WeightedRandomList;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(WeightedRandomList.class)
public class WeightedRandomListMixin<E extends WeightedEntry> implements WeightedRandomListExtension<E> {
@Shadow
@Final
private ImmutableList<E> items;

@Shadow
@Final
private int totalWeight;

@Override
public E sodium$getQuick(RandomSource random) {
int randomValue = Math.abs((int) random.nextLong()) % this.totalWeight;

int i = 0;
int len = items.size();

E weighted;

do {
if (i >= len) {
return null;
}

weighted = items.get(i++);
randomValue -= weighted.getWeight().asInt();
} while (randomValue >= 0);

return weighted;
}
}
1 change: 1 addition & 0 deletions fabric/src/main/resources/sodium-fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"core.model.quad.BakedQuadMixin",
"features.model.MultiPartBakedModelMixin",
"features.model.WeightedBakedModelMixin",
"features.model.WeightedRandomListMixin",
"features.render.model.block.ModelBlockRendererMixin"
]
}

0 comments on commit b655ae8

Please sign in to comment.