v1.5 new shapes + self culling + caching + coding tools/cleanup #10

Merged
Adrien1106 merged 11 commits from dev into master 2024-03-14 22:30:30 +01:00
4 changed files with 25 additions and 17 deletions
Showing only changes of commit b1ba784ee3 - Show all commits

View File

@ -27,13 +27,13 @@ import java.util.stream.Collectors;
import static fr.adrien1106.reframed.util.blocks.BlockProperties.LIGHT;
/**
* TODO add Hammer from framed ( removes theme ) for sure
* TODO add Hammer from framed ( removes theme ) -> for v1.5.5
* TODO add screwdriver ( iterate over theme states ) ?
* TODO add blueprint for survival friendly copy paste of a theme.
* TODO fix other models ( + half stair + layers )
* TODO get better naming for the shapes (will break a lot of already placed blocks)
* TODO put more coherence in the double theme orders / directions
* TODO better connected textures
* TODO add blueprint for survival friendly copy paste of a theme. -> for v1.5.5
* TODO add minecraft models like wall fence etc -> for v1.6
* TODO ( + half stair + layers ) -> priority for v1.5
* TODO put more coherence in the double theme orders / directions -> maybe v1.6 ?
* TODO better connected textures -> maybe v1.6 ?
*/
public class ReFramed implements ModInitializer {
public static final String MODID = "reframed";
@ -57,6 +57,7 @@ public class ReFramed implements ModInitializer {
// CUBE = registerReFramed("half_stair" , new ReFramedBlock(cp(Blocks.OAK_STAIRS))); // TODO
// CUBE = registerReFramed("half_stairs_stair" , new ReFramedBlock(cp(Blocks.OAK_STAIRS))); // TODO
// CUBE = registerReFramed("half_stairs_slab" , new ReFramedBlock(cp(Blocks.OAK_STAIRS))); // TODO
// CUBE = registerReFramed("layer" , new ReFramedBlock(cp(Blocks.OAK_SLAB))); // TODO
SLAB = registerReFramed("slab" , new ReFramedSlabBlock(cp(Blocks.OAK_SLAB)));
SLABS_CUBE = registerReFramed("slabs_cube" , new ReFramedSlabsCubeBlock(cp(Blocks.OAK_SLAB)));
STEP = registerReFramed("step" , new ReFramedStepBlock(cp(Blocks.OAK_SLAB)));

View File

@ -67,14 +67,14 @@ public class ReFramedStairBlock extends WaterloggableReFramedBlock implements Bl
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighbor_state, WorldAccess world, BlockPos pos, BlockPos moved) {
return super.getStateForNeighborUpdate(state, direction, neighbor_state, world, pos, moved)
.with(STAIR_SHAPE, BlockHelper.getStairsShape(state.getBlock(), state.get(EDGE), world, pos));
.with(STAIR_SHAPE, BlockHelper.getStairsShape(state.get(EDGE), world, pos));
}
@Nullable
@Override // Pretty happy of how clean it is (also got it on first try :) )
public BlockState getPlacementState(ItemPlacementContext ctx) {
Edge face = BlockHelper.getPlacementEdge(ctx);
StairShape shape = BlockHelper.getStairsShape(this, face, ctx.getWorld(), ctx.getBlockPos());
StairShape shape = BlockHelper.getStairsShape(face, ctx.getWorld(), ctx.getBlockPos());
return super.getPlacementState(ctx).with(EDGE, face).with(STAIR_SHAPE, shape);
}

View File

@ -59,7 +59,7 @@ public class ReFramedStairsCubeBlock extends ReFramedDoubleBlock implements Bloc
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighbor_state, WorldAccess world, BlockPos pos, BlockPos moved) {
return super.getStateForNeighborUpdate(state, direction, neighbor_state, world, pos, moved)
.with(STAIR_SHAPE, BlockHelper.getStairsShape(this, state.get(EDGE), world, pos));
.with(STAIR_SHAPE, BlockHelper.getStairsShape(state.get(EDGE), world, pos));
}
@ -67,7 +67,7 @@ public class ReFramedStairsCubeBlock extends ReFramedDoubleBlock implements Bloc
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
Edge face = BlockHelper.getPlacementEdge(ctx);
StairShape shape = BlockHelper.getStairsShape(this, face, ctx.getWorld(), ctx.getBlockPos());
StairShape shape = BlockHelper.getStairsShape(face, ctx.getWorld(), ctx.getBlockPos());
return super.getPlacementState(ctx).with(EDGE, face).with(STAIR_SHAPE, shape);
}

