Double frames #6
@ -6,5 +6,5 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraft.world.BlockRenderView;
|
import net.minecraft.world.BlockRenderView;
|
||||||
|
|
||||||
public interface DynamicBakedModel {
|
public interface DynamicBakedModel {
|
||||||
BakedModel computeQuads(BlockRenderView level, BlockState state, BlockPos pos);
|
BakedModel computeQuads(BlockRenderView level, BlockState state, BlockPos pos, int theme_index);
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel {
|
|||||||
}
|
}
|
||||||
if(theme.getBlock() == Blocks.BARRIER) return;
|
if(theme.getBlock() == Blocks.BARRIER) return;
|
||||||
|
|
||||||
CamoAppearance camo = tam.getCamoAppearance(world, theme, pos);
|
CamoAppearance camo = tam.getCamoAppearance(world, theme, pos, theme_index);
|
||||||
long seed = theme.getRenderingSeed(pos);
|
long seed = theme.getRenderingSeed(pos);
|
||||||
int model_id = 0;
|
int model_id = 0;
|
||||||
if (camo instanceof WeightedComputedAppearance wca) model_id = wca.getAppearanceIndex(seed);
|
if (camo instanceof WeightedComputedAppearance wca) model_id = wca.getAppearanceIndex(seed);
|
||||||
@ -124,7 +124,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel {
|
|||||||
int tint;
|
int tint;
|
||||||
BlockState theme = ReFramedEntity.readStateFromItem(stack, theme_index);
|
BlockState theme = ReFramedEntity.readStateFromItem(stack, theme_index);
|
||||||
if(!theme.isAir()) {
|
if(!theme.isAir()) {
|
||||||
nbtAppearance = tam.getCamoAppearance(null, theme, null);
|
nbtAppearance = tam.getCamoAppearance(null, theme, null, theme_index);
|
||||||
tint = 0xFF000000 | ((MinecraftAccessor) MinecraftClient.getInstance()).getItemColors().getColor(new ItemStack(theme.getBlock()), 0);
|
tint = 0xFF000000 | ((MinecraftAccessor) MinecraftClient.getInstance()).getItemColors().getColor(new ItemStack(theme.getBlock()), 0);
|
||||||
} else {
|
} else {
|
||||||
nbtAppearance = tam.getDefaultAppearance(theme_index);
|
nbtAppearance = tam.getDefaultAppearance(theme_index);
|
||||||
|
@ -74,12 +74,12 @@ public class CamoAppearanceManager {
|
|||||||
return appearance == 2 ? accent_appearance: default_appearance;
|
return appearance == 2 ? accent_appearance: default_appearance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CamoAppearance getCamoAppearance(BlockRenderView world, BlockState state, BlockPos pos) {
|
public CamoAppearance getCamoAppearance(BlockRenderView world, BlockState state, BlockPos pos, int theme_index) {
|
||||||
BakedModel model = MinecraftClient.getInstance().getBlockRenderManager().getModel(state);
|
BakedModel model = MinecraftClient.getInstance().getBlockRenderManager().getModel(state);
|
||||||
|
|
||||||
// add support for connected textures and more generally any compatible models injected so that they return baked quads
|
// add support for connected textures and more generally any compatible models injected so that they return baked quads
|
||||||
if (model instanceof DynamicBakedModel dynamic_model) {
|
if (model instanceof DynamicBakedModel dynamic_model) {
|
||||||
return computeAppearance(dynamic_model.computeQuads(world, state, pos), state);
|
return computeAppearance(dynamic_model.computeQuads(world, state, pos, theme_index), state);
|
||||||
}
|
}
|
||||||
return appearanceCache.computeIfAbsent(state, block_state -> computeAppearance(model, block_state));
|
return appearanceCache.computeIfAbsent(state, block_state -> computeAppearance(model, block_state));
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import earth.terrarium.athena.api.client.models.AthenaBlockModel;
|
|||||||
import fr.adrien1106.reframed.client.ReFramedClient;
|
import fr.adrien1106.reframed.client.ReFramedClient;
|
||||||
import fr.adrien1106.reframed.client.model.DynamicBakedModel;
|
import fr.adrien1106.reframed.client.model.DynamicBakedModel;
|
||||||
import fr.adrien1106.reframed.compat.RebakedAthenaModel;
|
import fr.adrien1106.reframed.compat.RebakedAthenaModel;
|
||||||
|
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.Renderer;
|
import net.fabricmc.fabric.api.renderer.v1.Renderer;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
|
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
|
||||||
@ -39,7 +40,7 @@ public abstract class AthenaBakedModelMixin implements DynamicBakedModel, BakedM
|
|||||||
* @return - the rebakedmodel containing the computed quads
|
* @return - the rebakedmodel containing the computed quads
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public BakedModel computeQuads(BlockRenderView level, BlockState state, BlockPos pos) {
|
public BakedModel computeQuads(BlockRenderView level, BlockState state, BlockPos pos, int theme_index) {
|
||||||
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();
|
||||||
@ -50,7 +51,12 @@ public abstract class AthenaBakedModelMixin implements DynamicBakedModel, BakedM
|
|||||||
|
|
||||||
(level == null || pos == null
|
(level == null || pos == null
|
||||||
? model.getDefaultQuads(direction).get(direction)
|
? model.getDefaultQuads(direction).get(direction)
|
||||||
: model.getQuads(getter, state, pos, direction))
|
: model.getQuads(
|
||||||
|
getter,
|
||||||
|
level.getBlockEntity(pos) instanceof ThemeableBlockEntity framed_entity
|
||||||
|
? framed_entity.getTheme(theme_index)
|
||||||
|
: state, pos, direction)
|
||||||
|
)
|
||||||
.forEach(sprite -> face_quads.computeIfPresent(direction, (d, quads) -> {
|
.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;
|
||||||
|
@ -1,46 +1,30 @@
|
|||||||
package fr.adrien1106.reframed.mixin.compat;
|
package fr.adrien1106.reframed.mixin.compat;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
import earth.terrarium.athena.api.client.fabric.WrappedGetter;
|
import earth.terrarium.athena.api.client.fabric.WrappedGetter;
|
||||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
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;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
@Mixin(WrappedGetter.class)
|
@Mixin(WrappedGetter.class)
|
||||||
public class AthenaWrappedGetterMixin {
|
public class AthenaWrappedGetterMixin {
|
||||||
|
|
||||||
// TODO return only the state that might be of interest
|
|
||||||
@Shadow @Final private BlockRenderView getter;
|
|
||||||
|
|
||||||
@Inject(method = "getBlockState", at = @At(value = "HEAD"), cancellable = true)
|
|
||||||
private void getCamoState(BlockPos pos, CallbackInfoReturnable<BlockState> cir) {
|
|
||||||
if (!(getter.getBlockEntity(pos) instanceof ThemeableBlockEntity framed_entity)) return;
|
|
||||||
cir.setReturnValue(framed_entity.getTheme(1)); // TODO theme
|
|
||||||
}
|
|
||||||
|
|
||||||
@Redirect(method = "getAppearance(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;)" +
|
|
||||||
"Lnet/minecraft/block/BlockState;",
|
|
||||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/BlockRenderView;" +
|
|
||||||
"getBlockState(Lnet/minecraft/util/math/BlockPos;)" +
|
|
||||||
"Lnet/minecraft/block/BlockState;"))
|
|
||||||
private BlockState appearanceCamoState(BlockRenderView world, BlockPos pos) {
|
|
||||||
if (world.getBlockEntity(pos) instanceof ThemeableBlockEntity framed_entity) return framed_entity.getTheme(1); // TODO theme
|
|
||||||
return world.getBlockState(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Redirect(method = "query",
|
@Redirect(method = "query",
|
||||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/BlockRenderView;" +
|
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/BlockRenderView;" +
|
||||||
"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, @Local(argsOnly = true) BlockState reference_state) {
|
||||||
if (world.getBlockEntity(pos) instanceof ThemeableBlockEntity framed_entity) return framed_entity.getTheme(1); // TODO theme
|
// get Any that will connect or return any other (/!\ isOf is an uncertain check)
|
||||||
|
if (world.getBlockEntity(pos) instanceof ThemeableBlockEntity framed_entity)
|
||||||
|
return framed_entity.getThemes()
|
||||||
|
.stream()
|
||||||
|
.filter(state -> reference_state.isOf(state.getBlock()))
|
||||||
|
.findAny()
|
||||||
|
.orElse(framed_entity.getTheme(1));
|
||||||
return world.getBlockState(pos);
|
return world.getBlockState(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user