Search in sources :

Example 1 with WrappedGoal

use of net.minecraft.world.entity.ai.goal.WrappedGoal 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)

Example 2 with WrappedGoal

use of net.minecraft.world.entity.ai.goal.WrappedGoal in project SpongeCommon by SpongePowered.

the class GoalSelectorMixin method onAddEntityTask.

/**
 * @author gabizou - February 1st, 2016
 *
 * Purpose: Rewrites the overwrite to use a redirect when an entry is being added
 * to the task entries. We throw an event for plugins to potentially cancel.
 */
@Redirect(method = "addGoal", at = @At(value = "INVOKE", target = "Ljava/util/Set;add(Ljava/lang/Object;)Z", remap = false))
private boolean onAddEntityTask(final Set<WrappedGoal> goals, final Object task, final int priority, final Goal base) {
    ((GoalBridge) base).bridge$setGoalExecutor((GoalExecutor<?>) this);
    if (!ShouldFire.GOAL_EVENT_ADD || this.owner == null || ((EntityBridge) this.owner).bridge$isConstructing()) {
        // Event is fired in bridge$fireConstructors
        return goals.add(new WrappedGoal(priority, base));
    }
    final GoalEvent.Add event = SpongeEventFactory.createGoalEventAdd(PhaseTracker.getCauseStackManager().currentCause(), priority, priority, (Agent) this.owner, (GoalExecutor<?>) this, (org.spongepowered.api.entity.ai.goal.Goal<?>) base);
    SpongeCommon.post(event);
    if (event.isCancelled()) {
        ((GoalBridge) base).bridge$setGoalExecutor(null);
        return false;
    }
    return goals.add(new WrappedGoal(event.priority(), base));
}
Also used : GoalBridge(org.spongepowered.common.bridge.world.entity.ai.GoalBridge) WrappedGoal(net.minecraft.world.entity.ai.goal.WrappedGoal) GoalEvent(org.spongepowered.api.event.entity.ai.goal.GoalEvent) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 3 with WrappedGoal

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

the class EntityKoaBase method updateUniqueEntityAI.

/*public void initTrades() {

        this.offers = new MerchantOffers();





        MerchantRecipeList list = new MerchantRecipeList();

        //stack count given is the base amount that will be multiplied based on value of currency traded for

        //item worth notes:
        //cooked marlin restores double that of cooked fish
        //1 leather drops, 4+ scales drop per mob

        if (getRole() == Roles.FISHERMAN) {

            addTradeForCurrencies(list, new ItemStack(Items.TROPICAL_FISH, 5));
            addTradeForCurrencies(list, new ItemStack(ItemRegistry.fishingNet, 1));
            addTradeForCurrencies(list, new ItemStack(ItemRegistry.fishingRod, 1));
            addTradeForCurrencies(list, new ItemStack(ItemRegistry.freshMarlin, 3));
            addTradeForCurrencies(list, new ItemStack(ItemRegistry.fertilizer, 5));

            //TODO: 1.14 fix
            for (int i = 0; i < EntityTropicalFish.NAMES.length; i++) {
                addTradeForCurrencies(list, new ItemStack(ItemRegistry.rawTropicalFish, 1, i));
            }
            for (int i = 0; i < ItemRiverFish.FISH_COLORS.length; i++) {
                addTradeForCurrencies(list, new ItemStack(ItemRegistry.rawRiverFish, 1, i));
            }

        } else if (getRole() == Roles.HUNTER) {

            addTradeForCurrencies(list, new ItemStack(ItemRegistry.frogLeg, 5));
            addTradeForCurrencies(list, new ItemStack(ItemRegistry.iguanaLeather, 2));
            addTradeForCurrencies(list, new ItemStack(ItemRegistry.scale, 5));

        }

        try {
            _buyingList.set(this, list);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }*/
/*public void addTradeForCurrencies(MerchantRecipeList list, ItemStack sell) {
        double pearlWhiteWorth = 1;
        double pearlBlackWorth = 1.5D;

        List<Double> listTradeCosts = new ArrayList<>();

        ItemStack stack1 = sell.copy();
        stack1.setCount((int)Math.round(sell.getCount() * pearlWhiteWorth));
        list.add(new MerchantRecipe(new ItemStack(ItemRegistry.whitePearl), stack1));

        ItemStack stack2 = sell.copy();
        stack2.setCount((int)Math.round(sell.getCount() * pearlBlackWorth));
        list.add(new MerchantRecipe(new ItemStack(ItemRegistry.blackPearl), stack2));

    }*/