View File

@ -4,6 +4,8 @@ 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.block.ReFramedStairBlock;
import fr.adrien1106.reframed.block.ReFramedStairsCubeBlock;
import fr.adrien1106.reframed.client.ReFramedClient;
import fr.adrien1106.reframed.client.model.QuadPosBounds;
import net.fabricmc.api.EnvType;
@ -109,28 +111,28 @@ public class BlockHelper {
);
}
public static StairShape getStairsShape(Block block, Edge face, BlockView world, BlockPos pos) {
public static StairShape getStairsShape(Edge face, BlockView world, BlockPos pos) {
StairShape shape = STRAIGHT;
String sol = getNeighborPos(face, face.getFirstDirection(), true, face.getSecondDirection(), world, pos, block);
String sol = getNeighborPos(face, face.getFirstDirection(), true, face.getSecondDirection(), world, pos);
switch (sol) {
case "right": return INNER_RIGHT;
case "left": return INNER_LEFT;
}
sol = getNeighborPos(face, face.getSecondDirection(), true, face.getFirstDirection(), world, pos, block);
sol = getNeighborPos(face, face.getSecondDirection(), true, face.getFirstDirection(), world, pos);
switch (sol) {
case "right": return INNER_RIGHT;
case "left": return INNER_LEFT;
}
sol = getNeighborPos(face, face.getFirstDirection(), false, face.getSecondDirection(), world, pos, block);
sol = getNeighborPos(face, face.getFirstDirection(), false, face.getSecondDirection(), world, pos);
switch (sol) {
case "right" -> shape = FIRST_OUTER_RIGHT;
case "left" -> shape = FIRST_OUTER_LEFT;
}
sol = getNeighborPos(face, face.getSecondDirection(), false, face.getFirstDirection(), world, pos, block);
sol = getNeighborPos(face, face.getSecondDirection(), false, face.getFirstDirection(), world, pos);
switch (sol) {
case "right" -> {
if (shape.equals(STRAIGHT)) shape = SECOND_OUTER_RIGHT;
@ -145,18 +147,23 @@ public class BlockHelper {
return shape;
}
public static String getNeighborPos(Edge face, Direction direction, Boolean reverse, Direction reference, BlockView world, BlockPos pos, Block block) {
public static String getNeighborPos(Edge face, Direction direction, Boolean reverse, Direction reference, BlockView world, BlockPos pos) {
BlockState block_state = world.getBlockState(
pos.offset(reverse ? direction.getOpposite() : direction)
);
if (block_state.isOf(block) && block_state.get(EDGE).hasDirection(reference)) {
if (isStair(block_state) && block_state.get(EDGE).hasDirection(reference)) {
if (block_state.get(EDGE).hasDirection(face.getLeftDirection())) return "left";
else if (block_state.get(EDGE).hasDirection(face.getRightDirection())) return "right";
}
return "";
}
public static boolean isStair(BlockState state) {
return state.getBlock() instanceof ReFramedStairBlock
|| state.getBlock() instanceof ReFramedStairsCubeBlock;
}
public static ActionResult useCamo(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, int theme_index) {
if(!(world.getBlockEntity(pos) instanceof ReFramedEntity block_entity)) return ActionResult.PASS;