-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 完成栅栏门的交互 * 应用门的交互(记忆)机制到栅栏门上 * 简化栅栏门的设计 --------- Co-authored-by: tartaric_acid <[email protected]>
- Loading branch information
1 parent
1bb3bb4
commit e3691fa
Showing
5 changed files
with
199 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...java/com/github/tartaricacid/touhoulittlemaid/entity/ai/navigation/MaidNodeEvaluator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.github.tartaricacid.touhoulittlemaid.entity.ai.navigation; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.BlockGetter; | ||
import net.minecraft.world.level.block.FenceGateBlock; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.pathfinder.BlockPathTypes; | ||
import net.minecraft.world.level.pathfinder.WalkNodeEvaluator; | ||
|
||
/** | ||
* 该方法仅修改了栅栏门的寻路判断 | ||
*/ | ||
public class MaidNodeEvaluator extends WalkNodeEvaluator { | ||
@Override | ||
public BlockPathTypes getBlockPathType(BlockGetter level, int pX, int pY, int pZ) { | ||
return getMaidBlockPathTypeStatic(level, new BlockPos.MutableBlockPos(pX, pY, pZ)); | ||
} | ||
|
||
private static BlockPathTypes getMaidBlockPathTypeStatic(BlockGetter level, BlockPos.MutableBlockPos pos) { | ||
int x = pos.getX(); | ||
int y = pos.getY(); | ||
int z = pos.getZ(); | ||
|
||
BlockPathTypes type = getMaidBlockPathTypeRaw(level, pos); | ||
if (type == BlockPathTypes.OPEN && y >= level.getMinBuildHeight() + 1) { | ||
BlockPathTypes typeBelow = getMaidBlockPathTypeRaw(level, pos.set(x, y - 1, z)); | ||
|
||
type = typeBelow != BlockPathTypes.WALKABLE | ||
&& typeBelow != BlockPathTypes.OPEN | ||
&& typeBelow != BlockPathTypes.WATER | ||
&& typeBelow != BlockPathTypes.LAVA ? BlockPathTypes.WALKABLE : BlockPathTypes.OPEN; | ||
|
||
if (typeBelow == BlockPathTypes.DAMAGE_FIRE) { | ||
type = BlockPathTypes.DAMAGE_FIRE; | ||
} | ||
|
||
if (typeBelow == BlockPathTypes.DAMAGE_CACTUS) { | ||
type = BlockPathTypes.DAMAGE_CACTUS; | ||
} | ||
|
||
if (typeBelow == BlockPathTypes.DAMAGE_OTHER) { | ||
type = BlockPathTypes.DAMAGE_OTHER; | ||
} | ||
|
||
if (typeBelow == BlockPathTypes.STICKY_HONEY) { | ||
type = BlockPathTypes.STICKY_HONEY; | ||
} | ||
|
||
if (typeBelow == BlockPathTypes.POWDER_SNOW) { | ||
type = BlockPathTypes.DANGER_POWDER_SNOW; | ||
} | ||
} | ||
|
||
if (type == BlockPathTypes.WALKABLE) { | ||
type = checkNeighbourBlocks(level, pos.set(x, y, z), type); | ||
} | ||
|
||
return type; | ||
} | ||
|
||
private static BlockPathTypes getMaidBlockPathTypeRaw(BlockGetter level, BlockPos pos) { | ||
BlockState blockState = level.getBlockState(pos); | ||
BlockPathTypes pathType = blockState.getBlockPathType(level, pos, null); | ||
if (pathType != null) { | ||
return pathType; | ||
} else if (blockState.isAir()) { | ||
return BlockPathTypes.OPEN; | ||
} else if (blockState.getBlock() instanceof FenceGateBlock) { | ||
return blockState.getValue(FenceGateBlock.OPEN) ? BlockPathTypes.DOOR_OPEN : BlockPathTypes.DOOR_WOOD_CLOSED; | ||
} else { | ||
return WalkNodeEvaluator.getBlockPathTypeRaw(level, pos); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ava/com/github/tartaricacid/touhoulittlemaid/entity/ai/navigation/MaidPathNavigation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.github.tartaricacid.touhoulittlemaid.entity.ai.navigation; | ||
|
||
import net.minecraft.world.entity.Mob; | ||
import net.minecraft.world.entity.ai.navigation.GroundPathNavigation; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.pathfinder.BlockPathTypes; | ||
import net.minecraft.world.level.pathfinder.PathFinder; | ||
|
||
public class MaidPathNavigation extends GroundPathNavigation { | ||
public MaidPathNavigation(Mob mob, Level level) { | ||
super(mob, level); | ||
this.mob.setPathfindingMalus(BlockPathTypes.COCOA, -1.0F); | ||
} | ||
|
||
@Override | ||
protected PathFinder createPathFinder(int range) { | ||
this.nodeEvaluator = new MaidNodeEvaluator(); | ||
this.nodeEvaluator.setCanOpenDoors(true); | ||
this.nodeEvaluator.setCanPassDoors(true); | ||
this.nodeEvaluator.setCanFloat(true); | ||
return new PathFinder(this.nodeEvaluator, range); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...main/java/com/github/tartaricacid/touhoulittlemaid/entity/ai/navigation/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@ParametersAreNonnullByDefault | ||
@MethodsReturnNonnullByDefault | ||
package com.github.tartaricacid.touhoulittlemaid.entity.ai.navigation; | ||
|
||
import net.minecraft.MethodsReturnNonnullByDefault; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters