Skip to content

Commit

Permalink
Fixed mangrove roots occlusion
Browse files Browse the repository at this point in the history
  • Loading branch information
supermassimo committed Aug 8, 2024
1 parent 9b43a92 commit 4cd8592
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,6 @@ public boolean checkForRot(LevelAccessor level, BlockPos pos, Species species, i
// SHAPE
//////////////////////////////

@Override
public VoxelShape getOcclusionShape(BlockState pState, BlockGetter pLevel, BlockPos pPos) {
if (pState.getValue(LAYER) == Layer.EXPOSED) return Shapes.empty();
return super.getOcclusionShape(pState, pLevel, pPos);
}

@Override
public VoxelShape getCollisionShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
if (isFullBlock(pState)) {
Expand Down Expand Up @@ -538,6 +532,33 @@ protected int getSideConnectionRadius(BlockGetter level, BlockPos pos, int radiu
return blockState == null ? 0 : TreeHelper.getTreePart(blockState).getRadiusForConnection(blockState, level, deltaPos, this, side, radius);
}

@Override
public VoxelShape getOcclusionShape(BlockState pState, BlockGetter pLevel, BlockPos pPos) {
if (isTransparent(pState)){
return Shapes.empty();
}
return super.getOcclusionShape(pState, pLevel, pPos);
}

@Override
public VoxelShape getVisualShape(BlockState pState, BlockGetter pReader, BlockPos pPos, CollisionContext pContext) {
if (isTransparent(pState)){
return Shapes.empty();
}
return super.getVisualShape(pState, pReader, pPos, pContext);
}

@Override
public boolean skipRendering(BlockState pState, BlockState pAdjacentBlockState, Direction pSide) {
return (pAdjacentBlockState.is(this) && pAdjacentBlockState.getValue(LAYER).ordinal() >= pState.getValue(LAYER).ordinal())
|| super.skipRendering(pState, pAdjacentBlockState, pSide);
}

public static boolean isTransparent (BlockState state){
return state.getBlock() instanceof BasicRootsBlock
&& state.getValue(LAYER) == Layer.EXPOSED;
}

//////////////////////////////
// GROWTH
//////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.common.ForgeMod;
import net.minecraftforge.common.ToolActions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ferreusveritas.dynamictrees.models.baked;

import com.ferreusveritas.dynamictrees.block.branch.BasicRootsBlock;
import com.ferreusveritas.dynamictrees.client.ModelUtils;
import com.ferreusveritas.dynamictrees.models.modeldata.ModelConnections;
import com.google.common.collect.Maps;
Expand Down Expand Up @@ -29,7 +30,7 @@
@OnlyIn(Dist.CLIENT)
public class BasicRootsBlockBakedModel extends BasicBranchBlockBakedModel {

private final BakedModel[][] sleeveFaces = new BakedModel[6][7];
private final BakedModel[][] sleeveFaces = new BakedModel[6][8];

public BasicRootsBlockBakedModel(IGeometryBakingContext customData, ResourceLocation modelLocation, ResourceLocation barkTextureLocation, ResourceLocation ringsTextureLocation,
Function<Material, TextureAtlasSprite> spriteGetter) {
Expand All @@ -41,10 +42,8 @@ private void initModels() {
if (getRenderType() == RenderType.solid()){
for (int i = 0; i < 8; i++) {
int radius = i + 1;
if (radius < 8) {
for (Direction dir : Direction.values()) {
sleeveFaces[dir.get3DDataValue()][i] = bakeSleeveFace(radius, dir, ringsTexture);
}
for (Direction dir : Direction.values()) {
sleeveFaces[dir.get3DDataValue()][i] = bakeSleeveFace(radius, dir, ringsTexture);
}
}
}
Expand Down Expand Up @@ -133,12 +132,10 @@ public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction
connections = connectionsData.getAllRadii();
}

if (coreRadius != 8) {
final int idx = side.get3DDataValue();
final int connRadius = connections[idx];
if (connRadius > 0) {
quadsList.addAll(sleeveFaces[idx][connRadius - 1].getQuads(state, side, rand, extraData, renderType));
}
final int idx = side.get3DDataValue();
final int connRadius = connections[idx];
if (connRadius > 0) {
quadsList.addAll(sleeveFaces[idx][connRadius - 1].getQuads(state, side, rand, extraData, renderType));
}

return quadsList;
Expand Down

0 comments on commit 4cd8592

Please sign in to comment.