Skip to content

Commit

Permalink
Port to 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
PepperCode1 committed Dec 27, 2024
1 parent 05ea0a7 commit 2107741
Show file tree
Hide file tree
Showing 22 changed files with 234 additions and 320 deletions.
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = true

# Fabric Properties
loom_version = 1.8.12
minecraft_version = 1.21.3
yarn_mappings = 1.21.3+build.2
loom_version = 1.9.2
minecraft_version = 1.21.4
yarn_mappings = 1.21.4+build.1
loader_version = 0.16.9

# Mod Properties
mod_version = 3.0.0
mod_minecraft_version = 1.21.3
mod_minecraft_version = 1.21.4
maven_group = me.pepperbell
archives_base_name = continuity

# Dependencies
fabric_version = 0.107.3+1.21.3
modmenu_version = 12.0.0-beta.1
fabric_version = 0.113.0+1.21.4
modmenu_version = 13.0.0-beta.1
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package me.pepperbell.continuity.api.client;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.minecraft.block.BlockState;
Expand All @@ -18,13 +16,7 @@ public interface QuadProcessor {
ProcessingResult processQuad(MutableQuadView quad, Sprite sprite, BlockRenderView blockView, BlockState appearanceState, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, int pass, ProcessingContext context);

interface ProcessingContext extends ProcessingDataProvider {
void addEmitterConsumer(Consumer<QuadEmitter> consumer);

void addMesh(Mesh mesh);

QuadEmitter getExtraQuadEmitter();

void markHasExtraQuads();
}

enum ProcessingResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class ContinuityConfig {
public final Option.BooleanOption connectedTextures = addOption(new Option.BooleanOption("connected_textures", true));
public final Option.BooleanOption emissiveTextures = addOption(new Option.BooleanOption("emissive_textures", true));
public final Option.BooleanOption customBlockLayers = addOption(new Option.BooleanOption("custom_block_layers", true));
public final Option.BooleanOption useManualCulling = addOption(new Option.BooleanOption("use_manual_culling", true));

public ContinuityConfig(File file) {
this.file = file;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Function;

import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import me.pepperbell.continuity.client.resource.BakedModelManagerBakeContext;
import me.pepperbell.continuity.client.resource.BakedModelManagerReloadExtension;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.block.entity.LoadedBlockEntityModels;
import net.minecraft.client.render.entity.model.LoadedEntityModels;
import net.minecraft.client.render.model.BakedModelManager;
import net.minecraft.client.render.model.ModelBaker;
import net.minecraft.client.render.model.SpriteAtlasManager;
Expand Down Expand Up @@ -54,11 +60,25 @@ abstract class BakedModelManagerMixin {
return original.thenRun(() -> continuity$reloadExtension = null);
}

@Inject(method = "bake(Lnet/minecraft/util/profiler/Profiler;Ljava/util/Map;Lnet/minecraft/client/render/model/ModelBaker;Lit/unimi/dsi/fastutil/objects/Object2IntMap;)Lnet/minecraft/client/render/model/BakedModelManager$BakingResult;", at = @At("HEAD"))
private void continuity$onHeadBake(Profiler profiler, Map<Identifier, SpriteAtlasManager.AtlasPreparation> preparations, ModelBaker bakery, Object2IntMap<BlockState> modelGroups, CallbackInfoReturnable<?> cir) {
@ModifyArg(method = "reload(Lnet/minecraft/resource/ResourceReloader$Synchronizer;Lnet/minecraft/resource/ResourceManager;Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;", slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/SpriteAtlasManager;reload(Lnet/minecraft/resource/ResourceManager;ILjava/util/concurrent/Executor;)Ljava/util/Map;")), at = @At(value = "INVOKE", target = "Ljava/util/concurrent/CompletableFuture;thenApplyAsync(Ljava/util/function/Function;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;", ordinal = 0), index = 0)
private Function<Void, Object> continuity$modifyFunction(Function<Void, Object> function) {
BakedModelManagerReloadExtension reloadExtension = continuity$reloadExtension;
if (reloadExtension != null) {
reloadExtension.beforeBaking(preparations);
return v -> {
BakedModelManagerBakeContext.THREAD_LOCAL.set(reloadExtension);
Object result = function.apply(v);
BakedModelManagerBakeContext.THREAD_LOCAL.remove();
return result;
};
}
return function;
}

@Inject(method = "bake(Lnet/minecraft/util/profiler/Profiler;Ljava/util/Map;Lnet/minecraft/client/render/model/ModelBaker;Lit/unimi/dsi/fastutil/objects/Object2IntMap;Lnet/minecraft/client/render/entity/model/LoadedEntityModels;Lnet/minecraft/client/render/block/entity/LoadedBlockEntityModels;)Lnet/minecraft/client/render/model/BakedModelManager$BakingResult;", at = @At("HEAD"))
private static void continuity$onHeadBake(Profiler profiler, final Map<Identifier, SpriteAtlasManager.AtlasPreparation> atlases, ModelBaker baker, Object2IntMap<BlockState> groups, LoadedEntityModels entityModels, LoadedBlockEntityModels blockEntityModels, CallbackInfoReturnable<Object> cir) {
BakedModelManagerBakeContext context = BakedModelManagerBakeContext.THREAD_LOCAL.get();
if (context != null) {
context.beforeBake(atlases);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package me.pepperbell.continuity.client.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

import me.pepperbell.continuity.client.resource.ModelWrappingHandler;
import net.minecraft.client.render.item.ItemRenderState;
import net.minecraft.client.render.model.BakedModel;

@Mixin(value = ItemRenderState.LayerRenderState.class, priority = -1000)
abstract class LayerRenderStateMixin {
@ModifyVariable(method = "setModel(Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/client/render/RenderLayer;)V", at = @At("HEAD"), argsOnly = true, ordinal = 0)
private BakedModel continuity$modifyBakedModel(BakedModel model) {
ModelWrappingHandler wrappingHandler = ModelWrappingHandler.getInstance();
if (wrappingHandler != null) {
return wrappingHandler.ensureWrapped(model);
}
return model;
}
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
package me.pepperbell.continuity.client.model;

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

import org.jetbrains.annotations.Nullable;

import me.pepperbell.continuity.api.client.QuadProcessor;
import me.pepperbell.continuity.client.config.ContinuityConfig;
import me.pepperbell.continuity.client.util.RenderUtil;
import me.pepperbell.continuity.impl.client.ProcessingContextImpl;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadTransform;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.WrapperBakedModel;
import net.minecraft.client.texture.Sprite;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.BlockRenderView;

public class CtmBakedModel extends ForwardingBakedModel {
public class CtmBakedModel extends WrapperBakedModel {
public static final int PASSES = 4;

protected final BlockState defaultState;
protected volatile Function<Sprite, QuadProcessors.Slice> defaultSliceFunc;

public CtmBakedModel(BakedModel wrapped, BlockState defaultState) {
this.wrapped = wrapped;
super(wrapped);
this.defaultState = defaultState;
}

@Override
public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
public void emitBlockQuads(QuadEmitter emitter, BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, Predicate<@Nullable Direction> cullTest) {
if (!ContinuityConfig.INSTANCE.connectedTextures.get()) {
super.emitBlockQuads(blockView, state, pos, randomSupplier, context);
super.emitBlockQuads(emitter, blockView, state, pos, randomSupplier, cullTest);
return;
}

ModelObjectsContainer container = ModelObjectsContainer.get();
if (!container.featureStates.getConnectedTexturesState().isEnabled()) {
super.emitBlockQuads(blockView, state, pos, randomSupplier, context);
super.emitBlockQuads(emitter, blockView, state, pos, randomSupplier, cullTest);
return;
}

CtmQuadTransform quadTransform = container.ctmQuadTransform;
if (quadTransform.isActive()) {
super.emitBlockQuads(blockView, state, pos, randomSupplier, context);
super.emitBlockQuads(emitter, blockView, state, pos, randomSupplier, cullTest);
return;
}

Expand All @@ -65,13 +69,13 @@ public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos
// especially if there is an actual use case for it.
BlockState appearanceState = state.getAppearance(blockView, pos, Direction.DOWN, state, pos);

quadTransform.prepare(blockView, appearanceState, state, pos, randomSupplier, context, ContinuityConfig.INSTANCE.useManualCulling.get(), getSliceFunc(appearanceState));
quadTransform.prepare(blockView, appearanceState, state, pos, randomSupplier, cullTest, getSliceFunc(appearanceState));

context.pushTransform(quadTransform);
super.emitBlockQuads(blockView, state, pos, randomSupplier, context);
context.popTransform();
emitter.pushTransform(quadTransform);
super.emitBlockQuads(emitter, blockView, state, pos, randomSupplier, cullTest);
emitter.popTransform();

quadTransform.processingContext.outputTo(context.getEmitter());
quadTransform.processingContext.outputTo(emitter);
quadTransform.reset();
}

Expand Down Expand Up @@ -100,23 +104,22 @@ protected Function<Sprite, QuadProcessors.Slice> getSliceFunc(BlockState state)
return QuadProcessors.getCache(state);
}

protected static class CtmQuadTransform implements RenderContext.QuadTransform {
protected static class CtmQuadTransform implements QuadTransform {
protected final ProcessingContextImpl processingContext = new ProcessingContextImpl();

protected BlockRenderView blockView;
protected BlockState appearanceState;
protected BlockState state;
protected BlockPos pos;
protected Supplier<Random> randomSupplier;
protected RenderContext renderContext;
protected boolean useManualCulling;
protected Predicate<@Nullable Direction> cullTest;
protected Function<Sprite, QuadProcessors.Slice> sliceFunc;

protected boolean active;

@Override
public boolean transform(MutableQuadView quad) {
if (useManualCulling && renderContext.isFaceCulled(quad.cullFace())) {
if (cullTest.test(quad.cullFace())) {
return false;
}

Expand Down Expand Up @@ -156,19 +159,16 @@ public boolean isActive() {
return active;
}

public void prepare(BlockRenderView blockView, BlockState appearanceState, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext renderContext, boolean useManualCulling, Function<Sprite, QuadProcessors.Slice> sliceFunc) {
public void prepare(BlockRenderView blockView, BlockState appearanceState, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, Predicate<@Nullable Direction> cullTest, Function<Sprite, QuadProcessors.Slice> sliceFunc) {
this.blockView = blockView;
this.appearanceState = appearanceState;
this.state = state;
this.pos = pos;
this.randomSupplier = randomSupplier;
this.renderContext = renderContext;
this.useManualCulling = useManualCulling;
this.cullTest = cullTest;
this.sliceFunc = sliceFunc;

active = true;

processingContext.prepare();
}

public void reset() {
Expand All @@ -177,8 +177,7 @@ public void reset() {
state = null;
pos = null;
randomSupplier = null;
renderContext = null;
useManualCulling = false;
cullTest = null;
sliceFunc = null;

active = false;
Expand Down
Loading

0 comments on commit 2107741

Please sign in to comment.