-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
256 additions
and
78 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
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
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
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
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
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
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
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: 51 additions & 23 deletions
74
.../faboslav/friendsandfoes/entity/ai/brain/task/rascal/RascalFindInteractionTargetTask.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 |
---|---|---|
@@ -1,34 +1,62 @@ | ||
package com.faboslav.friendsandfoes.entity.ai.brain.task.rascal; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.ai.brain.EntityLookTarget; | ||
import net.minecraft.entity.ai.brain.MemoryModuleType; | ||
import net.minecraft.entity.ai.brain.*; | ||
import net.minecraft.entity.ai.brain.task.Task; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.server.world.ServerWorld; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Predicate; | ||
|
||
public final class RascalFindInteractionTargetTask | ||
public class RascalFindInteractionTargetTask extends Task<LivingEntity> | ||
{ | ||
public static Task<LivingEntity> create(int maxDistance) { | ||
int squaredMaxDistance = maxDistance * maxDistance; | ||
return TaskTriggerer.task((context) -> { | ||
return context.group(context.queryMemoryOptional(MemoryModuleType.LOOK_TARGET), context.queryMemoryAbsent(MemoryModuleType.INTERACTION_TARGET), context.queryMemoryValue(MemoryModuleType.VISIBLE_MOBS)).apply(context, (lookTarget, interactionTarget, visibleMobs) -> { | ||
return (world, entity, time) -> { | ||
Optional<LivingEntity> optional = context.getValue(visibleMobs).findFirst((target) -> { | ||
return target.squaredDistanceTo(entity) <= (double) squaredMaxDistance && target instanceof PlayerEntity && !target.isSpectator() && !((PlayerEntity) target).isCreative(); | ||
}); | ||
|
||
if (optional.isEmpty()) { | ||
return false; | ||
} else { | ||
LivingEntity livingEntity = optional.get(); | ||
interactionTarget.remember(livingEntity); | ||
lookTarget.remember(new EntityLookTarget(livingEntity, true)); | ||
return true; | ||
} | ||
}; | ||
private final int maxSquaredDistance; | ||
private final Predicate<LivingEntity> predicate; | ||
private final Predicate<LivingEntity> shouldRunPredicate; | ||
|
||
public RascalFindInteractionTargetTask( | ||
int maxDistance, | ||
Predicate<LivingEntity> shouldRunPredicate, | ||
Predicate<LivingEntity> predicate | ||
) { | ||
super(ImmutableMap.of(MemoryModuleType.LOOK_TARGET, MemoryModuleState.REGISTERED, MemoryModuleType.INTERACTION_TARGET, MemoryModuleState.VALUE_ABSENT, MemoryModuleType.VISIBLE_MOBS, MemoryModuleState.VALUE_PRESENT)); | ||
this.maxSquaredDistance = maxDistance * maxDistance; | ||
this.predicate = predicate; | ||
this.shouldRunPredicate = shouldRunPredicate; | ||
} | ||
|
||
public RascalFindInteractionTargetTask(int maxDistance) { | ||
this(maxDistance, (livingEntity) -> { | ||
return true; | ||
}, (livingEntity) -> { | ||
return true; | ||
}); | ||
} | ||
|
||
public boolean shouldRun(ServerWorld world, LivingEntity entity) { | ||
return this.shouldRunPredicate.test(entity) && this.getVisibleMobs(entity).anyMatch(this::test); | ||
} | ||
|
||
public void run(ServerWorld world, LivingEntity entity, long time) { | ||
super.run(world, entity, time); | ||
Brain<?> brain = entity.getBrain(); | ||
brain.getOptionalMemory(MemoryModuleType.VISIBLE_MOBS).flatMap((livingTargetCache) -> { | ||
return livingTargetCache.findFirst((target) -> { | ||
return target.squaredDistanceTo(entity) <= (double) this.maxSquaredDistance && target instanceof PlayerEntity && !target.isSpectator() && !((PlayerEntity) target).isCreative(); | ||
}); | ||
}).ifPresent((target) -> { | ||
brain.remember(MemoryModuleType.INTERACTION_TARGET, target); | ||
brain.remember(MemoryModuleType.LOOK_TARGET, new EntityLookTarget(target, true)); | ||
}); | ||
} | ||
} | ||
|
||
private boolean test(LivingEntity entity) { | ||
return EntityType.PLAYER.equals(entity.getType()) && this.predicate.test(entity); | ||
} | ||
|
||
private LivingTargetCache getVisibleMobs(LivingEntity entity) { | ||
return entity.getBrain().getOptionalMemory(MemoryModuleType.VISIBLE_MOBS).get(); | ||
} | ||
} |
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
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
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
Binary file added
BIN
+6.56 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/ambient1.ogg
Binary file not shown.
Binary file added
BIN
+6.72 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/ambient2.ogg
Binary file not shown.
Binary file added
BIN
+8.17 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/ambient3.ogg
Binary file not shown.
Binary file added
BIN
+6.84 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/ambient4.ogg
Binary file not shown.
Binary file added
BIN
+5.56 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/ambient5.ogg
Binary file not shown.
Binary file added
BIN
+22.2 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/disappear1.ogg
Binary file not shown.
Binary file added
BIN
+28.3 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/disappear2.ogg
Binary file not shown.
Binary file added
BIN
+4.79 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/hurt1.ogg
Binary file not shown.
Binary file added
BIN
+4.95 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/hurt2.ogg
Binary file not shown.
Binary file added
BIN
+5.68 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/hurt3.ogg
Binary file not shown.
Binary file added
BIN
+6.4 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/hurt4.ogg
Binary file not shown.
Binary file added
BIN
+6.03 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/hurt5.ogg
Binary file not shown.
Binary file added
BIN
+9.5 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/nod1.ogg
Binary file not shown.
Binary file added
BIN
+9.52 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/nod2.ogg
Binary file not shown.
Binary file added
BIN
+9.03 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/nod3.ogg
Binary file not shown.
Binary file added
BIN
+9.97 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/nod4.ogg
Binary file not shown.
Binary file added
BIN
+34.2 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/reappear1.ogg
Binary file not shown.
Binary file added
BIN
+25.9 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/reappear2.ogg
Binary file not shown.
Binary file added
BIN
+4.97 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/reward1.ogg
Binary file not shown.
Binary file added
BIN
+6.19 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/reward2.ogg
Binary file not shown.
Binary file added
BIN
+7.31 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/reward_bad1.ogg
Binary file not shown.
Binary file added
BIN
+7.12 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/reward_bad2.ogg
Binary file not shown.
Binary file added
BIN
+6.14 KB
common/src/main/resources/assets/friendsandfoes/sounds/entity/rascal/reward_bad3.ogg
Binary file not shown.
Binary file added
BIN
+824 Bytes
common/src/main/resources/assets/friendsandfoes/textures/entity/rascal/rascal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.