Created
January 18, 2021 10:14
-
-
Save ZornTaov/f3252e37507dee0ed8f9677fd625627e to your computer and use it in GitHub Desktop.
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
@Mod.EventBusSubscriber(modid = YOURMOD.MOD_ID) | |
public static class ServerEvents { | |
@SubscribeEvent | |
public static void onLivingUpdateEvent(LivingEvent.LivingUpdateEvent event) { | |
LivingEntity le = event.getEntityLiving(); | |
if (le instanceof MobEntity) { // only MobEntity has a Navigator, so this includes most entities | |
PathNavigator navi = ((MobEntity) le).getNavigator(); | |
if (le.world instanceof ServerWorld && le.world.getGameTime() % 10 == 0) { // only generate every 0.5 seconds, to try and cut back on packet spam | |
Path path = navi.getPath(); | |
if (path != null) { | |
for (int i = path.getCurrentPathIndex(); i < path.getCurrentPathLength(); i++) { | |
//get current point | |
BlockPos pos = path.getPathPointFromIndex(i).func_224759_a(); | |
//get next point (or current point) | |
BlockPos nextPos = (i+1) != path.getCurrentPathLength() ? path.getPathPointFromIndex(i+1).func_224759_a() : pos; | |
//get difference for vector | |
BlockPos endPos = nextPos.subtract(pos); | |
//render pathpoints | |
((ServerWorld) le.world).spawnParticle(ParticleTypes.HAPPY_VILLAGER, | |
pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 0, | |
0, 0, 0, 0); | |
//send a particle between points for direction | |
((ServerWorld) le.world).spawnParticle(ParticleTypes.END_ROD, | |
pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 0, | |
endPos.getX(), endPos.getY(), endPos.getZ(), 0.1); | |
} | |
// render end point | |
BlockPos pos = navi.getTargetPos(); | |
((ServerWorld) le.world).spawnParticle(ParticleTypes.HEART, | |
pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 0, | |
0, 0, 0, 0); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment