Compare commits
No commits in common. "394c75f9edcb8a70b56347e490c17a5a12f99053" and "de7acfee50df0c6b54a327a450f73ece3059a3d1" have entirely different histories.
394c75f9ed
...
de7acfee50
@ -1,7 +1,7 @@
|
||||
package fr.adrien1106.reframed;
|
||||
|
||||
import fr.adrien1106.reframed.block.*;
|
||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.BlockHelper;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
|
||||
@ -26,9 +26,7 @@ import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* TODO self culling
|
||||
* TODO fix other models
|
||||
* TODO better connected textures
|
||||
* TODO self culling, fix other models, better connected textures, preload items, better cache
|
||||
*/
|
||||
public class ReFramed implements ModInitializer {
|
||||
public static final String MODID = "reframed";
|
||||
|
@ -2,7 +2,7 @@ package fr.adrien1106.reframed.block;
|
||||
|
||||
import fr.adrien1106.reframed.ReFramed;
|
||||
import fr.adrien1106.reframed.generator.RecipeSetter;
|
||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.BlockHelper;
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
@ -33,7 +33,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static fr.adrien1106.reframed.util.blocks.BlockProperties.LIGHT;
|
||||
import static fr.adrien1106.reframed.util.BlockProperties.LIGHT;
|
||||
|
||||
public class ReFramedBlock extends Block implements BlockEntityProvider, RecipeSetter {
|
||||
|
||||
@ -41,23 +41,6 @@ public class ReFramedBlock extends Block implements BlockEntityProvider, RecipeS
|
||||
super(settings);
|
||||
setDefaultState(getDefaultState().with(LIGHT, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a record for the key so that it replaces the blockstate
|
||||
* which may have states that returns same models
|
||||
* @param state - the state_key to generate the key from
|
||||
* @return a cache key with only relevant properties
|
||||
*/
|
||||
public Object getModelCacheKey(BlockState state) {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amount of models the block can have prevents allocating too much space for a model
|
||||
*/
|
||||
public int getModelStateCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
//For addon devs: override this so your blocks don't end up trying to place my block entity, my BlockEntityType only handles blocks internal to the mod
|
||||
//Just make your own BlockEntityType, it's fine, you can even use the same ReFramedEntity class
|
||||
@ -115,7 +98,7 @@ public class ReFramedBlock extends Block implements BlockEntityProvider, RecipeS
|
||||
&& themes.stream().noneMatch(theme -> theme.getLuminance() != 0))
|
||||
drops.add(new ItemStack(Items.GLOWSTONE_DUST));
|
||||
if(!frame_entity.isSolid()
|
||||
&& themes.stream().anyMatch(AbstractBlockState::isSolid))
|
||||
&& themes.stream().anyMatch(theme -> theme.isSolid()))
|
||||
drops.add(new ItemStack(Items.POPPED_CHORUS_FRUIT));
|
||||
|
||||
ItemScatterer.spawn(world, pos, drops);
|
||||
|
@ -1,8 +1,8 @@
|
||||
package fr.adrien1106.reframed.block;
|
||||
|
||||
import fr.adrien1106.reframed.ReFramed;
|
||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
|
@ -44,7 +44,7 @@ public class ReFramedDoubleEntity extends ReFramedEntity {
|
||||
public void readNbt(NbtCompound nbt) {
|
||||
super.readNbt(nbt);
|
||||
|
||||
BlockState rendered_state = second_state;// keep previous state_key to check if rerender is needed
|
||||
BlockState rendered_state = second_state;// keep previous state to check if rerender is needed
|
||||
second_state = NbtHelper.toBlockState(Registries.BLOCK.getReadOnlyWrapper(), nbt.getCompound(BLOCKSTATE_KEY + 2));
|
||||
|
||||
// Force a chunk remesh on the client if the displayed blockstate has changed
|
||||
|
@ -13,6 +13,7 @@ import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.recipe.book.RecipeCategory;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
@ -24,36 +25,25 @@ import static net.minecraft.data.client.VariantSettings.Rotation.R90;
|
||||
import static net.minecraft.state.property.Properties.AXIS;
|
||||
|
||||
public class ReFramedDoubleSlabBlock extends ReFramedDoubleBlock implements BlockStateProvider {
|
||||
|
||||
public ReFramedDoubleSlabBlock(Settings settings) {
|
||||
super(settings);
|
||||
setDefaultState(getDefaultState().with(AXIS, Direction.Axis.Y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getModelCacheKey(BlockState state) {
|
||||
return state.get(AXIS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModelStateCount() {
|
||||
return 3;
|
||||
setDefaultState(getDefaultState().with(Properties.AXIS, Direction.Axis.Y));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder.add(AXIS));
|
||||
super.appendProperties(builder.add(Properties.AXIS));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
return super.getPlacementState(ctx).with(AXIS, ctx.getSide().getAxis());
|
||||
return super.getPlacementState(ctx).with(Properties.AXIS, ctx.getSide().getAxis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, int i) {
|
||||
return switch (state.get(AXIS)) {
|
||||
return switch (state.get(Properties.AXIS)) {
|
||||
case Y -> i == 2 ? UP : DOWN;
|
||||
case Z -> i == 2 ? NORTH : SOUTH;
|
||||
case X -> i == 2 ? EAST : WEST;
|
||||
|
@ -2,9 +2,9 @@ package fr.adrien1106.reframed.block;
|
||||
|
||||
import fr.adrien1106.reframed.ReFramed;
|
||||
import fr.adrien1106.reframed.generator.BlockStateProvider;
|
||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.blocks.Corner;
|
||||
import fr.adrien1106.reframed.util.blocks.StairShape;
|
||||
import fr.adrien1106.reframed.util.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.property.Corner;
|
||||
import fr.adrien1106.reframed.util.property.StairShape;
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
@ -28,27 +28,17 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static fr.adrien1106.reframed.block.ReFramedStairsBlock.*;
|
||||
import static fr.adrien1106.reframed.util.blocks.BlockProperties.CORNER;
|
||||
import static fr.adrien1106.reframed.util.blocks.BlockProperties.STAIR_SHAPE;
|
||||
import static fr.adrien1106.reframed.util.BlockProperties.CORNER;
|
||||
import static fr.adrien1106.reframed.util.BlockProperties.STAIR_SHAPE;
|
||||
import static fr.adrien1106.reframed.util.property.StairShape.STRAIGHT;
|
||||
|
||||
public class ReFramedDoubleStairsBlock extends ReFramedDoubleBlock implements BlockStateProvider {
|
||||
|
||||
private static final List<VoxelShape> COMPLEMENT_LIST = new ArrayList<>(52);
|
||||
private record ModelCacheKey(Corner corner, StairShape shape) {}
|
||||
|
||||
public ReFramedDoubleStairsBlock(Settings settings) {
|
||||
super(settings);
|
||||
setDefaultState(getDefaultState().with(CORNER, Corner.NORTH_DOWN).with(STAIR_SHAPE, StairShape.STRAIGHT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getModelCacheKey(BlockState state) {
|
||||
return new ModelCacheKey(state.get(CORNER), state.get(STAIR_SHAPE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModelStateCount() {
|
||||
return 108; // Has 12 * 9 state combination and 52 models still reduces cache size
|
||||
setDefaultState(getDefaultState().with(CORNER, Corner.NORTH_DOWN).with(STAIR_SHAPE, STRAIGHT));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,9 +1,9 @@
|
||||
package fr.adrien1106.reframed.block;
|
||||
|
||||
import fr.adrien1106.reframed.ReFramed;
|
||||
import fr.adrien1106.reframed.generator.BlockStateProvider;
|
||||
import fr.adrien1106.reframed.generator.GBlockstate;
|
||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||
import fr.adrien1106.reframed.generator.BlockStateProvider;
|
||||
import fr.adrien1106.reframed.util.BlockHelper;
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
@ -24,31 +24,19 @@ import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.BlockView;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static fr.adrien1106.reframed.block.ReFramedSlabBlock.getSlabShape;
|
||||
import static fr.adrien1106.reframed.block.ReFramedSlabBlock.*;
|
||||
import static fr.adrien1106.reframed.block.ReFramedStepBlock.STEP_VOXELS;
|
||||
import static net.minecraft.data.client.VariantSettings.Rotation.*;
|
||||
import static net.minecraft.state.property.Properties.AXIS;
|
||||
import static net.minecraft.state.property.Properties.FACING;
|
||||
import static net.minecraft.state.property.Properties.AXIS;
|
||||
import static net.minecraft.util.shape.VoxelShapes.empty;
|
||||
|
||||
public class ReFramedDoubleStepBlock extends WaterloggableReFramedDoubleBlock implements BlockStateProvider {
|
||||
private record ModelCacheKey(Direction facing, Axis axis) {}
|
||||
|
||||
public ReFramedDoubleStepBlock(Settings settings) {
|
||||
super(settings);
|
||||
setDefaultState(getDefaultState().with(FACING, Direction.DOWN).with(AXIS, Axis.X));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getModelCacheKey(BlockState state) {
|
||||
return new ModelCacheKey(state.get(FACING), state.get(AXIS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModelStateCount() {
|
||||
return 18;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder.add(FACING, AXIS));
|
||||
|
@ -1,8 +1,8 @@
|
||||
package fr.adrien1106.reframed.block;
|
||||
|
||||
import fr.adrien1106.reframed.ReFramed;
|
||||
import fr.adrien1106.reframed.util.blocks.BlockProperties;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.BlockProperties;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
@ -27,7 +27,7 @@ import java.util.Objects;
|
||||
|
||||
//Keeping the weight of this block entity down, both in terms of memory consumption and NBT sync traffic,
|
||||
//is pretty important since players might place a lot of them. There were tons and tons of these at Blanketcon.
|
||||
//To that end, most of the state_key has been crammed into a bitfield.
|
||||
//To that end, most of the state has been crammed into a bitfield.
|
||||
public class ReFramedEntity extends BlockEntity implements ThemeableBlockEntity {
|
||||
protected BlockState first_state = Blocks.AIR.getDefaultState();
|
||||
protected byte bit_field = SOLIDITY_MASK;
|
||||
@ -47,7 +47,7 @@ public class ReFramedEntity extends BlockEntity implements ThemeableBlockEntity
|
||||
public void readNbt(NbtCompound nbt) {
|
||||
super.readNbt(nbt);
|
||||
|
||||
BlockState rendered_state = first_state; // keep previous state_key to check if rerender is needed
|
||||
BlockState rendered_state = first_state; // keep previous state to check if rerender is needed
|
||||
first_state = NbtHelper.toBlockState(Registries.BLOCK.getReadOnlyWrapper(), nbt.getCompound(BLOCKSTATE_KEY + 1));
|
||||
if (nbt.contains(BITFIELD_KEY)) bit_field = nbt.getByte(BITFIELD_KEY);
|
||||
|
||||
|
@ -38,16 +38,6 @@ public class ReFramedSlabBlock extends WaterloggableReFramedBlock implements Blo
|
||||
super(settings);
|
||||
setDefaultState(getDefaultState().with(FACING, Direction.DOWN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getModelCacheKey(BlockState state) {
|
||||
return state.get(FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModelStateCount() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
|
@ -3,10 +3,10 @@ package fr.adrien1106.reframed.block;
|
||||
import fr.adrien1106.reframed.ReFramed;
|
||||
import fr.adrien1106.reframed.generator.GBlockstate;
|
||||
import fr.adrien1106.reframed.generator.BlockStateProvider;
|
||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.VoxelHelper;
|
||||
import fr.adrien1106.reframed.util.blocks.Corner;
|
||||
import fr.adrien1106.reframed.util.blocks.StairShape;
|
||||
import fr.adrien1106.reframed.util.property.Corner;
|
||||
import fr.adrien1106.reframed.util.property.StairShape;
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
@ -34,30 +34,19 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static fr.adrien1106.reframed.util.blocks.BlockProperties.*;
|
||||
import static fr.adrien1106.reframed.util.blocks.StairShape.*;
|
||||
import static fr.adrien1106.reframed.util.BlockProperties.*;
|
||||
import static fr.adrien1106.reframed.util.property.StairShape.*;
|
||||
import static net.minecraft.data.client.VariantSettings.Rotation.*;
|
||||
import static fr.adrien1106.reframed.util.blocks.Corner.*;
|
||||
import static fr.adrien1106.reframed.util.property.Corner.*;
|
||||
|
||||
public class ReFramedStairsBlock extends WaterloggableReFramedBlock implements BlockStateProvider {
|
||||
|
||||
public static final List<VoxelShape> VOXEL_LIST = new ArrayList<>(52);
|
||||
private record ModelCacheKey(Corner corner, StairShape shape) {}
|
||||
|
||||
public ReFramedStairsBlock(Settings settings) {
|
||||
super(settings);
|
||||
setDefaultState(getDefaultState().with(CORNER, Corner.NORTH_DOWN).with(STAIR_SHAPE, STRAIGHT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getModelCacheKey(BlockState state) {
|
||||
return new ModelCacheKey(state.get(CORNER), state.get(STAIR_SHAPE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModelStateCount() {
|
||||
return 108; // Has 12 * 9 state combination and 52 models still reduces cache size
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
|
@ -3,9 +3,9 @@ package fr.adrien1106.reframed.block;
|
||||
import fr.adrien1106.reframed.ReFramed;
|
||||
import fr.adrien1106.reframed.generator.GBlockstate;
|
||||
import fr.adrien1106.reframed.generator.BlockStateProvider;
|
||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.VoxelHelper;
|
||||
import fr.adrien1106.reframed.util.blocks.Corner;
|
||||
import fr.adrien1106.reframed.util.property.Corner;
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
@ -28,8 +28,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static fr.adrien1106.reframed.util.blocks.BlockProperties.CORNER;
|
||||
import static fr.adrien1106.reframed.util.blocks.Corner.*;
|
||||
import static fr.adrien1106.reframed.util.BlockProperties.CORNER;
|
||||
import static fr.adrien1106.reframed.util.property.Corner.*;
|
||||
import static net.minecraft.data.client.VariantSettings.Rotation.*;
|
||||
|
||||
public class ReFramedStepBlock extends WaterloggableReFramedBlock implements BlockStateProvider {
|
||||
@ -41,16 +41,6 @@ public class ReFramedStepBlock extends WaterloggableReFramedBlock implements Blo
|
||||
setDefaultState(getDefaultState().with(CORNER, Corner.NORTH_DOWN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getModelCacheKey(BlockState state) {
|
||||
return state.get(CORNER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModelStateCount() {
|
||||
return 12;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder.add(CORNER));
|
||||
|
@ -5,6 +5,7 @@ import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel;
|
||||
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.texture.Sprite;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@ -44,7 +45,7 @@ public class DoubleRetexturingBakedModel extends ForwardingBakedModel implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ForwardingBakedModel> models() {
|
||||
public List<BakedModel> models() {
|
||||
return List.of(model_1, model_2);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package fr.adrien1106.reframed.client.model;
|
||||
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MultiRetexturableModel {
|
||||
|
||||
List<ForwardingBakedModel> models();
|
||||
List<BakedModel> models();
|
||||
}
|
||||
|
@ -76,15 +76,4 @@ public record QuadPosBounds(float min_x, float max_x, float min_y, float max_y,
|
||||
quad.pos(i, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof QuadPosBounds other)) return false;
|
||||
return MathHelper.approximatelyEquals(min_x, other.min_x)
|
||||
&& MathHelper.approximatelyEquals(min_y, other.min_y)
|
||||
&& MathHelper.approximatelyEquals(min_z, other.min_z)
|
||||
&& MathHelper.approximatelyEquals(max_x, other.max_x)
|
||||
&& MathHelper.approximatelyEquals(max_y, other.max_y)
|
||||
&& MathHelper.approximatelyEquals(max_z, other.max_z);
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,17 @@
|
||||
package fr.adrien1106.reframed.client.model;
|
||||
|
||||
import fr.adrien1106.reframed.block.ReFramedBlock;
|
||||
import fr.adrien1106.reframed.block.ReFramedEntity;
|
||||
import fr.adrien1106.reframed.client.ReFramedClient;
|
||||
import fr.adrien1106.reframed.client.model.apperance.SpriteProperties;
|
||||
import fr.adrien1106.reframed.mixin.MinecraftAccessor;
|
||||
import fr.adrien1106.reframed.client.model.apperance.CamoAppearance;
|
||||
import fr.adrien1106.reframed.client.model.apperance.CamoAppearanceManager;
|
||||
import fr.adrien1106.reframed.client.model.apperance.WeightedComputedAppearance;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
|
||||
import net.fabricmc.fabric.api.renderer.v1.mesh.*;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
|
||||
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
|
||||
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
|
||||
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel;
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||
import net.minecraft.block.BlockState;
|
||||
@ -24,43 +26,34 @@ import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class RetexturingBakedModel extends ForwardingBakedModel {
|
||||
public RetexturingBakedModel(BakedModel base_model, CamoAppearanceManager tam, int theme_index, ModelBakeSettings settings, BlockState item_state, boolean ao) {
|
||||
this.wrapped = base_model; //field from the superclass; vanilla getQuads etc. will delegate through to this
|
||||
|
||||
this.appearance_manager = tam;
|
||||
this.tam = tam;
|
||||
this.theme_index = theme_index;
|
||||
this.uv_lock = settings.isUvLocked();
|
||||
this.item_state = item_state;
|
||||
this.ao = ao;
|
||||
|
||||
int cache_size = 64; // default is 64 why don't ask me and it should get overwritten
|
||||
if (item_state.getBlock() instanceof ReFramedBlock frame_block) cache_size = frame_block.getModelStateCount() + 1;
|
||||
BASE_MESH_CACHE = new Object2ObjectLinkedOpenHashMap<>(cache_size, 0.25f) {
|
||||
@Override
|
||||
protected void rehash(int v) {}
|
||||
};
|
||||
}
|
||||
|
||||
protected final CamoAppearanceManager appearance_manager;
|
||||
protected final CamoAppearanceManager tam;
|
||||
protected final int theme_index;
|
||||
protected final boolean uv_lock;
|
||||
protected final boolean ao;
|
||||
protected final BlockState item_state;
|
||||
protected final boolean ao;
|
||||
|
||||
protected record MeshCacheKey(Object state_key, CamoAppearance appearance, int model_id) {}
|
||||
/** cache that store retextured models */
|
||||
protected final Object2ObjectLinkedOpenHashMap<MeshCacheKey, Mesh> RETEXTURED_MESH_CACHE =
|
||||
new Object2ObjectLinkedOpenHashMap<>(128, 0.25f) {
|
||||
@Override
|
||||
protected void rehash(int v) {}
|
||||
};
|
||||
|
||||
/** cache that stores the base meshes which has the size of the amount of models */
|
||||
protected final Object2ObjectLinkedOpenHashMap<Object, Mesh> BASE_MESH_CACHE;
|
||||
/* ----------------------------------------------- CACHE ELEMENT ------------------------------------------------ */
|
||||
// TODO make static ? for connected textures ?
|
||||
protected record MeshCacheKey(BlockState state, TransformCacheKey transform) {}
|
||||
protected record TransformCacheKey(CamoAppearance appearance, int model_id) {}
|
||||
protected final ConcurrentMap<TransformCacheKey, RetexturingTransformer> retextured_transforms = new ConcurrentHashMap<>();
|
||||
protected final ConcurrentMap<MeshCacheKey, Mesh> retextured_meshes = new ConcurrentHashMap<>(); //mutable, append-only cache
|
||||
|
||||
protected static final Direction[] DIRECTIONS_AND_NULL;
|
||||
static {
|
||||
@ -69,12 +62,11 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel {
|
||||
System.arraycopy(values, 0, DIRECTIONS_AND_NULL, 0, values.length);
|
||||
}
|
||||
|
||||
protected Mesh getBaseMesh(Object key, BlockState state) {
|
||||
protected final ConcurrentMap<BlockState, Mesh> jsonToMesh = new ConcurrentHashMap<>();
|
||||
|
||||
protected Mesh getBaseMesh(BlockState state) {
|
||||
//Convert models to re-texturable Meshes lazily, the first time we encounter each blockstate
|
||||
if (BASE_MESH_CACHE.containsKey(key)) return BASE_MESH_CACHE.getAndMoveToFirst(key);
|
||||
Mesh mesh = convertModel(state);
|
||||
BASE_MESH_CACHE.putAndMoveToFirst(key, mesh);
|
||||
return mesh;
|
||||
return jsonToMesh.computeIfAbsent(state, this::convertModel);
|
||||
}
|
||||
|
||||
protected abstract Mesh convertModel(BlockState state);
|
||||
@ -86,42 +78,39 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel {
|
||||
|
||||
@Override
|
||||
public Sprite getParticleSprite() {
|
||||
return appearance_manager.getDefaultAppearance(theme_index).getSprites(Direction.UP, 0).get(0).sprite();
|
||||
return tam.getDefaultAppearance(theme_index).getSprites(Direction.UP, 0).get(0).sprite();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitBlockQuads(BlockRenderView world, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
// skip render if block not a frame (which should always be the case
|
||||
if (!(state.getBlock() instanceof ReFramedBlock frame_block)) return;
|
||||
BlockState theme = (world.getBlockEntity(pos) instanceof ThemeableBlockEntity s) ? s.getTheme(theme_index) : null;
|
||||
QuadEmitter quad_emitter = context.getEmitter();
|
||||
if(theme == null || theme.isAir()) {
|
||||
getRetexturedMesh(
|
||||
new MeshCacheKey(
|
||||
frame_block.getModelCacheKey(state),
|
||||
appearance_manager.getDefaultAppearance(theme_index),
|
||||
0
|
||||
),
|
||||
state
|
||||
).outputTo(quad_emitter);
|
||||
getUntintedRetexturedMesh(new MeshCacheKey(state, new TransformCacheKey(tam.getDefaultAppearance(theme_index), 0)), 0).outputTo(quad_emitter);
|
||||
return;
|
||||
}
|
||||
if(theme.getBlock() == Blocks.BARRIER) return;
|
||||
|
||||
CamoAppearance camo = appearance_manager.getCamoAppearance(world, theme, pos, theme_index);
|
||||
CamoAppearance camo = tam.getCamoAppearance(world, theme, pos, theme_index);
|
||||
long seed = theme.getRenderingSeed(pos);
|
||||
int model_id = 0;
|
||||
if (camo instanceof WeightedComputedAppearance wca) model_id = wca.getAppearanceIndex(seed);
|
||||
|
||||
|
||||
int tint = 0xFF000000 | MinecraftClient.getInstance().getBlockColors().getColor(theme, world, pos, 0);
|
||||
Mesh untintedMesh = getRetexturedMesh(new MeshCacheKey(frame_block.getModelCacheKey(state), camo, model_id), state);
|
||||
Mesh untintedMesh = getUntintedRetexturedMesh(
|
||||
new MeshCacheKey(
|
||||
state,
|
||||
new TransformCacheKey(camo, model_id)
|
||||
),
|
||||
seed
|
||||
);
|
||||
|
||||
//The specific tint might vary a lot; imagine grass color smoothly changing. Trying to bake the tint into
|
||||
//the cached mesh will pollute it with a ton of single-use meshes with only slightly different colors.
|
||||
if(tint == 0xFFFFFFFF) {
|
||||
untintedMesh.outputTo(quad_emitter);
|
||||
} else {
|
||||
context.pushTransform(new TintingTransformer(camo, model_id, tint));
|
||||
context.pushTransform(new TintingTransformer(camo, tint, seed));
|
||||
untintedMesh.outputTo(quad_emitter);
|
||||
context.popTransform();
|
||||
}
|
||||
@ -131,72 +120,121 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel {
|
||||
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
//cheeky: if the item has NBT data, pluck out the blockstate from it & look up the item color provider
|
||||
//none of this is accessible unless you're in creative mode doing ctrl-pick btw
|
||||
CamoAppearance appearance;
|
||||
CamoAppearance nbtAppearance;
|
||||
int tint;
|
||||
BlockState theme = ReFramedEntity.readStateFromItem(stack, theme_index);
|
||||
if(!theme.isAir()) {
|
||||
appearance = appearance_manager.getCamoAppearance(null, theme, null, theme_index);
|
||||
nbtAppearance = tam.getCamoAppearance(null, theme, null, theme_index);
|
||||
tint = 0xFF000000 | ((MinecraftAccessor) MinecraftClient.getInstance()).getItemColors().getColor(new ItemStack(theme.getBlock()), 0);
|
||||
} else {
|
||||
appearance = appearance_manager.getDefaultAppearance(theme_index);
|
||||
nbtAppearance = tam.getDefaultAppearance(theme_index);
|
||||
tint = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
Mesh untintedMesh = getRetexturedMesh(new MeshCacheKey("I", appearance, 0), item_state);
|
||||
Mesh untintedMesh = getUntintedRetexturedMesh(new MeshCacheKey(item_state, new TransformCacheKey(nbtAppearance, 0)), 0);
|
||||
|
||||
QuadEmitter quad_emitter = context.getEmitter();
|
||||
if(tint == 0xFFFFFFFF) {
|
||||
untintedMesh.outputTo(quad_emitter);
|
||||
} else {
|
||||
context.pushTransform(new TintingTransformer(appearance, 0, tint));
|
||||
context.pushTransform(new TintingTransformer(nbtAppearance, tint, 0));
|
||||
untintedMesh.outputTo(quad_emitter);
|
||||
context.popTransform();
|
||||
}
|
||||
}
|
||||
|
||||
protected Mesh getRetexturedMesh(MeshCacheKey key, BlockState state) {
|
||||
if (RETEXTURED_MESH_CACHE.containsKey(key)) return RETEXTURED_MESH_CACHE.getAndMoveToFirst(key);
|
||||
Mesh mesh = transformMesh(key, state);
|
||||
RETEXTURED_MESH_CACHE.putAndMoveToFirst(key, mesh);
|
||||
return mesh;
|
||||
protected Mesh getUntintedRetexturedMesh(MeshCacheKey key, long seed) {
|
||||
return retextured_meshes.computeIfAbsent(key, (k) -> createUntintedRetexturedMesh(k, seed));
|
||||
}
|
||||
|
||||
protected Mesh transformMesh(MeshCacheKey key, BlockState state) {
|
||||
protected Mesh createUntintedRetexturedMesh(MeshCacheKey key, long seed) {
|
||||
RetexturingTransformer transformer = retextured_transforms.computeIfAbsent(key.transform, (k) -> new RetexturingTransformer(k.appearance, seed));
|
||||
return pretransformMesh(getBaseMesh(key.state), transformer);
|
||||
}
|
||||
|
||||
private static Mesh pretransformMesh(Mesh mesh, RetexturingTransformer transform) {
|
||||
MeshBuilder builder = ReFramedClient.HELPER.getFabricRenderer().meshBuilder();
|
||||
QuadEmitter emitter = builder.getEmitter();
|
||||
|
||||
AtomicInteger quad_index = new AtomicInteger();
|
||||
getBaseMesh(key.state_key, state).forEach(quad -> {
|
||||
mesh.forEach(quad -> {
|
||||
int i = -1;
|
||||
do {
|
||||
emitter.copyFrom(quad);
|
||||
i = key.appearance.transformQuad(emitter, i, quad_index.get(), key.model_id, ao, uv_lock);
|
||||
i = transform.transform(emitter, i);
|
||||
} while (i > 0);
|
||||
// kinda weird to do it like that but other directions don't use the quad_index so it doesn't matter
|
||||
if (quad.cullFace() == null) quad_index.getAndIncrement();
|
||||
});
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected static class TintingTransformer implements RenderContext.QuadTransform {
|
||||
private final CamoAppearance appearance;
|
||||
private final int model_id;
|
||||
private final int tint;
|
||||
|
||||
protected TintingTransformer(CamoAppearance appearance, int model_id, int tint) {
|
||||
this.appearance = appearance;
|
||||
this.model_id = model_id;
|
||||
this.tint = tint;
|
||||
|
||||
public class RetexturingTransformer {
|
||||
private final long seed;
|
||||
protected RetexturingTransformer(CamoAppearance ta, long seed) {
|
||||
this.ta = ta;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
protected final CamoAppearance ta;
|
||||
|
||||
public int transform(QuadEmitter quad, int i) {
|
||||
if(quad.tag() == 0) return 0; //Pass the quad through unmodified.
|
||||
|
||||
Direction direction = quad.nominalFace();
|
||||
List<SpriteProperties> sprites = ta.getSprites(direction, seed);
|
||||
if (i == -1) i = sprites.size();
|
||||
|
||||
SpriteProperties properties = sprites.get(sprites.size() - i);
|
||||
i--;
|
||||
QuadPosBounds bounds = properties.bounds();
|
||||
|
||||
if (bounds == null) { // sprite applies anywhere e.g. default behaviour
|
||||
quad.material(ta.getRenderMaterial(ao));
|
||||
quad.spriteBake(
|
||||
properties.sprite(),
|
||||
MutableQuadView.BAKE_NORMALIZED
|
||||
| properties.flags()
|
||||
| (uv_lock ? MutableQuadView.BAKE_LOCK_UV : 0)
|
||||
);
|
||||
quad.tag(i+1);
|
||||
quad.emit();
|
||||
return i;
|
||||
}
|
||||
|
||||
// verify if sprite covers the current quad and apply the new size
|
||||
QuadPosBounds origin_bounds = QuadPosBounds.read(quad, false);
|
||||
if (!bounds.matches(origin_bounds)) return i;
|
||||
|
||||
// apply new quad shape
|
||||
quad.material(ta.getRenderMaterial(ao));
|
||||
bounds.intersection(origin_bounds, direction.getAxis()).apply(quad, origin_bounds);
|
||||
quad.spriteBake( // seems to work without the flags and break with it
|
||||
properties.sprite(),
|
||||
MutableQuadView.BAKE_NORMALIZED
|
||||
| MutableQuadView.BAKE_LOCK_UV
|
||||
);
|
||||
quad.tag(i+1);
|
||||
quad.emit();
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class TintingTransformer implements RenderContext.QuadTransform {
|
||||
private final long seed;
|
||||
protected TintingTransformer(CamoAppearance ta, int tint, long seed) {
|
||||
this.ta = ta;
|
||||
this.tint = tint;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
protected final CamoAppearance ta;
|
||||
protected final int tint;
|
||||
|
||||
@Override
|
||||
public boolean transform(MutableQuadView quad) {
|
||||
int camo_quad_index = quad.tag() - ((quad.tag() >>> 8) << 8);
|
||||
if(camo_quad_index == 0) return true;
|
||||
|
||||
if(appearance.hasColor(quad.nominalFace(), model_id, camo_quad_index)) quad.color(tint, tint, tint, tint);
|
||||
if(quad.tag() == 0) return true;
|
||||
|
||||
if(ta.hasColor(quad.nominalFace(), seed, quad.tag())) quad.color(tint, tint, tint, tint);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class UnbakedAutoRetexturedModel extends UnbakedRetexturedModel {
|
||||
Renderer r = ReFramedClient.HELPER.getFabricRenderer();
|
||||
MeshBuilder builder = r.meshBuilder();
|
||||
QuadEmitter emitter = builder.getEmitter();
|
||||
RenderMaterial mat = appearance_manager.getCachedMaterial(state, false);
|
||||
RenderMaterial mat = tam.getCachedMaterial(state, false);
|
||||
|
||||
Random rand = Random.create(42);
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class UnbakedJsonRetexturedModel extends UnbakedRetexturedModel {
|
||||
Renderer r = ReFramedClient.HELPER.getFabricRenderer();
|
||||
MeshBuilder builder = r.meshBuilder();
|
||||
QuadEmitter emitter = builder.getEmitter();
|
||||
RenderMaterial mat = appearance_manager.getCachedMaterial(state, false);
|
||||
RenderMaterial mat = tam.getCachedMaterial(state, false);
|
||||
|
||||
Random rand = Random.create(42);
|
||||
|
||||
|
@ -14,7 +14,7 @@ public abstract class UnbakedRetexturedModel implements UnbakedModel {
|
||||
|
||||
protected int theme_index = 1;
|
||||
protected BlockState item_state;
|
||||
protected final boolean ao = true;
|
||||
protected boolean ao = true;
|
||||
|
||||
public UnbakedRetexturedModel(Identifier parent) {
|
||||
this.parent = parent;
|
||||
|
@ -1,77 +1,13 @@
|
||||
package fr.adrien1106.reframed.client.model.apperance;
|
||||
|
||||
import fr.adrien1106.reframed.client.model.QuadPosBounds;
|
||||
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
|
||||
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
|
||||
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CamoAppearance {
|
||||
protected final int id;
|
||||
protected final RenderMaterial ao_material;
|
||||
protected final RenderMaterial material;
|
||||
|
||||
protected CamoAppearance(RenderMaterial ao_material, RenderMaterial material, int id) {
|
||||
this.id = id;
|
||||
|
||||
this.ao_material = ao_material;
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public abstract @NotNull List<SpriteProperties> getSprites(Direction dir, int model_id);
|
||||
public abstract boolean hasColor(Direction dir, int model_id, int index);
|
||||
|
||||
public @NotNull RenderMaterial getRenderMaterial(boolean ao) {
|
||||
return ao && ao_material != null? ao_material : material;
|
||||
}
|
||||
|
||||
public int transformQuad(QuadEmitter quad, int i, int quad_index, int model_id, boolean ao, boolean uv_lock) {
|
||||
if(quad.tag() == 0) return 0; // Pass the quad through unmodified.
|
||||
|
||||
Direction direction = quad.nominalFace();
|
||||
List<SpriteProperties> sprites = getSprites(direction, model_id);
|
||||
if (i == -1) i = sprites.size();
|
||||
|
||||
SpriteProperties properties = sprites.get(sprites.size() - i);
|
||||
int tag = i + (quad_index << 8);
|
||||
i--;
|
||||
QuadPosBounds bounds = properties.bounds();
|
||||
|
||||
if (bounds == null) { // sprite applies anywhere e.g. default behaviour
|
||||
quad.material(getRenderMaterial(ao));
|
||||
quad.spriteBake(
|
||||
properties.sprite(),
|
||||
MutableQuadView.BAKE_NORMALIZED
|
||||
| properties.flags()
|
||||
| (uv_lock ? MutableQuadView.BAKE_LOCK_UV : 0)
|
||||
);
|
||||
quad.tag(tag);
|
||||
quad.emit();
|
||||
return i;
|
||||
}
|
||||
|
||||
// verify if sprite covers the current quad and apply the new size
|
||||
QuadPosBounds origin_bounds = QuadPosBounds.read(quad, false);
|
||||
if (!bounds.matches(origin_bounds)) return i;
|
||||
|
||||
// apply new quad shape
|
||||
quad.material(getRenderMaterial(ao));
|
||||
bounds.intersection(origin_bounds, direction.getAxis()).apply(quad, origin_bounds);
|
||||
quad.spriteBake( // seems to work without the flags and break with it
|
||||
properties.sprite(),
|
||||
MutableQuadView.BAKE_NORMALIZED
|
||||
| MutableQuadView.BAKE_LOCK_UV
|
||||
);
|
||||
quad.tag(tag);
|
||||
quad.emit();
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id;
|
||||
}
|
||||
public interface CamoAppearance {
|
||||
@NotNull RenderMaterial getRenderMaterial(boolean ao);
|
||||
@NotNull List<SpriteProperties> getSprites(Direction dir, long seed);
|
||||
boolean hasColor(Direction dir, long seed, int index);
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import fr.adrien1106.reframed.client.ReFramedClient;
|
||||
import fr.adrien1106.reframed.client.model.DynamicBakedModel;
|
||||
import fr.adrien1106.reframed.client.model.QuadPosBounds;
|
||||
import fr.adrien1106.reframed.mixin.model.WeightedBakedModelAccessor;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
|
||||
import net.fabricmc.fabric.api.renderer.v1.Renderer;
|
||||
import net.fabricmc.fabric.api.renderer.v1.material.BlendMode;
|
||||
import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder;
|
||||
@ -30,6 +29,7 @@ import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
|
||||
@ -40,20 +40,20 @@ public class CamoAppearanceManager {
|
||||
for(BlendMode blend : BlendMode.values()) {
|
||||
finder.clear().disableDiffuse(false).blendMode(blend);
|
||||
|
||||
materials.put(blend, finder.ambientOcclusion(TriState.FALSE).find());
|
||||
ao_materials.put(blend, finder.ambientOcclusion(TriState.DEFAULT).find()); //not "true" since that *forces* AO, i just want to *allow* AO
|
||||
materialsWithoutAo.put(blend, finder.ambientOcclusion(TriState.FALSE).find());
|
||||
materialsWithAo.put(blend, finder.ambientOcclusion(TriState.DEFAULT).find()); //not "true" since that *forces* AO, i just want to *allow* AO
|
||||
}
|
||||
|
||||
Sprite sprite = spriteLookup.apply(DEFAULT_SPRITE_MAIN);
|
||||
if(sprite == null) throw new IllegalStateException("Couldn't locate " + DEFAULT_SPRITE_MAIN + " !");
|
||||
this.default_appearance = new SingleSpriteAppearance(sprite, materials.get(BlendMode.CUTOUT), serial_number.getAndIncrement());
|
||||
this.default_appearance = new SingleSpriteAppearance(sprite, materialsWithoutAo.get(BlendMode.CUTOUT), serial_number.getAndIncrement());
|
||||
|
||||
sprite = spriteLookup.apply(DEFAULT_SPRITE_SECONDARY);
|
||||
if(sprite == null) throw new IllegalStateException("Couldn't locate " + DEFAULT_SPRITE_MAIN + " !");
|
||||
this.accent_appearance = new SingleSpriteAppearance(sprite, materials.get(BlendMode.CUTOUT), serial_number.getAndIncrement());
|
||||
this.accent_appearance = new SingleSpriteAppearance(sprite, materialsWithoutAo.get(BlendMode.CUTOUT), serial_number.getAndIncrement());
|
||||
|
||||
sprite = spriteLookup.apply(BARRIER_SPRITE_ID);
|
||||
this.barrierItemAppearance = new SingleSpriteAppearance(sprite, materials.get(BlendMode.CUTOUT), serial_number.getAndIncrement());
|
||||
this.barrierItemAppearance = new SingleSpriteAppearance(sprite, materialsWithoutAo.get(BlendMode.CUTOUT), serial_number.getAndIncrement());
|
||||
}
|
||||
|
||||
protected static final SpriteIdentifier DEFAULT_SPRITE_MAIN = new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(ReFramed.MODID, "block/framed_block"));
|
||||
@ -63,16 +63,12 @@ public class CamoAppearanceManager {
|
||||
private final CamoAppearance default_appearance;
|
||||
private final CamoAppearance accent_appearance;
|
||||
private final CamoAppearance barrierItemAppearance;
|
||||
|
||||
private static final Object2ObjectLinkedOpenHashMap<BlockState, CamoAppearance> APPEARANCE_CACHE =
|
||||
new Object2ObjectLinkedOpenHashMap<>(2048, 0.25f) {
|
||||
@Override
|
||||
protected void rehash(int n) {}
|
||||
};
|
||||
|
||||
private final ConcurrentHashMap<BlockState, CamoAppearance> appearanceCache = new ConcurrentHashMap<>(); //Mutable, append-only cache
|
||||
private final AtomicInteger serial_number = new AtomicInteger(0); //Mutable
|
||||
|
||||
private final EnumMap<BlendMode, RenderMaterial> ao_materials = new EnumMap<>(BlendMode.class);
|
||||
private final EnumMap<BlendMode, RenderMaterial> materials = new EnumMap<>(BlendMode.class); //Immutable contents
|
||||
private final EnumMap<BlendMode, RenderMaterial> materialsWithAo = new EnumMap<>(BlendMode.class);
|
||||
private final EnumMap<BlendMode, RenderMaterial> materialsWithoutAo = new EnumMap<>(BlendMode.class); //Immutable contents
|
||||
|
||||
public CamoAppearance getDefaultAppearance(int appearance) {
|
||||
return appearance == 2 ? accent_appearance: default_appearance;
|
||||
@ -85,17 +81,11 @@ public class CamoAppearanceManager {
|
||||
if (model instanceof DynamicBakedModel dynamic_model) {
|
||||
return computeAppearance(dynamic_model.computeQuads(world, state, pos, theme_index), state);
|
||||
}
|
||||
|
||||
// refresh cache
|
||||
if (APPEARANCE_CACHE.containsKey(state)) return APPEARANCE_CACHE.getAndMoveToFirst(state);
|
||||
|
||||
CamoAppearance appearance = computeAppearance(model, state);
|
||||
APPEARANCE_CACHE.putAndMoveToFirst(state, appearance);
|
||||
return appearance;
|
||||
return appearanceCache.computeIfAbsent(state, block_state -> computeAppearance(model, block_state));
|
||||
}
|
||||
|
||||
public RenderMaterial getCachedMaterial(BlockState state, boolean ao) {
|
||||
Map<BlendMode, RenderMaterial> m = ao ? ao_materials : materials;
|
||||
Map<BlendMode, RenderMaterial> m = ao ? materialsWithAo : materialsWithoutAo;
|
||||
return m.get(BlendMode.fromRenderLayer(RenderLayers.getBlockLayer(state)));
|
||||
}
|
||||
|
||||
|
@ -6,22 +6,33 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ComputedAppearance extends CamoAppearance {
|
||||
public class ComputedAppearance implements CamoAppearance {
|
||||
private final Appearance appearance;
|
||||
private final int id;
|
||||
private final RenderMaterial matWithAo;
|
||||
private final RenderMaterial matWithoutAo;
|
||||
|
||||
public ComputedAppearance(@NotNull Appearance appearance, RenderMaterial ao_material, RenderMaterial material, int id) {
|
||||
super(ao_material, material, id);
|
||||
public ComputedAppearance(@NotNull Appearance appearance, RenderMaterial withAo, RenderMaterial withoutAo, int id) {
|
||||
this.appearance = appearance;
|
||||
this.id = id;
|
||||
|
||||
this.matWithAo = withAo;
|
||||
this.matWithoutAo = withoutAo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<SpriteProperties> getSprites(Direction dir, int model_id) {
|
||||
public @NotNull RenderMaterial getRenderMaterial(boolean ao) {
|
||||
return ao ? matWithAo : matWithoutAo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<SpriteProperties> getSprites(Direction dir, long seed) {
|
||||
return appearance.sprites().get(dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasColor(Direction dir, int model_id, int index) {
|
||||
List<SpriteProperties> properties = getSprites(dir, model_id);
|
||||
public boolean hasColor(Direction dir, long seed, int index) {
|
||||
List<SpriteProperties> properties = getSprites(dir, seed);
|
||||
if (index != 0) index = properties.size() - index;
|
||||
return properties.get(index).has_colors();
|
||||
}
|
||||
@ -29,7 +40,13 @@ public class ComputedAppearance extends CamoAppearance {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(this == o) return true;
|
||||
if(!(o instanceof ComputedAppearance that)) return false;
|
||||
if(o == null || getClass() != o.getClass()) return false;
|
||||
ComputedAppearance that = (ComputedAppearance) o;
|
||||
return id == that.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
@ -7,33 +7,47 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SingleSpriteAppearance extends CamoAppearance {
|
||||
public class SingleSpriteAppearance implements CamoAppearance {
|
||||
private final @NotNull Sprite defaultSprite;
|
||||
private final RenderMaterial mat;
|
||||
private final int id;
|
||||
|
||||
public SingleSpriteAppearance(@NotNull Sprite defaultSprite, RenderMaterial mat, int id) {
|
||||
super(null, mat, id);
|
||||
this.defaultSprite = defaultSprite;
|
||||
this.mat = mat;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<SpriteProperties> getSprites(Direction dir, int model_id) {
|
||||
public @NotNull RenderMaterial getRenderMaterial(boolean ao) {
|
||||
return mat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<SpriteProperties> getSprites(Direction dir, long seed) {
|
||||
return List.of(new SpriteProperties(defaultSprite, 0, null, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasColor(Direction dir, int model_id, int index) {
|
||||
public boolean hasColor(Direction dir, long seed, int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(this == o) return true;
|
||||
if(!(o instanceof SingleSpriteAppearance that)) return false;
|
||||
if(o == null || getClass() != o.getClass()) return false;
|
||||
SingleSpriteAppearance that = (SingleSpriteAppearance) o;
|
||||
return id == that.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SingleSpriteAppearance[defaultSprite=%s, mat=%s, id=%d]".formatted(defaultSprite, material, id);
|
||||
return "SingleSpriteAppearance[defaultSprite=%s, mat=%s, id=%d]".formatted(defaultSprite, mat, id);
|
||||
}
|
||||
}
|
||||
|
@ -9,14 +9,25 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WeightedComputedAppearance extends CamoAppearance {
|
||||
public class WeightedComputedAppearance implements CamoAppearance {
|
||||
private final List<Weighted.Present<Appearance>> appearances;
|
||||
private final int total_weight;
|
||||
private final int id;
|
||||
private final RenderMaterial matWithAo;
|
||||
private final RenderMaterial matWithoutAo;
|
||||
|
||||
public WeightedComputedAppearance(@NotNull List<Weighted.Present<Appearance>> appearances, RenderMaterial ao_material, RenderMaterial material, int id) {
|
||||
super(ao_material, material, id);
|
||||
public WeightedComputedAppearance(@NotNull List<Weighted.Present<Appearance>> appearances, RenderMaterial withAo, RenderMaterial withoutAo, int id) {
|
||||
this.appearances = appearances;
|
||||
this.total_weight = Weighting.getWeightSum(appearances);
|
||||
this.id = id;
|
||||
|
||||
this.matWithAo = withAo;
|
||||
this.matWithoutAo = withoutAo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull RenderMaterial getRenderMaterial(boolean ao) {
|
||||
return ao ? matWithAo : matWithoutAo;
|
||||
}
|
||||
|
||||
|
||||
@ -26,19 +37,21 @@ public class WeightedComputedAppearance extends CamoAppearance {
|
||||
.map(appearances::indexOf).orElse(0);
|
||||
}
|
||||
|
||||
private Appearance getAppearance(int model_id) {
|
||||
return appearances.get(model_id).getData();
|
||||
private Appearance getAppearance(long seed) {
|
||||
Random random = Random.create(seed);
|
||||
return Weighting.getAt(appearances, Math.abs((int)random.nextLong()) % total_weight)
|
||||
.map(Weighted.Present::getData).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<SpriteProperties> getSprites(Direction dir, int model_id) {
|
||||
return getAppearance(model_id).sprites().get(dir);
|
||||
public @NotNull List<SpriteProperties> getSprites(Direction dir, long seed) {
|
||||
return getAppearance(seed).sprites().get(dir);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasColor(Direction dir, int model_id, int index) {
|
||||
List<SpriteProperties> properties = getSprites(dir, model_id);
|
||||
public boolean hasColor(Direction dir, long seed, int index) {
|
||||
List<SpriteProperties> properties = getSprites(dir, seed);
|
||||
if (index != 0) index = properties.size() - index;
|
||||
return properties.get(index).has_colors();
|
||||
}
|
||||
@ -46,7 +59,13 @@ public class WeightedComputedAppearance extends CamoAppearance {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(this == o) return true;
|
||||
if(!(o instanceof WeightedComputedAppearance that)) return false;
|
||||
if(o == null || getClass() != o.getClass()) return false;
|
||||
WeightedComputedAppearance that = (WeightedComputedAppearance) o;
|
||||
return id == that.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,9 @@ public class GLanguage extends FabricLanguageProvider {
|
||||
public void generateTranslations(TranslationBuilder builder) {
|
||||
builder.add(Registries.ITEM_GROUP.getKey(ReFramed.ITEM_GROUP).get(), "Frames");
|
||||
builder.add("advancements.reframed.description", "Get all the frame types.");
|
||||
ReFramed.BLOCKS.forEach(block -> builder.add(block, beautify(Registries.BLOCK.getId(block).getPath()) + " Frame"));
|
||||
ReFramed.BLOCKS.forEach(block -> {
|
||||
builder.add(block, beautify(Registries.BLOCK.getId(block).getPath()) + " Frame");
|
||||
});
|
||||
}
|
||||
|
||||
private static String beautify(String name) {
|
||||
|
@ -11,7 +11,9 @@ import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtHelper;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
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.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@ -21,6 +23,8 @@ import static fr.adrien1106.reframed.block.ReFramedEntity.BLOCKSTATE_KEY;
|
||||
@Mixin(BlockItem.class)
|
||||
public class BlockItemMixin {
|
||||
|
||||
@Shadow @Final @Deprecated private Block block;
|
||||
|
||||
@Inject(
|
||||
method = "writeNbtToBlockEntity",
|
||||
at = @At(
|
||||
@ -37,7 +41,6 @@ public class BlockItemMixin {
|
||||
|| !Block.isShapeFullCube(block.getBlock().getDefaultState().getCollisionShape(world, pos))
|
||||
) return;
|
||||
NbtCompound new_comp = new NbtCompound();
|
||||
player.getOffHandStack().decrement(1);
|
||||
new_comp.put(BLOCKSTATE_KEY + 1, NbtHelper.fromBlockState(block.getBlock().getDefaultState()));
|
||||
compound.set(new_comp);
|
||||
}
|
||||
|
@ -21,11 +21,9 @@ public class CompatMixinPlugin implements IMixinConfigPlugin {
|
||||
"fr.adrien1106.reframed.mixin.compat.AthenaBakedModelMixin", () -> LOADER.isModLoaded(COMPAT_MOD.get(0)),
|
||||
"fr.adrien1106.reframed.mixin.compat.AthenaWrappedGetterMixin", () -> LOADER.isModLoaded(COMPAT_MOD.get(0)),
|
||||
"fr.adrien1106.reframed.mixin.render.TerrainRenderContextMixin", () -> !LOADER.isModLoaded(COMPAT_MOD.get(1)),
|
||||
"fr.adrien1106.reframed.mixin.render.BlockRenderInfoMixin", () -> !LOADER.isModLoaded(COMPAT_MOD.get(1)),
|
||||
"fr.adrien1106.reframed.mixin.render.AbstractBlockRenderContextMixin", () -> !LOADER.isModLoaded(COMPAT_MOD.get(1)),
|
||||
"fr.adrien1106.reframed.mixin.compat.IndiumTerrainRenderContextMixin", () -> LOADER.isModLoaded(COMPAT_MOD.get(1)),
|
||||
"fr.adrien1106.reframed.mixin.render.BlockRenderInfoMixin", () -> !LOADER.isModLoaded(COMPAT_MOD.get(1)),
|
||||
"fr.adrien1106.reframed.mixin.compat.IndiumTerrainBlockRenderInfoMixin", () -> LOADER.isModLoaded(COMPAT_MOD.get(1)),
|
||||
"fr.adrien1106.reframed.mixin.compat.IndiumAbstractBlockRenderContextMixin", () -> LOADER.isModLoaded(COMPAT_MOD.get(1)),
|
||||
"fr.adrien1106.reframed.mixin.compat.SodiumBlockOcclusionCacheMixin", () -> LOADER.isModLoaded(COMPAT_MOD.get(2))
|
||||
);
|
||||
|
||||
|
@ -6,7 +6,7 @@ import earth.terrarium.athena.api.client.models.AthenaBlockModel;
|
||||
import fr.adrien1106.reframed.client.ReFramedClient;
|
||||
import fr.adrien1106.reframed.client.model.DynamicBakedModel;
|
||||
import fr.adrien1106.reframed.compat.RebakedAthenaModel;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import net.fabricmc.fabric.api.renderer.v1.Renderer;
|
||||
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
|
||||
|
@ -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.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
@ -2,7 +2,7 @@ package fr.adrien1106.reframed.mixin.compat;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import earth.terrarium.athena.api.client.fabric.WrappedGetter;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
|
@ -1,29 +0,0 @@
|
||||
package fr.adrien1106.reframed.mixin.compat;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.mixin.IBlockRenderInfoMixin;
|
||||
import link.infra.indium.renderer.mesh.MutableQuadViewImpl;
|
||||
import link.infra.indium.renderer.render.AbstractBlockRenderContext;
|
||||
import link.infra.indium.renderer.render.BlockRenderInfo;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
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.Redirect;
|
||||
|
||||
@Mixin(AbstractBlockRenderContext.class)
|
||||
public abstract class IndiumAbstractBlockRenderContextMixin {
|
||||
|
||||
@Shadow(remap = false) protected BlockRenderInfo blockInfo;
|
||||
|
||||
@Shadow public abstract boolean isFaceCulled(@Nullable Direction face);
|
||||
|
||||
@Redirect(method = "renderQuad", at = @At(value = "INVOKE", target = "Llink/infra/indium/renderer/render/AbstractBlockRenderContext;isFaceCulled(Lnet/minecraft/util/math/Direction;)Z"))
|
||||
private boolean shouldDrawInnerQuad(AbstractBlockRenderContext instance, Direction face, @Local(argsOnly = true) MutableQuadViewImpl quad) {
|
||||
if (face != null || quad.tag() == 0 || !(blockInfo instanceof IBlockRenderInfoMixin info) || info.getThemeIndex() == 0) return isFaceCulled(face);
|
||||
|
||||
return !BlockHelper.shouldDrawInnerFace(blockInfo.blockState, blockInfo.blockView, blockInfo.blockPos, quad.tag() >>> 8, info.getThemeIndex());
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package fr.adrien1106.reframed.mixin.compat;
|
||||
|
||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.mixin.IBlockRenderInfoMixin;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.IBlockRenderInfoMixin;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import link.infra.indium.renderer.render.BlockRenderInfo;
|
||||
import link.infra.indium.renderer.render.TerrainBlockRenderInfo;
|
||||
import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockOcclusionCache;
|
||||
@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
@Mixin(TerrainBlockRenderInfo.class)
|
||||
public abstract class IndiumTerrainBlockRenderInfoMixin extends BlockRenderInfo implements IBlockRenderInfoMixin {
|
||||
|
||||
@Unique private int theme_index = 0;
|
||||
@Unique private int theme_index = 1;
|
||||
|
||||
@Redirect(
|
||||
method = "shouldDrawFaceInner",
|
||||
@ -40,9 +40,4 @@ public abstract class IndiumTerrainBlockRenderInfoMixin extends BlockRenderInfo
|
||||
this.theme_index = theme_index;
|
||||
prepareForBlock(blockState, blockPos, seed, modelAo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getThemeIndex() {
|
||||
return theme_index;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,11 @@
|
||||
package fr.adrien1106.reframed.mixin.compat;
|
||||
|
||||
import fr.adrien1106.reframed.client.model.MultiRetexturableModel;
|
||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.mixin.IBlockRenderInfoMixin;
|
||||
import fr.adrien1106.reframed.util.mixin.IMultipartBakedModelMixin;
|
||||
import fr.adrien1106.reframed.util.IBlockRenderInfoMixin;
|
||||
import fr.adrien1106.reframed.util.IMultipartBakedModelMixin;
|
||||
import link.infra.indium.renderer.render.AbstractBlockRenderContext;
|
||||
import link.infra.indium.renderer.render.TerrainRenderContext;
|
||||
import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderContext;
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@ -31,14 +29,13 @@ public abstract class IndiumTerrainRenderContextMixin extends AbstractBlockRende
|
||||
if (!(ctx.model() instanceof IMultipartBakedModelMixin wrapped)
|
||||
|| !(wrapped.getModel(ctx.state()) instanceof MultiRetexturableModel retexturing_model)) return;
|
||||
|
||||
List<ForwardingBakedModel> models = retexturing_model.models();
|
||||
BlockHelper.computeInnerCull(ctx.state(), models);
|
||||
List<BakedModel> models = retexturing_model.models();
|
||||
int i = 0;
|
||||
for (BakedModel model : models) {
|
||||
for (BakedModel bakedModel : models) {
|
||||
i++;
|
||||
aoCalc.clear();
|
||||
((IBlockRenderInfoMixin) blockInfo).prepareForBlock(ctx.state(), ctx.pos(), ctx.seed(), model.useAmbientOcclusion(), i);
|
||||
model.emitBlockQuads(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, blockInfo.randomSupplier, this);
|
||||
((IBlockRenderInfoMixin) blockInfo).prepareForBlock(ctx.state(), ctx.pos(), ctx.seed(), bakedModel.useAmbientOcclusion(), i);
|
||||
bakedModel.emitBlockQuads(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, blockInfo.randomSupplier, this);
|
||||
}
|
||||
ci.cancel();
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package fr.adrien1106.reframed.mixin.compat;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockOcclusionCache;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.adrien1106.reframed.mixin.particles;
|
||||
|
||||
import fr.adrien1106.reframed.block.ReFramedBlock;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.particle.BlockDustParticle;
|
||||
|
@ -2,7 +2,7 @@ package fr.adrien1106.reframed.mixin.particles;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import fr.adrien1106.reframed.block.ReFramedBlock;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -2,7 +2,7 @@ package fr.adrien1106.reframed.mixin.particles;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import fr.adrien1106.reframed.block.ReFramedBlock;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
@ -1,36 +0,0 @@
|
||||
package fr.adrien1106.reframed.mixin.render;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.mixin.IBlockRenderInfoMixin;
|
||||
import net.fabricmc.fabric.impl.client.indigo.renderer.mesh.MutableQuadViewImpl;
|
||||
import net.fabricmc.fabric.impl.client.indigo.renderer.render.AbstractBlockRenderContext;
|
||||
import net.fabricmc.fabric.impl.client.indigo.renderer.render.BlockRenderInfo;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
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.Redirect;
|
||||
|
||||
@Mixin(AbstractBlockRenderContext.class)
|
||||
public abstract class AbstractBlockRenderContextMixin {
|
||||
|
||||
@Shadow public abstract boolean isFaceCulled(@Nullable Direction face);
|
||||
|
||||
@Shadow(remap = false) @Final protected BlockRenderInfo blockInfo;
|
||||
|
||||
@Redirect(
|
||||
method = "renderQuad",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/fabricmc/fabric/impl/client/indigo/renderer/render/AbstractBlockRenderContext;isFaceCulled(Lnet/minecraft/util/math/Direction;)Z"
|
||||
)
|
||||
)
|
||||
private boolean shouldDrawInnerQuad(AbstractBlockRenderContext instance, Direction face, @Local(argsOnly = true) MutableQuadViewImpl quad) {
|
||||
if (face != null || quad.tag() == 0 || !(blockInfo instanceof IBlockRenderInfoMixin info) || info.getThemeIndex() == 0) return isFaceCulled(face);
|
||||
|
||||
return !BlockHelper.shouldDrawInnerFace(blockInfo.blockState, blockInfo.blockView, blockInfo.blockPos, quad.tag() >>> 8, info.getThemeIndex());
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package fr.adrien1106.reframed.mixin.render;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.mixin.IBlockRenderInfoMixin;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.IBlockRenderInfoMixin;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import net.fabricmc.fabric.impl.client.indigo.renderer.render.BlockRenderInfo;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
@ -24,7 +24,8 @@ public abstract class BlockRenderInfoMixin implements IBlockRenderInfoMixin {
|
||||
@Shadow public abstract void prepareForBlock(BlockState blockState, BlockPos blockPos, boolean modelAo);
|
||||
|
||||
@Shadow public BlockRenderView blockView;
|
||||
@Unique private int theme_index = 0;
|
||||
@Unique
|
||||
private int theme_index = 1;
|
||||
|
||||
@ModifyArg(method = "prepareForBlock",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/RenderLayers;" +
|
||||
@ -46,9 +47,4 @@ public abstract class BlockRenderInfoMixin implements IBlockRenderInfoMixin {
|
||||
this.theme_index = theme_index;
|
||||
prepareForBlock(state, pos, ao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getThemeIndex() {
|
||||
return theme_index;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package fr.adrien1106.reframed.mixin.render;
|
||||
|
||||
import fr.adrien1106.reframed.util.mixin.IMultipartBakedModelMixin;
|
||||
import fr.adrien1106.reframed.util.IMultipartBakedModelMixin;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.MultipartBakedModel;
|
||||
|
@ -1,10 +1,8 @@
|
||||
package fr.adrien1106.reframed.mixin.render;
|
||||
|
||||
import fr.adrien1106.reframed.client.model.MultiRetexturableModel;
|
||||
import fr.adrien1106.reframed.util.blocks.BlockHelper;
|
||||
import fr.adrien1106.reframed.util.mixin.IBlockRenderInfoMixin;
|
||||
import fr.adrien1106.reframed.util.mixin.IMultipartBakedModelMixin;
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel;
|
||||
import fr.adrien1106.reframed.util.IBlockRenderInfoMixin;
|
||||
import fr.adrien1106.reframed.util.IMultipartBakedModelMixin;
|
||||
import net.fabricmc.fabric.impl.client.indigo.renderer.render.AbstractBlockRenderContext;
|
||||
import net.fabricmc.fabric.impl.client.indigo.renderer.render.TerrainRenderContext;
|
||||
import net.minecraft.block.BlockState;
|
||||
@ -30,14 +28,13 @@ public abstract class TerrainRenderContextMixin extends AbstractBlockRenderConte
|
||||
if (!(wrapper instanceof IMultipartBakedModelMixin wrapped)
|
||||
|| !(wrapped.getModel(state) instanceof MultiRetexturableModel retexturing_model)) return;
|
||||
|
||||
List<ForwardingBakedModel> models = retexturing_model.models();
|
||||
BlockHelper.computeInnerCull(state, models);
|
||||
List<BakedModel> models = retexturing_model.models();
|
||||
int i = 0;
|
||||
for (BakedModel model : models) {
|
||||
for (BakedModel bakedModel : models) {
|
||||
i++;
|
||||
aoCalc.clear();
|
||||
((IBlockRenderInfoMixin) blockInfo).prepareForBlock(state, pos, model.useAmbientOcclusion(), i);
|
||||
model.emitBlockQuads(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, blockInfo.randomSupplier, this);
|
||||
((IBlockRenderInfoMixin) blockInfo).prepareForBlock(state, pos, bakedModel.useAmbientOcclusion(), i);
|
||||
bakedModel.emitBlockQuads(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, blockInfo.randomSupplier, this);
|
||||
}
|
||||
ci.cancel();
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package fr.adrien1106.reframed.mixin.sound;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import fr.adrien1106.reframed.block.ReFramedBlock;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.BlockItem;
|
||||
|
@ -2,7 +2,7 @@ package fr.adrien1106.reframed.mixin.sound;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import fr.adrien1106.reframed.block.ReFramedBlock;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.adrien1106.reframed.mixin.sound;
|
||||
|
||||
import fr.adrien1106.reframed.block.ReFramedBlock;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
@ -2,7 +2,7 @@ package fr.adrien1106.reframed.mixin.sound;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import fr.adrien1106.reframed.block.ReFramedBlock;
|
||||
import fr.adrien1106.reframed.util.blocks.ThemeableBlockEntity;
|
||||
import fr.adrien1106.reframed.util.ThemeableBlockEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.render.WorldRenderer;
|
||||
|
@ -1,15 +1,9 @@
|
||||
package fr.adrien1106.reframed.util.blocks;
|
||||
package fr.adrien1106.reframed.util;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import fr.adrien1106.reframed.block.ReFramedBlock;
|
||||
import fr.adrien1106.reframed.block.ReFramedEntity;
|
||||
import fr.adrien1106.reframed.client.ReFramedClient;
|
||||
import fr.adrien1106.reframed.client.model.QuadPosBounds;
|
||||
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.ForwardingBakedModel;
|
||||
import fr.adrien1106.reframed.util.property.Corner;
|
||||
import fr.adrien1106.reframed.util.property.StairShape;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockEntityProvider;
|
||||
import net.minecraft.block.BlockState;
|
||||
@ -25,32 +19,24 @@ import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static fr.adrien1106.reframed.util.blocks.BlockProperties.CORNER;
|
||||
import static fr.adrien1106.reframed.util.blocks.BlockProperties.LIGHT;
|
||||
import static fr.adrien1106.reframed.util.blocks.StairShape.*;
|
||||
import static fr.adrien1106.reframed.util.BlockProperties.CORNER;
|
||||
import static fr.adrien1106.reframed.util.BlockProperties.LIGHT;
|
||||
import static fr.adrien1106.reframed.util.property.StairShape.*;
|
||||
import static net.minecraft.util.shape.VoxelShapes.combine;
|
||||
|
||||
public class BlockHelper {
|
||||
|
||||
// self culling cache of the models not made thread local so that it is only computed once
|
||||
private static final Cache<CullElement, Integer[]> INNER_CULL_MAP = CacheBuilder.newBuilder().maximumSize(1024).build();
|
||||
|
||||
private record CullElement(Object state_key, int model) {}
|
||||
|
||||
public static Corner getPlacementCorner(ItemPlacementContext ctx) {
|
||||
Direction side = ctx.getSide().getOpposite();
|
||||
Vec3d pos = getHitPos(ctx.getHitPos(), ctx.getBlockPos());
|
||||
@ -72,7 +58,7 @@ public class BlockHelper {
|
||||
Math.abs(axis_1.choose(pos.x, pos.y, pos.z)) > Math.abs(axis_2.choose(pos.x, pos.y, pos.z))
|
||||
? axis_1
|
||||
: axis_2
|
||||
).orElse(null);
|
||||
).get();
|
||||
}
|
||||
|
||||
public static Vec3d getRelativePos(Vec3d pos, BlockPos block_pos) {
|
||||
@ -219,66 +205,6 @@ public class BlockHelper {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* compute which quad might cull with another model quad
|
||||
* @param state - the state of the model
|
||||
* @param models - list of models on the same block
|
||||
*/
|
||||
public static void computeInnerCull(BlockState state, List<ForwardingBakedModel> models) {
|
||||
if (!(state.getBlock() instanceof ReFramedBlock frame_block)) return;
|
||||
Object key = frame_block.getModelCacheKey(state);
|
||||
if (INNER_CULL_MAP.asMap().containsKey(new CullElement(key, 1))) return;
|
||||
|
||||
Renderer r = ReFramedClient.HELPER.getFabricRenderer();
|
||||
QuadEmitter quad_emitter = r.meshBuilder().getEmitter();
|
||||
RenderMaterial material = r.materialFinder().clear().find();
|
||||
Random random = Random.create();
|
||||
|
||||
List<List<QuadPosBounds>> model_bounds = models.stream()
|
||||
.map(ForwardingBakedModel::getWrappedModel)
|
||||
.filter(Objects::nonNull)
|
||||
.map(wrapped -> wrapped.getQuads(state, null, random))
|
||||
.map(quads -> quads.stream().map(quad -> {
|
||||
quad_emitter.fromVanilla(quad, material, null);
|
||||
return QuadPosBounds.read(quad_emitter, false);
|
||||
}).toList()).toList();
|
||||
|
||||
Integer[] cull_array;
|
||||
for(int self_id = 1; self_id <= model_bounds.size(); self_id++) {
|
||||
List<QuadPosBounds> self_bounds = model_bounds.get(self_id - 1);
|
||||
cull_array = new Integer[self_bounds.size()];
|
||||
for (int self_quad = 0; self_quad < cull_array.length; self_quad++) {
|
||||
QuadPosBounds self_bound = self_bounds.get(self_quad);
|
||||
for(int other_id = 1; other_id <= model_bounds.size(); other_id++) {
|
||||
if (other_id == self_id) continue;
|
||||
if (model_bounds.get(other_id - 1).stream().anyMatch(other_bound -> other_bound.equals(self_bound))) {
|
||||
cull_array[self_quad] = other_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
INNER_CULL_MAP.put(new CullElement(key, self_id), cull_array);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean shouldDrawInnerFace(BlockState state, BlockRenderView view, BlockPos pos, int quad_index, int theme_index) {
|
||||
if ( !(state.getBlock() instanceof ReFramedBlock frame_block)
|
||||
|| !(view.getBlockEntity(pos) instanceof ThemeableBlockEntity frame_entity)
|
||||
) return true;
|
||||
CullElement key = new CullElement(frame_block.getModelCacheKey(state), theme_index);
|
||||
if (!INNER_CULL_MAP.asMap().containsKey(key)) return true;
|
||||
|
||||
// needs to be Integer object because array is initialized with null not 0
|
||||
Integer cull_theme = Objects.requireNonNull(INNER_CULL_MAP.getIfPresent(key))[quad_index];
|
||||
if (cull_theme == null) return true; // no culling possible
|
||||
|
||||
BlockState self_theme = frame_entity.getTheme(theme_index);
|
||||
BlockState other_theme = frame_entity.getTheme(cull_theme);
|
||||
|
||||
if (self_theme.isSideInvisible(other_theme, null)) return false;
|
||||
return !self_theme.isOpaque() || !other_theme.isOpaque();
|
||||
}
|
||||
|
||||
// Doing this method from scratch as it is simpler to do than injecting everywhere
|
||||
public static boolean shouldDrawSide(BlockState self_state, BlockView world, BlockPos pos, Direction side, BlockPos other_pos, int theme_index) {
|
||||
ThemeableBlockEntity self = world.getBlockEntity(pos) instanceof ThemeableBlockEntity e ? e : null;
|
@ -1,5 +1,7 @@
|
||||
package fr.adrien1106.reframed.util.blocks;
|
||||
package fr.adrien1106.reframed.util;
|
||||
|
||||
import fr.adrien1106.reframed.util.property.Corner;
|
||||
import fr.adrien1106.reframed.util.property.StairShape;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package fr.adrien1106.reframed.util.mixin;
|
||||
package fr.adrien1106.reframed.util;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@ -8,6 +8,4 @@ public interface IBlockRenderInfoMixin {
|
||||
void prepareForBlock(BlockState state, BlockPos pos, boolean ao, int theme_index);
|
||||
|
||||
void prepareForBlock(BlockState state, BlockPos pos, long seed, boolean ao, int theme_index);
|
||||
|
||||
int getThemeIndex();
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package fr.adrien1106.reframed.util.mixin;
|
||||
package fr.adrien1106.reframed.util;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
@ -1,4 +1,4 @@
|
||||
package fr.adrien1106.reframed.util.blocks;
|
||||
package fr.adrien1106.reframed.util;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
@ -1,4 +1,4 @@
|
||||
package fr.adrien1106.reframed.util.blocks;
|
||||
package fr.adrien1106.reframed.util;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package fr.adrien1106.reframed.util.blocks;
|
||||
package fr.adrien1106.reframed.util.property;
|
||||
|
||||
import net.minecraft.util.StringIdentifiable;
|
||||
import net.minecraft.util.math.Direction;
|
@ -1,4 +1,4 @@
|
||||
package fr.adrien1106.reframed.util.blocks;
|
||||
package fr.adrien1106.reframed.util.property;
|
||||
|
||||
import net.minecraft.util.StringIdentifiable;
|
||||
|
@ -30,7 +30,7 @@
|
||||
"fabricloader": "^${loader_version}",
|
||||
"fabric-api": "*"
|
||||
},
|
||||
"suggests": {
|
||||
"suggest": {
|
||||
"athena": "^${athena_version}",
|
||||
"sodium": "^${sodium_version}",
|
||||
"indium": "^${indium_version}"
|
||||
|
@ -14,7 +14,6 @@
|
||||
"compat.AthenaBakedModelMixin",
|
||||
"compat.AthenaConnectedBlockModelMixin",
|
||||
"compat.AthenaWrappedGetterMixin",
|
||||
"compat.IndiumAbstractBlockRenderContextMixin",
|
||||
"compat.IndiumTerrainBlockRenderInfoMixin",
|
||||
"compat.IndiumTerrainRenderContextMixin",
|
||||
"compat.SodiumBlockOcclusionCacheMixin",
|
||||
@ -22,7 +21,6 @@
|
||||
"particles.AccessorParticle",
|
||||
"particles.AccessorSpriteBillboardParticle",
|
||||
"particles.MixinBlockDustParticle",
|
||||
"render.AbstractBlockRenderContextMixin",
|
||||
"render.BlockRenderInfoMixin",
|
||||
"render.MultipartBakedModelMixin",
|
||||
"render.TerrainRenderContextMixin",
|
||||
|
Loading…
Reference in New Issue
Block a user