Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Commit

Permalink
small tweak
Browse files Browse the repository at this point in the history
- crawl & crouch
- rails are no longer avoided
  • Loading branch information
SiverDX committed Sep 26, 2023
1 parent 6b21fc0 commit 754e156
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ geckolib_version_range=[4.2,)
mod_id=cave_dweller
mod_name=cave_dweller
mod_license=MIT
mod_version=1.6.3
mod_version=1.6.4
mod_group_id=de.cadentem
mod_authors=Cadentem
mod_description=Fork of the Cave Dweller mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.pathfinder.BlockPathTypes;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.ForgeMod;
import net.minecraftforge.network.PacketDistributor;
Expand Down Expand Up @@ -85,6 +86,7 @@ public CaveDwellerEntity(final EntityType<? extends CaveDwellerEntity> entityTyp
super(entityType, level);
this.refreshDimensions();
this.ticksTillRemove = Utils.secondsToTicks(ServerConfig.TIME_UNTIL_LEAVE.get());
this.setPathfindingMalus(BlockPathTypes.UNPASSABLE_RAIL, 0.0f);
}

@Override
Expand Down Expand Up @@ -196,7 +198,7 @@ public void tick() {
}

/* [- : blocks | o : cave dweller]
To handle these variants:
To handle these variants among other things:
o -----
----o ----o o
o o o
Expand All @@ -206,16 +208,21 @@ public void tick() {
boolean isTwoAboveSolid = level().getBlockState(blockPosition().above(2)).isSolid();
boolean isThreeAboveSolid = level().getBlockState(blockPosition().above(3)).isSolid();

Vec3i offset = new Vec3i(getDirection().getStepX(), getDirection().getStepY(), getDirection().getStepZ());
Vec3i offset = getDirectionVector();
boolean isFacingSolid = level().getBlockState(blockPosition().relative(getDirection())).isSolid();

/* Offset is set to the block above the block position (which is at feet level) (since direction is used it's the block in front for both cases)
-----o -----o
o o <- offset
-----o <- current -----o
*/
if (isFacingSolid) {
offset = offset.offset(0, 1, 0);
}

boolean isOffsetFacingSolid = level().getBlockState(blockPosition().offset(offset)).isSolid();
boolean isOffsetFacingAboveSolid = level().getBlockState(blockPosition().offset(offset).above()).isSolid();
boolean isOffsetFacingTwoAboveSolid = level().getBlockState(blockPosition().offset(offset).above(2)).isSolid();
boolean isOffsetFacingAboveSolid = level().getBlockState(blockPosition().relative(getDirection()).above()).isSolid();

boolean shouldCrouch = isTwoAboveSolid || (!isOffsetFacingSolid && !isOffsetFacingAboveSolid && (isOffsetFacingTwoAboveSolid || isFacingSolid && isThreeAboveSolid)) ;
boolean shouldCrawl = isAboveSolid || (!isOffsetFacingSolid && isOffsetFacingAboveSolid);
Expand Down Expand Up @@ -304,10 +311,17 @@ public void setClimbing(boolean isClimbing) {
}

private PlayState predicate(final AnimationState<CaveDwellerEntity> state) {
if (level().getBlockState(blockPosition().above()).isSolid()) {
boolean isCurrentAboveSolid = level().getBlockState(blockPosition().above()).isSolid();
boolean unsure = isCrawling() && level().getBlockState(blockPosition()).isSolid();
// boolean isFacingAboveSolid = isCrawling() && level.getBlockState(blockPosition().offset(getDirectionVector()).above()).getMaterial().isSolid();
boolean isCurrentTwoAboveSolid = level().getBlockState(blockPosition().above(2)).isSolid();
// boolean isFacingTwoAboveSolid = isCrouching() && level.getBlockState(blockPosition().offset(getDirectionVector()).above(2)).getMaterial().isSolid();;

// TODO :: Climbing animation
if (isCurrentAboveSolid || unsure /*|| isFacingAboveSolid*/) {
// Crawling
return state.setAndContinue(CRAWL);
} else if (level().getBlockState(blockPosition().above(2)).isSolid()) {
} else if (isCurrentTwoAboveSolid /*|| isFacingTwoAboveSolid*/) {
// Crouching
if (state.isMoving()) {
return state.setAndContinue(CROUCH_RUN);
Expand Down Expand Up @@ -529,6 +543,10 @@ public boolean teleportToTarget() {
return true;
}

private Vec3i getDirectionVector() {
return new Vec3i(getDirection().getStepX(), getDirection().getStepY(), getDirection().getStepZ());
}

@Override
protected SoundEvent getHurtSound(@NotNull final DamageSource damageSourceIn) {
return chooseHurtSound();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void tick() {
// Create a new path when the target moves away too far from the initial goal
boolean targetMoved = path != null && (path.getEndNode() != null && path.getEndNode().distanceTo(target.blockPosition()) > 2);

if (path == null || targetMoved || path.isDone() && !shouldClimb(path) || caveDweller.getNavigation().shouldRecomputePath(target.blockPosition()) && caveDweller.tickCount % 20 == 0) {
if (path == null || caveDweller.getNavigation().isStuck() || targetMoved || path.isDone() && !shouldClimb(path) || caveDweller.getNavigation().shouldRecomputePath(target.blockPosition()) && caveDweller.tickCount % 20 == 0) {
path = caveDweller.getNavigation().createPath(target, 0);
fixPath(path);
}
Expand Down

0 comments on commit 754e156

Please sign in to comment.