public void updateUniqueEntityAI() {
    // TODO: 1.14 maybe not needed, since villagers use diff system
    /*Set<GoalSelector.EntityAITaskEntry> executingTaskEntries = ReflectionHelper.getPrivateValue(GoalSelector.class, this.goalSelector, "field_75780_b", "executingTaskEntries");
        if (executingTaskEntries != null) {
            for (GoalSelector.EntityAITaskEntry entry : this.goalSelector.taskEntries) {
                entry.action.resetTask();
            }
            executingTaskEntries.clear();
        }

        Set<GoalSelector.EntityAITaskEntry> executingTaskEntries2 = ReflectionHelper.getPrivateValue(GoalSelector.class, this.targetSelector, "field_75780_b", "executingTaskEntries");
        if (executingTaskEntries2 != null) {
            for (GoalSelector.EntityAITaskEntry entry : this.targetSelector.taskEntries) {
                entry.action.resetTask();
            }
            executingTaskEntries2.clear();
        }*/
    /*this.goalSelector.taskEntries.clear();
        this.targetSelector.taskEntries.clear();*/
    this.goalSelector.getRunningGoals().forEach(WrappedGoal::stop);
    this.targetSelector.getRunningGoals().forEach(WrappedGoal::stop);
    int curPri = 0;
    this.goalSelector.addGoal(curPri++, new FloatGoal(this));
    this.goalSelector.addGoal(curPri++, new EntityAIAvoidEntityOnLowHealth(this, LivingEntity.class, ENEMY_PREDICATE, 12.0F, 1.4D, 1.4D, 15F));
    this.goalSelector.addGoal(curPri++, new EntityAIEatToHeal(this));
    this.goalSelector.addGoal(curPri++, new TradeWithPlayerGoal(this));
    this.goalSelector.addGoal(curPri++, new MeleeAttackGoal(this, 1F, true) {

        @Override
        public void start() {
            super.start();
            if (this.mob instanceof EntityKoaBase) {
                ((EntityKoaBase) this.mob).setFightingItem();
            }
        }

        @Override
        protected double getAttackReachSqr(LivingEntity attackTarget) {
            return this.mob.getType().getDimensions().width * 2.5F * this.mob.getType().getDimensions().width * 2.5F + attackTarget.getType().getDimensions().width;
        }
    });
    this.goalSelector.addGoal(curPri++, new EntityAITemptHelmet(this, 1.0D, false, TEMPTATION_ITEMS));
    this.goalSelector.addGoal(curPri++, new MoveTowardsRestrictionGoal(this, 1D));
    this.goalSelector.addGoal(curPri++, new EntityAIKoaMate(this));
    this.goalSelector.addGoal(curPri++, new EntityAIChillAtFire(this));
    this.goalSelector.addGoal(curPri++, new EntityAIPartyTime(this));
    if (canFish()) {
        this.goalSelector.addGoal(curPri++, new EntityAIGoneFishin(this));
    }
    if (isBaby()) {
        this.goalSelector.addGoal(curPri++, new EntityAIPlayKoa(this, 1.2D));
    }
    this.goalSelector.addGoal(curPri, new LookAtPlayerGoal(this, Player.class, 3.0F, 1.0F));
    this.goalSelector.addGoal(curPri++, new EntityAIWanderNotLazy(this, 1D, 40));
    this.goalSelector.addGoal(curPri++, new LookAtPlayerGoal(this, Mob.class, 8.0F));
    this.targetSelector.addGoal(1, new HurtByTargetGoal(this));
    // i dont think this one works, change to predicate
    if (canHunt()) {
        this.targetSelector.addGoal(2, new NearestAttackableTargetGoal(this, LivingEntity.class, 10, true, false, ENEMY_PREDICATE));
    }
}
Also used : AgeableMob(net.minecraft.world.entity.AgeableMob) Mob(net.minecraft.world.entity.Mob) Player(net.minecraft.world.entity.player.Player) MoveTowardsRestrictionGoal(net.minecraft.world.entity.ai.goal.MoveTowardsRestrictionGoal) EntityAIChillAtFire(net.tropicraft.core.common.entity.ai.EntityAIChillAtFire) EntityAIKoaMate(net.tropicraft.core.common.entity.ai.EntityAIKoaMate) HurtByTargetGoal(net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal) NearestAttackableTargetGoal(net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal) WrappedGoal(net.minecraft.world.entity.ai.goal.WrappedGoal) EntityAIEatToHeal(net.tropicraft.core.common.entity.ai.EntityAIEatToHeal) LivingEntity(net.minecraft.world.entity.LivingEntity) EntityAITemptHelmet(net.tropicraft.core.common.entity.ai.EntityAITemptHelmet) EntityAIGoneFishin(net.tropicraft.core.common.entity.ai.EntityAIGoneFishin) LookAtPlayerGoal(net.minecraft.world.entity.ai.goal.LookAtPlayerGoal) EntityAIAvoidEntityOnLowHealth(net.tropicraft.core.common.entity.ai.EntityAIAvoidEntityOnLowHealth) MeleeAttackGoal(net.minecraft.world.entity.ai.goal.MeleeAttackGoal) EntityAIPartyTime(net.tropicraft.core.common.entity.ai.EntityAIPartyTime) EntityAIPlayKoa(net.tropicraft.core.common.entity.ai.EntityAIPlayKoa) TradeWithPlayerGoal(net.minecraft.world.entity.ai.goal.TradeWithPlayerGoal) EntityAIWanderNotLazy(net.tropicraft.core.common.entity.ai.EntityAIWanderNotLazy) FloatGoal(net.minecraft.world.entity.ai.goal.FloatGoal)

Aggregations

WrappedGoal (net.minecraft.world.entity.ai.goal.WrappedGoal)3 AgeableMob (net.minecraft.world.entity.AgeableMob)2 LivingEntity (net.minecraft.world.entity.LivingEntity)2 Mob (net.minecraft.world.entity.Mob)2 Player (net.minecraft.world.entity.player.Player)2 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