From fcd5d77b26264b63b05ebb482e4075cd994abe69 Mon Sep 17 00:00:00 2001 From: Adrien1106 Date: Wed, 28 Feb 2024 00:31:42 +0100 Subject: [PATCH] added item render support for athena blocks and some improved readability --- .../adrien1106/reframed/mixin/BlockMixin.java | 10 ++--- .../reframed/mixin/BlockRenderInfoMixin.java | 6 +-- .../mixin/compat/AthenaBakedModelMixin.java | 37 ++++++++++--------- .../AthenaConnectedBlockModelMixin.java | 6 +-- .../compat/AthenaWrappedGetterMixin.java | 8 ++-- 5 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/main/java/fr/adrien1106/reframed/mixin/BlockMixin.java b/src/main/java/fr/adrien1106/reframed/mixin/BlockMixin.java index ee3fe25..7e5f4d1 100644 --- a/src/main/java/fr/adrien1106/reframed/mixin/BlockMixin.java +++ b/src/main/java/fr/adrien1106/reframed/mixin/BlockMixin.java @@ -1,7 +1,7 @@ package fr.adrien1106.reframed.mixin; import com.llamalad7.mixinextras.sugar.Local; -import fr.adrien1106.reframed.block.ReFramedEntity; +import fr.adrien1106.reframed.util.ThemeableBlockEntity; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; @@ -21,20 +21,20 @@ public class BlockMixin { @Redirect(method = "shouldDrawSide", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;isOpaque()Z")) private static boolean isNeighborCamoOpaque(BlockState state, @Local(argsOnly = true) BlockView world, @Local(ordinal = 1, argsOnly = true) BlockPos pos) { BlockEntity block_entity = world.getBlockEntity(pos); - if (!(block_entity instanceof ReFramedEntity frame_entity)) return state.isOpaque(); + if (!(block_entity instanceof ThemeableBlockEntity frame_entity)) return state.isOpaque(); return frame_entity.getThemeState().isOpaque(); } @Redirect(method = "shouldDrawSide", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;isSideInvisible(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/Direction;)Z")) private static boolean isCamoInvisible(BlockState state, BlockState other_state, Direction direction, @Local(argsOnly = true) BlockView world, @Local(ordinal = 0, argsOnly = true) BlockPos pos, @Local(ordinal = 1, argsOnly = true) BlockPos other_pos) { - if (world.getBlockEntity(other_pos) instanceof ReFramedEntity entity) other_state = entity.getThemeState(); - if (world.getBlockEntity(pos) instanceof ReFramedEntity entity) state = entity.getThemeState(); + if (world.getBlockEntity(other_pos) instanceof ThemeableBlockEntity entity) other_state = entity.getThemeState(); + if (world.getBlockEntity(pos) instanceof ThemeableBlockEntity entity) state = entity.getThemeState(); return state.isSideInvisible(other_state, direction); } @Inject(method = "shouldDrawSide", at = @At(value = "RETURN", ordinal = 0), cancellable = true) private static void shouldDrawGlassCamoSide(BlockState state, BlockView world, BlockPos pos, Direction side, BlockPos other_pos, CallbackInfoReturnable cir, @Local(ordinal = 1) BlockState neighbor) { - if (!(world.getBlockEntity(pos) instanceof ReFramedEntity) && !(world.getBlockEntity(other_pos) instanceof ReFramedEntity)) return; + if (!(world.getBlockEntity(pos) instanceof ThemeableBlockEntity) && !(world.getBlockEntity(other_pos) instanceof ThemeableBlockEntity)) return; VoxelShape voxel_block = state.getCullingFace(world, pos, side); if (voxel_block.isEmpty()) { cir.setReturnValue(true); diff --git a/src/main/java/fr/adrien1106/reframed/mixin/BlockRenderInfoMixin.java b/src/main/java/fr/adrien1106/reframed/mixin/BlockRenderInfoMixin.java index 0e73ed7..cb1ffb4 100644 --- a/src/main/java/fr/adrien1106/reframed/mixin/BlockRenderInfoMixin.java +++ b/src/main/java/fr/adrien1106/reframed/mixin/BlockRenderInfoMixin.java @@ -1,7 +1,7 @@ package fr.adrien1106.reframed.mixin; import com.llamalad7.mixinextras.sugar.Local; -import fr.adrien1106.reframed.block.ReFramedEntity; +import fr.adrien1106.reframed.util.ThemeableBlockEntity; import net.fabricmc.fabric.impl.client.indigo.renderer.render.BlockRenderInfo; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -34,7 +34,7 @@ public abstract class BlockRenderInfoMixin { "getBlockLayer(Lnet/minecraft/block/BlockState;)Lnet/minecraft/client/render/RenderLayer;")) public BlockState prepareCamoLayer(BlockState state, @Local(argsOnly = true) BlockPos pos) { BlockEntity block_entity = MinecraftClient.getInstance().world.getBlockEntity(pos); - if (!(block_entity instanceof ReFramedEntity frame_entity)) return state; + if (!(block_entity instanceof ThemeableBlockEntity frame_entity)) return state; return frame_entity.getThemeState(); } @@ -43,7 +43,7 @@ public abstract class BlockRenderInfoMixin { cancellable = true) private void shouldDrawCamoFace(Direction face, CallbackInfoReturnable cir) { BlockEntity block_entity = MinecraftClient.getInstance().world.getBlockEntity(blockPos); - if (!(block_entity instanceof ReFramedEntity)) return; + if (!(block_entity instanceof ThemeableBlockEntity)) return; cir.setReturnValue(Block.shouldDrawSide(blockState, blockView, blockPos, face, searchPos.set(blockPos, face))); } } diff --git a/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaBakedModelMixin.java b/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaBakedModelMixin.java index b622908..03c8703 100644 --- a/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaBakedModelMixin.java +++ b/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaBakedModelMixin.java @@ -40,34 +40,35 @@ public abstract class AthenaBakedModelMixin implements DynamicBakedModel, BakedM */ @Override public BakedModel computeQuads(BlockRenderView level, BlockState state, BlockPos pos) { - if (level == null || pos == null) return this; - Map> face_quads = new HashMap<>(); - Renderer r = ReFramedClient.HELPER.getFabricRenderer(); QuadEmitter emitter = r.meshBuilder().getEmitter(); WrappedGetter getter = new WrappedGetter(level); Arrays.stream(Direction.values()).forEach(direction -> { face_quads.put(direction, new ArrayList<>()); - model.getQuads(getter, state, pos, direction).forEach(sprite -> face_quads.computeIfPresent(direction, (d, quads) -> { - Sprite texture = textures.get(sprite.sprite()); - if (texture == null) return quads; - emitter.square(direction, sprite.left(), sprite.bottom(), sprite.right(), sprite.top(), sprite.depth()); - int flag = MutableQuadView.BAKE_LOCK_UV; + (level == null || pos == null + ? model.getDefaultQuads(direction).get(direction) + : model.getQuads(getter, state, pos, direction)) + .forEach(sprite -> face_quads.computeIfPresent(direction, (d, quads) -> { + Sprite texture = textures.get(sprite.sprite()); + if (texture == null) return quads; + emitter.square(direction, sprite.left(), sprite.bottom(), sprite.right(), sprite.top(), sprite.depth()); - switch (sprite.rotation()) { - case CLOCKWISE_90 -> flag |= MutableQuadView.BAKE_ROTATE_90; - case CLOCKWISE_180 -> flag |= MutableQuadView.BAKE_ROTATE_180; - case COUNTERCLOCKWISE_90 -> flag |= MutableQuadView.BAKE_ROTATE_270; - } + int flag = MutableQuadView.BAKE_LOCK_UV; - emitter.spriteBake(texture, flag); - emitter.color(-1, -1, -1, -1); - quads.add(emitter.toBakedQuad(texture)); - return quads; - })); + switch (sprite.rotation()) { + case CLOCKWISE_90 -> flag |= MutableQuadView.BAKE_ROTATE_90; + case CLOCKWISE_180 -> flag |= MutableQuadView.BAKE_ROTATE_180; + case COUNTERCLOCKWISE_90 -> flag |= MutableQuadView.BAKE_ROTATE_270; + } + + emitter.spriteBake(texture, flag); + emitter.color(-1, -1, -1, -1); + quads.add(emitter.toBakedQuad(texture)); + return quads; + })); }); return new RebakedAthenaModel(face_quads); diff --git a/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaConnectedBlockModelMixin.java b/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaConnectedBlockModelMixin.java index 54742db..efc633b 100644 --- a/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaConnectedBlockModelMixin.java +++ b/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaConnectedBlockModelMixin.java @@ -3,7 +3,7 @@ package fr.adrien1106.reframed.mixin.compat; import earth.terrarium.athena.api.client.utils.AppearanceAndTintGetter; import earth.terrarium.athena.api.client.utils.CtmUtils; import earth.terrarium.athena.impl.client.models.ConnectedBlockModel; -import fr.adrien1106.reframed.block.ReFramedEntity; +import fr.adrien1106.reframed.util.ThemeableBlockEntity; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -22,8 +22,8 @@ public class AthenaConnectedBlockModelMixin { "Lnet/minecraft/util/math/Direction;)Z")) private boolean checkForCull(AppearanceAndTintGetter level, BlockState state, BlockPos pos, Direction direction) { // Always get all the textures unless its another block then use default behaviour - if (level.getBlockEntity(pos) instanceof ReFramedEntity - || level.getBlockEntity(pos.offset(direction)) instanceof ReFramedEntity) + if (level.getBlockEntity(pos) instanceof ThemeableBlockEntity + || level.getBlockEntity(pos.offset(direction)) instanceof ThemeableBlockEntity) return false; return CtmUtils.checkRelative(level, state, pos, direction); } diff --git a/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaWrappedGetterMixin.java b/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaWrappedGetterMixin.java index 24632f3..63781de 100644 --- a/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaWrappedGetterMixin.java +++ b/src/main/java/fr/adrien1106/reframed/mixin/compat/AthenaWrappedGetterMixin.java @@ -1,7 +1,7 @@ package fr.adrien1106.reframed.mixin.compat; import earth.terrarium.athena.api.client.fabric.WrappedGetter; -import fr.adrien1106.reframed.block.ReFramedEntity; +import fr.adrien1106.reframed.util.ThemeableBlockEntity; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockRenderView; @@ -20,7 +20,7 @@ public class AthenaWrappedGetterMixin { @Inject(method = "getBlockState", at = @At(value = "HEAD"), cancellable = true) private void getCamoState(BlockPos pos, CallbackInfoReturnable cir) { - if (!(getter.getBlockEntity(pos) instanceof ReFramedEntity framed_entity)) return; + if (!(getter.getBlockEntity(pos) instanceof ThemeableBlockEntity framed_entity)) return; cir.setReturnValue(framed_entity.getThemeState()); } @@ -30,7 +30,7 @@ public class AthenaWrappedGetterMixin { "getBlockState(Lnet/minecraft/util/math/BlockPos;)" + "Lnet/minecraft/block/BlockState;")) private BlockState appearanceCamoState(BlockRenderView world, BlockPos pos) { - if (world.getBlockEntity(pos) instanceof ReFramedEntity framed_entity) return framed_entity.getThemeState(); + if (world.getBlockEntity(pos) instanceof ThemeableBlockEntity framed_entity) return framed_entity.getThemeState(); return world.getBlockState(pos); } @@ -39,7 +39,7 @@ public class AthenaWrappedGetterMixin { "getBlockState(Lnet/minecraft/util/math/BlockPos;)" + "Lnet/minecraft/block/BlockState;")) private BlockState queryCamoState(BlockRenderView world, BlockPos pos) { - if (world.getBlockEntity(pos) instanceof ReFramedEntity framed_entity) return framed_entity.getThemeState(); + if (world.getBlockEntity(pos) instanceof ThemeableBlockEntity framed_entity) return framed_entity.getThemeState(); return world.getBlockState(pos); } }