Skip to content

Commit

Permalink
1.21.4 Port
Browse files Browse the repository at this point in the history
  • Loading branch information
FoundationGames committed Jan 18, 2025
1 parent 911d8ce commit 8e6fc28
Show file tree
Hide file tree
Showing 27 changed files with 273 additions and 146 deletions.
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
org.gradle.jvmargs=-Xmx2G

minecraft_version=1.21.2
yarn_mappings=1.21.2+build.1
loader_version=0.16.7
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.8
loader_version=0.16.10

fabric_version=0.106.1+1.21.2
fabric_version=0.114.3+1.21.4

mod_version = 0.11+1.21.2
mod_version = 0.11+1.21.4
maven_group = foundationgames
archives_base_name = enhancedblockentities

modmenu_version=12.0.0-beta.1
sodium_version=mc1.21.3-0.6.0-fabric
modmenu_version=13.0.0
sodium_version=mc1.21.4-0.6.6-fabric
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public static void setupRRPChests() {
ResourceUtil.addDoubleChestModels("christmas_left", "christmas_right","christmas_chest", p);
ResourceUtil.addSingleChestModels("ender", "ender_chest", p);

ResourceUtil.addChestItemModel(Identifier.of("models/item/chest.json"), "chest_center", p);
ResourceUtil.addChestItemModel(Identifier.of("models/item/trapped_chest.json"), "trapped_chest_center", p);
ResourceUtil.addChestItemDefinition("chest", "chest_center", p);
ResourceUtil.addChestItemDefinition("trapped_chest", "trapped_chest_center", p);
ResourceUtil.addParentModel("block/ender_chest_center", Identifier.of("item/ender_chest"), p);

p.addDirBlockSprites("entity/chest", "entity/chest/");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package foundationgames.enhancedblockentities;

import foundationgames.enhancedblockentities.client.model.ModelIdentifiers;
import foundationgames.enhancedblockentities.client.model.item.EBEIsChristmasProperty;
import foundationgames.enhancedblockentities.client.render.SignRenderManager;
import foundationgames.enhancedblockentities.client.resource.template.TemplateLoader;
import foundationgames.enhancedblockentities.config.EBEConfig;
import foundationgames.enhancedblockentities.util.DateUtil;
import foundationgames.enhancedblockentities.util.EBEUtil;
import foundationgames.enhancedblockentities.util.ResourceUtil;
import foundationgames.enhancedblockentities.util.WorldUtil;
Expand All @@ -13,7 +13,7 @@
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.client.render.item.property.bool.BooleanProperties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -45,12 +45,13 @@ public void onInitializeClient() {
init.getEntrypoint().accept((Runnable) EnhancedBlockEntities::load);
}

BooleanProperties.ID_MAPPER.put(EBEUtil.id("ebe_is_christmas"), EBEIsChristmasProperty.CODEC);

WorldRenderEvents.END.register(SignRenderManager::endFrame);
ClientTickEvents.END_WORLD_TICK.register(WorldUtil.EVENT_LISTENER);

ModelIdentifiers.init();
EBESetup.setupResourceProviders();
ModelPredicateProviderRegistry.register(EBEUtil.id("is_christmas"), (stack, world, entity, seed) -> DateUtil.isChristmas() ? 1 : 0);

load();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package foundationgames.enhancedblockentities.client.model;

import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
import net.fabricmc.fabric.api.renderer.v1.Renderer;
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.render.model.json.ModelOverrideList;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.texture.Sprite;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.BlockRenderView;
import org.jetbrains.annotations.Nullable;

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

public class DynamicBakedModel implements BakedModel, FabricBakedModel {
Expand All @@ -45,14 +43,13 @@ public boolean isVanillaAdapter() {
}

@Override
public void emitBlockQuads(BlockRenderView view, BlockState state, BlockPos blockPos, Supplier<Random> rng, RenderContext context) {
QuadEmitter emitter = context.getEmitter();
public void emitBlockQuads(QuadEmitter emitter, BlockRenderView view, BlockState state, BlockPos pos, Supplier<Random> rng, Predicate<@Nullable Direction> cullTest) {
RenderMaterial mat = null;

var indices = this.activeModelIndices.get();
var models = this.displayedModels.get();

getSelector().writeModelIndices(view, state, blockPos, rng, context, indices);
getSelector().writeModelIndices(view, state, pos, rng, indices);
for (int i = 0; i < indices.length; i++) {
int modelIndex = indices[i];

Expand All @@ -63,9 +60,9 @@ public void emitBlockQuads(BlockRenderView view, BlockState state, BlockPos bloc
}
}

var renderer = RendererAccess.INSTANCE.getRenderer();
var renderer = Renderer.get();
if (renderer != null) {
mat = renderer.materialById(RenderMaterial.MATERIAL_STANDARD);
mat = renderer.materialById(RenderMaterial.STANDARD_ID);
}

for (int i = 0; i <= 6; i++) {
Expand All @@ -79,11 +76,6 @@ public void emitBlockQuads(BlockRenderView view, BlockState state, BlockPos bloc
}
}

@Override
public void emitItemQuads(ItemStack itemStack, Supplier<Random> supplier, RenderContext renderContext) {
// no
}

@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction face, Random random) {
return models[0].getQuads(state, face, random);
Expand All @@ -104,11 +96,6 @@ public boolean isSideLit() {
return false;
}

@Override
public boolean isBuiltin() {
return false;
}

@Override
public Sprite getParticleSprite() {
return models[getSelector().getParticleModelIndex()].getParticleSprite();
Expand All @@ -119,11 +106,6 @@ public ModelTransformation getTransformation() {
return null;
}

@Override
public ModelOverrideList getOverrides() {
return null;
}

public BakedModel[] getModels() {
return models;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package foundationgames.enhancedblockentities.client.model;

import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelResolver;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelModifier;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

import java.util.function.Supplier;

public class DynamicModelProvidingPlugin implements ModelLoadingPlugin, ModelResolver {
public class DynamicModelProvidingPlugin implements ModelLoadingPlugin, ModelModifier.OnLoad {
private final Supplier<DynamicUnbakedModel> model;
private final Identifier id;

Expand All @@ -19,12 +19,12 @@ public DynamicModelProvidingPlugin(Identifier id, Supplier<DynamicUnbakedModel>

@Override
public void initialize(ModelLoadingPlugin.Context ctx) {
ctx.resolveModel().register(this);
ctx.modifyModelOnLoad().register(this);
}

@Override
public @Nullable UnbakedModel resolveModel(ModelResolver.Context ctx) {
if (ctx.id().equals(this.id)) return this.model.get();
return null;
public @Nullable UnbakedModel modifyModelOnLoad(@Nullable UnbakedModel model, ModelModifier.OnLoad.Context context) {
if (context.id().equals(this.id)) return this.model.get();
return model;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.Baker;
import net.minecraft.client.render.model.ModelBakeSettings;
import net.minecraft.client.render.model.ModelTextures;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

import java.util.function.Function;

public class DynamicUnbakedModel implements UnbakedModel {
private final Identifier[] models;
private final ModelSelector selector;
Expand All @@ -31,10 +29,10 @@ public void resolve(Resolver resolver) {
}

@Override
public @Nullable BakedModel bake(Baker baker, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer) {
public @Nullable BakedModel bake(ModelTextures textures, Baker baker, ModelBakeSettings settings, boolean ambientOcclusion, boolean isSideLit, ModelTransformation transformation) {
BakedModel[] baked = new BakedModel[models.length];
for (int i = 0; i < models.length; i++) {
baked[i] = baker.bake(models[i], rotationContainer);
baked[i] = baker.bake(models[i], settings);
}
return new DynamicBakedModel(baked, selector, effects);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import foundationgames.enhancedblockentities.util.DateUtil;
import foundationgames.enhancedblockentities.util.duck.AppearanceStateHolder;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.BlockRenderView;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -18,7 +16,7 @@ public abstract class ModelSelector {

public static final ModelSelector STATE_HOLDER_SELECTOR = new ModelSelector() {
@Override
public void writeModelIndices(BlockRenderView view, BlockState state, BlockPos pos, Supplier<Random> rand, @Nullable RenderContext ctx, int[] indices) {
public void writeModelIndices(BlockRenderView view, BlockState state, BlockPos pos, Supplier<Random> rand, int[] indices) {
if (view.getBlockEntity(pos) instanceof AppearanceStateHolder stateHolder) {
indices[0] = stateHolder.getModelState();
return;
Expand All @@ -36,7 +34,7 @@ public int getParticleModelIndex() {
}

@Override
public void writeModelIndices(BlockRenderView view, BlockState state, BlockPos pos, Supplier<Random> rand, @Nullable RenderContext ctx, int[] indices) {
public void writeModelIndices(BlockRenderView view, BlockState state, BlockPos pos, Supplier<Random> rand, int[] indices) {
if (view.getBlockEntity(pos) instanceof AppearanceStateHolder stateHolder) {
indices[0] = stateHolder.getModelState() + this.getParticleModelIndex();
return;
Expand All @@ -53,7 +51,7 @@ public int getParticleModelIndex() {
return 0;
}

public abstract void writeModelIndices(BlockRenderView view, BlockState state, BlockPos pos, Supplier<Random> rand, @Nullable RenderContext ctx, int[] indices);
public abstract void writeModelIndices(BlockRenderView view, BlockState state, BlockPos pos, Supplier<Random> rand, int[] indices);

public final int id;
public final int displayedModelCount;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package foundationgames.enhancedblockentities.client.model.item;

import com.mojang.serialization.MapCodec;
import foundationgames.enhancedblockentities.util.DateUtil;
import net.minecraft.client.render.item.property.bool.BooleanProperty;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ModelTransformationMode;
import org.jetbrains.annotations.Nullable;

public record EBEIsChristmasProperty() implements BooleanProperty {
public static final MapCodec<EBEIsChristmasProperty> CODEC = MapCodec.unit(new EBEIsChristmasProperty());

@Override
public boolean getValue(ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity user, int seed, ModelTransformationMode modelTransformationMode) {
return DateUtil.isChristmas();
}

@Override
public MapCodec<EBEIsChristmasProperty> getCodec() {
return CODEC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import foundationgames.enhancedblockentities.client.model.ModelIdentifiers;
import foundationgames.enhancedblockentities.client.model.ModelSelector;
import foundationgames.enhancedblockentities.util.duck.AppearanceStateHolder;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.block.BlockState;
import net.minecraft.block.DecoratedPotPattern;
import net.minecraft.block.DecoratedPotPatterns;
Expand All @@ -16,7 +15,6 @@
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.BlockRenderView;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -58,7 +56,7 @@ public Identifier[] createModelIDs() {
}

@Override
public void writeModelIndices(BlockRenderView view, BlockState state, BlockPos pos, Supplier<Random> rand, @Nullable RenderContext ctx, int[] indices) {
public void writeModelIndices(BlockRenderView view, BlockState state, BlockPos pos, Supplier<Random> rand, int[] indices) {
final int patternCount = potteryPatterns.size();

indices[0] = IDX_BASE_POT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import foundationgames.enhancedblockentities.EnhancedBlockEntities;
import foundationgames.enhancedblockentities.config.EBEConfig;
import foundationgames.enhancedblockentities.mixin.SignBlockEntityRenderAccessor;
import foundationgames.enhancedblockentities.mixin.AbstractSignBlockEntityRenderAccessor;
import foundationgames.enhancedblockentities.util.duck.AppearanceStateHolder;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
Expand Down Expand Up @@ -33,7 +33,7 @@ public interface BlockEntityRenderCondition {
SignRenderManager.renderedSigns++;
return playerDistance < 80 + Math.max(0, 580 - (SignRenderManager.getRenderedSignAmount() * 0.7));
}
double dist = SignBlockEntityRenderAccessor.enhanced_bes$getRenderDistance();
double dist = AbstractSignBlockEntityRenderAccessor.enhanced_bes$getRenderDistance();
Vec3d blockPos = Vec3d.ofCenter(entity.getPos());
Vec3d playerPos = MinecraftClient.getInstance().player.getPos();
if (config.signTextRendering.equals("most")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void render(BlockEntityRenderer<BlockEntity> renderer, BlockEntity blockE
LidOpenable chest = getLidAnimationHolder(blockEntity, tickDelta);
matrices.translate(0.5f, 0, 0.5f);
Direction dir = blockEntity.getCachedState().get(ChestBlock.FACING);
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180 - dir.asRotation()));
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180 - EBEUtil.angle(dir)));
matrices.translate(-0.5f, 0, -0.5f);
float yPiv = 9f / 16;
float zPiv = 15f / 16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void render(BlockEntityRenderer<BlockEntity> renderer, BlockEntity blockE
var dir = pot.getHorizontalFacing();

matrices.translate(0.5f, 0, 0.5f);
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180 - dir.asRotation()));
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180 - EBEUtil.angle(dir)));
matrices.translate(-0.5f, 0, -0.5f);

var wobbleType = pot.lastWobbleType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package foundationgames.enhancedblockentities.client.render.entity;

import foundationgames.enhancedblockentities.client.render.BlockEntityRendererOverride;
import foundationgames.enhancedblockentities.mixin.AbstractSignBlockEntityRenderAccessor;
import foundationgames.enhancedblockentities.mixin.SignBlockEntityRenderAccessor;
import net.minecraft.block.AbstractSignBlock;
import net.minecraft.block.entity.BlockEntity;
Expand All @@ -14,13 +15,14 @@ public SignBlockEntityRendererOverride() {}

@Override
public void render(BlockEntityRenderer<BlockEntity> renderer, BlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
if (blockEntity instanceof SignBlockEntity entity) {
if (blockEntity instanceof SignBlockEntity entity) {
var state = entity.getCachedState();
AbstractSignBlock block = (AbstractSignBlock) state.getBlock();
var textRenderer = (SignBlockEntityRenderAccessor) renderer;
textRenderer.enhanced_bes$setAngles(matrices, -block.getRotationDegrees(state), state);
textRenderer.enhanced_bes$renderText(entity.getPos(), entity.getFrontText(), matrices, vertexConsumers, light, entity.getTextLineHeight(), entity.getMaxTextWidth(), true);
textRenderer.enhanced_bes$renderText(entity.getPos(), entity.getBackText(), matrices, vertexConsumers, light, entity.getTextLineHeight(), entity.getMaxTextWidth(), false);
var sign = (SignBlockEntityRenderAccessor) renderer;
var aSign = (AbstractSignBlockEntityRenderAccessor) renderer;
sign.enhanced_bes$applyTransforms(matrices, -block.getRotationDegrees(state), state);
aSign.enhanced_bes$renderText(entity.getPos(), entity.getFrontText(), matrices, vertexConsumers, light, entity.getTextLineHeight(), entity.getMaxTextWidth(), true);
aSign.enhanced_bes$renderText(entity.getPos(), entity.getBackText(), matrices, vertexConsumers, light, entity.getTextLineHeight(), entity.getMaxTextWidth(), false);
}
}
}
Loading

0 comments on commit 8e6fc28

Please sign in to comment.