Skip to content

Commit

Permalink
Improved interaction with passable leaves
Browse files Browse the repository at this point in the history
isLeavesPassable = false & vanillaLeavesCollision = false
- default dynamic trees behavior, slightly sink in leaves and get slowed down.
isLeavesPassable = true & vanillaLeavesCollision = false
- Pass through leaves but still get slowed down by them
isLeavesPassable = false & vanillaLeavesCollision = true
- Vanilla-like leaves, blocks are solid and you can run on them but still break.
isLeavesPassable = true & vanillaLeavesCollision = true
- Completely transparent leaves, you can run through them and they don't catch your fall
  • Loading branch information
supermassimo committed Dec 9, 2024
1 parent 7a6631f commit 6d58ac8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
modName=DynamicTrees
modId=dynamictrees
modVersion=1.3.5
modVersion=1.3.6

group=com.ferreusveritas.dynamictrees

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.ferreusveritas.dynamictrees.api.network.MapSignal;
import com.ferreusveritas.dynamictrees.api.treedata.TreePart;
import com.ferreusveritas.dynamictrees.block.branch.BranchBlock;
import com.ferreusveritas.dynamictrees.data.DTEntityTypeTags;
import com.ferreusveritas.dynamictrees.init.DTClient;
import com.ferreusveritas.dynamictrees.init.DTConfigs;
import com.ferreusveritas.dynamictrees.item.Seed;
Expand Down Expand Up @@ -252,11 +253,19 @@ public boolean addLandingEffects(BlockState state1, ServerLevel level, BlockPos
return true;
}

@Override
public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
if (this.isEntityPassable(pContext)) {
return Shapes.empty();
}
return super.getShape(pState, pLevel, pPos, pContext);
}

@Override
public VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
if (isLeavesPassable() || this.isEntityPassable(context)) {
return Shapes.empty();
} else if (DTConfigs.SERVER_CONFIG.isLoaded() && DTConfigs.VANILLA_LEAVES_COLLISION.get()) {
} else if (isMovementVanilla()) {
return Shapes.block();
} else {
return Shapes.create(new AABB(0.125, 0, 0.125, 0.875, 0.50, 0.875));
Expand All @@ -272,6 +281,10 @@ public VoxelShape getBlockSupportShape(BlockState pState, BlockGetter pReader, B
return SUPPORT_SHAPE;
}

protected boolean isMovementVanilla(){
return DTConfigs.SERVER_CONFIG.isLoaded() && DTConfigs.VANILLA_LEAVES_COLLISION.get();
}

protected boolean isLeavesPassable() {
return (DTConfigs.SERVER_CONFIG.isLoaded() && DTConfigs.IS_LEAVES_PASSABLE.get()) || ModList.get().isLoaded(DynamicTrees.PASSABLE_FOLIAGE);
}
Expand All @@ -285,18 +298,12 @@ public boolean isEntityPassable(CollisionContext context) {

public boolean isEntityPassable(@Nullable Entity entity) {
if (entity instanceof Projectile) //Projectiles such as arrows fly through leaves
{
return true;
}
if (entity instanceof ItemEntity) //Seed items fall through leaves
{
return ((ItemEntity) entity).getItem().getItem() instanceof Seed;
}
if (entity instanceof LivingEntity) //Bees fly through leaves, otherwise they get stuck :(
{
return entity instanceof Bee;
}
return false;

//Bees fly through leaves, otherwise they get stuck :(
return entity != null && entity.getType().is(DTEntityTypeTags.CAN_PASS_THROUGH_LEAVES);
}

/**
Expand Down Expand Up @@ -354,13 +361,13 @@ public void fallOn(Level level, BlockState blockState, BlockPos pos, Entity enti

@Override
public void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) {
if (isLeavesPassable() || isEntityPassable(entity)) {
if (isMovementVanilla() || isEntityPassable(entity)) {
super.entityInside(state, level, pos, entity);
} else {
if (entity.getDeltaMovement().y < 0.0D && entity.fallDistance < 2.0f) {
entity.fallDistance = 0.0f;
entity.setDeltaMovement(entity.getDeltaMovement().x, entity.getDeltaMovement().y * 0.5D, entity.getDeltaMovement().z); // Slowly sink into the block
} else if (entity.getDeltaMovement().y > 0 && entity.getDeltaMovement().y < 0.25D) {
} else if (!isLeavesPassable() && entity.getDeltaMovement().y > 0 && entity.getDeltaMovement().y < 0.25D) {
entity.setDeltaMovement(entity.getDeltaMovement().x, entity.getDeltaMovement().y + 0.025, entity.getDeltaMovement().z); // Allow a little climbing
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
public final class DTEntityTypeTags {

public static final TagKey<EntityType<?>> CAN_PASS_THROUGH_LEAVES = bind("can_pass_through_leaves");
public static final TagKey<EntityType<?>> FALLING_TREE_DAMAGE_IMMUNE = bind("falling_tree_damage_immune");

private static TagKey<EntityType<?>> bind(String identifier) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"minecraft:bee"
]
}

0 comments on commit 6d58ac8

Please sign in to comment.