added item render support for athena blocks and some improved readability
This commit is contained in:
parent
0a050a2abc
commit
fcd5d77b26
@ -1,7 +1,7 @@
|
|||||||
package fr.adrien1106.reframed.mixin;
|
package fr.adrien1106.reframed.mixin;
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.sugar.Local;
|
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.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
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"))
|
@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) {
|
private static boolean isNeighborCamoOpaque(BlockState state, @Local(argsOnly = true) BlockView world, @Local(ordinal = 1, argsOnly = true) BlockPos pos) {
|
||||||
BlockEntity block_entity = world.getBlockEntity(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();
|
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"))
|
@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) {
|
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(other_pos) instanceof ThemeableBlockEntity entity) other_state = entity.getThemeState();
|
||||||
if (world.getBlockEntity(pos) instanceof ReFramedEntity entity) state = entity.getThemeState();
|
if (world.getBlockEntity(pos) instanceof ThemeableBlockEntity entity) state = entity.getThemeState();
|
||||||
return state.isSideInvisible(other_state, direction);
|
return state.isSideInvisible(other_state, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "shouldDrawSide", at = @At(value = "RETURN", ordinal = 0), cancellable = true)
|
@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<Boolean> cir, @Local(ordinal = 1) BlockState neighbor) {
|
private static void shouldDrawGlassCamoSide(BlockState state, BlockView world, BlockPos pos, Direction side, BlockPos other_pos, CallbackInfoReturnable<Boolean> 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);
|
VoxelShape voxel_block = state.getCullingFace(world, pos, side);
|
||||||
if (voxel_block.isEmpty()) {
|
if (voxel_block.isEmpty()) {
|
||||||
cir.setReturnValue(true);
|
cir.setReturnValue(true);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package fr.adrien1106.reframed.mixin;
|
package fr.adrien1106.reframed.mixin;
|
||||||
|
|
||||||
import com.llamalad7.mixinextras.sugar.Local;
|
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.fabricmc.fabric.impl.client.indigo.renderer.render.BlockRenderInfo;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
@ -34,7 +34,7 @@ public abstract class BlockRenderInfoMixin {
|
|||||||
"getBlockLayer(Lnet/minecraft/block/BlockState;)Lnet/minecraft/client/render/RenderLayer;"))
|
"getBlockLayer(Lnet/minecraft/block/BlockState;)Lnet/minecraft/client/render/RenderLayer;"))
|
||||||
public BlockState prepareCamoLayer(BlockState state, @Local(argsOnly = true) BlockPos pos) {
|
public BlockState prepareCamoLayer(BlockState state, @Local(argsOnly = true) BlockPos pos) {
|
||||||
BlockEntity block_entity = MinecraftClient.getInstance().world.getBlockEntity(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();
|
return frame_entity.getThemeState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ public abstract class BlockRenderInfoMixin {
|
|||||||
cancellable = true)
|
cancellable = true)
|
||||||
private void shouldDrawCamoFace(Direction face, CallbackInfoReturnable<Boolean> cir) {
|
private void shouldDrawCamoFace(Direction face, CallbackInfoReturnable<Boolean> cir) {
|
||||||
BlockEntity block_entity = MinecraftClient.getInstance().world.getBlockEntity(blockPos);
|
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)));
|
cir.setReturnValue(Block.shouldDrawSide(blockState, blockView, blockPos, face, searchPos.set(blockPos, face)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,17 +40,18 @@ public abstract class AthenaBakedModelMixin implements DynamicBakedModel, BakedM
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public BakedModel computeQuads(BlockRenderView level, BlockState state, BlockPos pos) {
|
public BakedModel computeQuads(BlockRenderView level, BlockState state, BlockPos pos) {
|
||||||
if (level == null || pos == null) return this;
|
|
||||||
|
|
||||||
Map<Direction, List<BakedQuad>> face_quads = new HashMap<>();
|
Map<Direction, List<BakedQuad>> face_quads = new HashMap<>();
|
||||||
|
|
||||||
Renderer r = ReFramedClient.HELPER.getFabricRenderer();
|
Renderer r = ReFramedClient.HELPER.getFabricRenderer();
|
||||||
QuadEmitter emitter = r.meshBuilder().getEmitter();
|
QuadEmitter emitter = r.meshBuilder().getEmitter();
|
||||||
|
|
||||||
WrappedGetter getter = new WrappedGetter(level);
|
WrappedGetter getter = new WrappedGetter(level);
|
||||||
Arrays.stream(Direction.values()).forEach(direction -> {
|
Arrays.stream(Direction.values()).forEach(direction -> {
|
||||||
face_quads.put(direction, new ArrayList<>());
|
face_quads.put(direction, new ArrayList<>());
|
||||||
model.getQuads(getter, state, pos, direction).forEach(sprite -> face_quads.computeIfPresent(direction, (d, quads) -> {
|
|
||||||
|
(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());
|
Sprite texture = textures.get(sprite.sprite());
|
||||||
if (texture == null) return quads;
|
if (texture == null) return quads;
|
||||||
emitter.square(direction, sprite.left(), sprite.bottom(), sprite.right(), sprite.top(), sprite.depth());
|
emitter.square(direction, sprite.left(), sprite.bottom(), sprite.right(), sprite.top(), sprite.depth());
|
||||||
|
@ -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.AppearanceAndTintGetter;
|
||||||
import earth.terrarium.athena.api.client.utils.CtmUtils;
|
import earth.terrarium.athena.api.client.utils.CtmUtils;
|
||||||
import earth.terrarium.athena.impl.client.models.ConnectedBlockModel;
|
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.block.BlockState;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
@ -22,8 +22,8 @@ public class AthenaConnectedBlockModelMixin {
|
|||||||
"Lnet/minecraft/util/math/Direction;)Z"))
|
"Lnet/minecraft/util/math/Direction;)Z"))
|
||||||
private boolean checkForCull(AppearanceAndTintGetter level, BlockState state, BlockPos pos, Direction direction) {
|
private boolean checkForCull(AppearanceAndTintGetter level, BlockState state, BlockPos pos, Direction direction) {
|
||||||
// Always get all the textures unless its another block then use default behaviour
|
// Always get all the textures unless its another block then use default behaviour
|
||||||
if (level.getBlockEntity(pos) instanceof ReFramedEntity
|
if (level.getBlockEntity(pos) instanceof ThemeableBlockEntity
|
||||||
|| level.getBlockEntity(pos.offset(direction)) instanceof ReFramedEntity)
|
|| level.getBlockEntity(pos.offset(direction)) instanceof ThemeableBlockEntity)
|
||||||
return false;
|
return false;
|
||||||
return CtmUtils.checkRelative(level, state, pos, direction);
|
return CtmUtils.checkRelative(level, state, pos, direction);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package fr.adrien1106.reframed.mixin.compat;
|
package fr.adrien1106.reframed.mixin.compat;
|
||||||
|
|
||||||
import earth.terrarium.athena.api.client.fabric.WrappedGetter;
|
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.block.BlockState;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.BlockRenderView;
|
import net.minecraft.world.BlockRenderView;
|
||||||
@ -20,7 +20,7 @@ public class AthenaWrappedGetterMixin {
|
|||||||
|
|
||||||
@Inject(method = "getBlockState", at = @At(value = "HEAD"), cancellable = true)
|
@Inject(method = "getBlockState", at = @At(value = "HEAD"), cancellable = true)
|
||||||
private void getCamoState(BlockPos pos, CallbackInfoReturnable<BlockState> cir) {
|
private void getCamoState(BlockPos pos, CallbackInfoReturnable<BlockState> cir) {
|
||||||
if (!(getter.getBlockEntity(pos) instanceof ReFramedEntity framed_entity)) return;
|
if (!(getter.getBlockEntity(pos) instanceof ThemeableBlockEntity framed_entity)) return;
|
||||||
cir.setReturnValue(framed_entity.getThemeState());
|
cir.setReturnValue(framed_entity.getThemeState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ public class AthenaWrappedGetterMixin {
|
|||||||
"getBlockState(Lnet/minecraft/util/math/BlockPos;)" +
|
"getBlockState(Lnet/minecraft/util/math/BlockPos;)" +
|
||||||
"Lnet/minecraft/block/BlockState;"))
|
"Lnet/minecraft/block/BlockState;"))
|
||||||
private BlockState appearanceCamoState(BlockRenderView world, BlockPos pos) {
|
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);
|
return world.getBlockState(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ public class AthenaWrappedGetterMixin {
|
|||||||
"getBlockState(Lnet/minecraft/util/math/BlockPos;)" +
|
"getBlockState(Lnet/minecraft/util/math/BlockPos;)" +
|
||||||
"Lnet/minecraft/block/BlockState;"))
|
"Lnet/minecraft/block/BlockState;"))
|
||||||
private BlockState queryCamoState(BlockRenderView world, BlockPos pos) {
|
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);
|
return world.getBlockState(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user