Search in sources :

Example 1 with GoalSelector

use of net.minecraft.world.entity.ai.goal.GoalSelector in project Tropicraft by Tropicraft.

the class SeaTurtleEntity method registerGoals.

@Override
protected void registerGoals() {
    super.registerGoals();
    // goalSelector
    GoalSelector goalSelector = ObfuscationReflectionHelper.getPrivateValue(Mob.class, this, "goalSelector");
    // goals
    Set<WrappedGoal> goalSet = ObfuscationReflectionHelper.getPrivateValue(GoalSelector.class, goalSelector, "availableGoals");
    final Optional<WrappedGoal> eggGoal = goalSet.stream().filter(p -> p.getGoal().toString().contains("Egg")).findFirst();
    if (eggGoal.isPresent()) {
        goalSelector.removeGoal(eggGoal.get().getGoal());
        goalSelector.addGoal(1, new BetterLayEggGoal(this, 1.0));
    }
    final Optional<WrappedGoal> mateGoal = goalSet.stream().filter(p -> p.getGoal().toString().contains("Mate")).findFirst();
    if (mateGoal.isPresent()) {
        goalSelector.removeGoal(mateGoal.get().getGoal());
        goalSelector.addGoal(1, new BetterMateGoal(this, 1.0));
    }
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) MoveToBlockGoal(net.minecraft.world.entity.ai.goal.MoveToBlockGoal) ParticleOptions(net.minecraft.core.particles.ParticleOptions) EntityDataSerializers(net.minecraft.network.syncher.EntityDataSerializers) ForgeMod(net.minecraftforge.common.ForgeMod) Random(java.util.Random) MobType(net.minecraft.world.entity.MobType) SeaTurtleEggEntity(net.tropicraft.core.common.entity.egg.SeaTurtleEggEntity) ObfuscationReflectionHelper(net.minecraftforge.fml.util.ObfuscationReflectionHelper) CriteriaTriggers(net.minecraft.advancements.CriteriaTriggers) TropicraftItems(net.tropicraft.core.common.item.TropicraftItems) BreedGoal(net.minecraft.world.entity.ai.goal.BreedGoal) LevelEvent(net.minecraft.world.level.block.LevelEvent) Set(java.util.Set) GameRules(net.minecraft.world.level.GameRules) EntityDataAccessor(net.minecraft.network.syncher.EntityDataAccessor) InteractionResult(net.minecraft.world.InteractionResult) ExperienceOrb(net.minecraft.world.entity.ExperienceOrb) LevelReader(net.minecraft.world.level.LevelReader) Blocks(net.minecraft.world.level.block.Blocks) Player(net.minecraft.world.entity.player.Player) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) WrappedGoal(net.minecraft.world.entity.ai.goal.WrappedGoal) Optional(java.util.Optional) LevelAccessor(net.minecraft.world.level.LevelAccessor) ItemStack(net.minecraft.world.item.ItemStack) MoverType(net.minecraft.world.entity.MoverType) Level(net.minecraft.world.level.Level) SpawnGroupData(net.minecraft.world.entity.SpawnGroupData) SoundSource(net.minecraft.sounds.SoundSource) GoalSelector(net.minecraft.world.entity.ai.goal.GoalSelector) EntityType(net.minecraft.world.entity.EntityType) MobSpawnType(net.minecraft.world.entity.MobSpawnType) AgeableMob(net.minecraft.world.entity.AgeableMob) TropicraftDimension(net.tropicraft.core.common.dimension.TropicraftDimension) ServerLevel(net.minecraft.server.level.ServerLevel) ServerLevelAccessor(net.minecraft.world.level.ServerLevelAccessor) ServerPlayer(net.minecraft.server.level.ServerPlayer) net.minecraft.world(net.minecraft.world) Turtle(net.minecraft.world.entity.animal.Turtle) Stats(net.minecraft.stats.Stats) SoundEvents(net.minecraft.sounds.SoundEvents) Nullable(javax.annotation.Nullable) Material(net.minecraft.world.level.material.Material) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) HitResult(net.minecraft.world.phys.HitResult) Entity(net.minecraft.world.entity.Entity) Vec3(net.minecraft.world.phys.Vec3) Attributes(net.minecraft.world.entity.ai.attributes.Attributes) Block(net.minecraft.world.level.block.Block) InteractionHand(net.minecraft.world.InteractionHand) Mob(net.minecraft.world.entity.Mob) ParticleTypes(net.minecraft.core.particles.ParticleTypes) Mth(net.minecraft.util.Mth) GoalSelector(net.minecraft.world.entity.ai.goal.GoalSelector) WrappedGoal(net.minecraft.world.entity.ai.goal.WrappedGoal)

Aggregations

List (java.util.List)1 Optional (java.util.Optional)1 Random (java.util.Random)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1 CriteriaTriggers (net.minecraft.advancements.CriteriaTriggers)1 BlockPos (net.minecraft.core.BlockPos)1 ParticleOptions (net.minecraft.core.particles.ParticleOptions)1 ParticleTypes (net.minecraft.core.particles.ParticleTypes)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 EntityDataAccessor (net.minecraft.network.syncher.EntityDataAccessor)1 EntityDataSerializers (net.minecraft.network.syncher.EntityDataSerializers)1 SynchedEntityData (net.minecraft.network.syncher.SynchedEntityData)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 SoundEvents (net.minecraft.sounds.SoundEvents)1 SoundSource (net.minecraft.sounds.SoundSource)1 Stats (net.minecraft.stats.Stats)1 Mth (net.minecraft.util.Mth)1 net.minecraft.world (net.minecraft.world)1