Skip to content

Commit

Permalink
close #4259
Browse files Browse the repository at this point in the history
  • Loading branch information
yrsegal committed Oct 2, 2023
1 parent bc227f5 commit 8ea6ebf
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/main/java/vazkii/quark/mixin/TemptGoalMixin.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package vazkii.quark.mixin;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.ai.goal.TemptGoal;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.ai.goal.TemptGoal;
import net.minecraft.world.entity.player.Player;
import vazkii.quark.content.automation.module.FeedingTroughModule;

@Mixin(TemptGoal.class)
Expand All @@ -23,9 +24,23 @@ public class TemptGoalMixin {
@Final
public PathfinderMob mob;

@Unique
private long nextScheduledStart;

private static final int RATE = 20;

@Inject(method = "canUse", at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/ai/goal/TemptGoal;player:Lnet/minecraft/world/entity/player/Player;", ordinal = 0, shift = At.Shift.AFTER))
private void findTroughs(CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
if (mob.level instanceof ServerLevel level)
player = FeedingTroughModule.temptWithTroughs((TemptGoal) (Object) this, player, level);
if (mob.level instanceof ServerLevel level) {
if (nextScheduledStart == 0L) {
nextScheduledStart = level.getGameTime() + level.random.nextInt(RATE);
} else if (level.getGameTime() >= nextScheduledStart)
player = FeedingTroughModule.temptWithTroughs((TemptGoal) (Object) this, player, level);
}
}

@Inject(method = "start", at = @At(value = "HEAD"))
private void updateSchedule(CallbackInfo ci) {
nextScheduledStart = mob.level.getGameTime() + mob.level.random.nextInt(RATE);
}
}

0 comments on commit 8ea6ebf

Please sign in to comment.