Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/zeta120' into zeta120
Browse files Browse the repository at this point in the history
  • Loading branch information
Siuolplex committed Dec 30, 2023
2 parents 3dc9c70 + f99bc24 commit 4473217
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 45 deletions.
9 changes: 8 additions & 1 deletion contributors.properties
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,6 @@ jeniuslu=2
Bobisnotap=1
Rosenator=2
MrBons4i=2
VolrathStormborn=2
Lorykeee=2
TheMelon27=2
YYMB=2
Expand All @@ -908,3 +907,11 @@ DarrSkunk=2
Erratix3107=1
MythicHH=2
Infernal187=2
Fuxedo_Tox=2
tangolikeelk=1
alex2005a=2
billbertking1=2
badsbee=2
Guildes_=3
peapen_teh_elf=2
julienmsorel=2
3 changes: 2 additions & 1 deletion src/main/java/org/violetmoon/quark/QuarkRemapHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class QuarkRemapHandler {
private static final Map<String, String> REMAP = new HashMap<>();

static {
REMAP.put("quark:crafter", "minecraft:crafter");
//fixme crafter
//REMAP.put("quark:crafter", "minecraft:crafter");
REMAP.put("quark:polished_tuff", "minecraft:polished_tuff");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
import net.minecraft.world.ContainerHelper;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.DispenserMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
Expand Down Expand Up @@ -63,14 +65,22 @@ public void updateFoodHolder(Animal mob, Ingredient temptations, FakePlayer food
Vec3 newPos = Vec3.ZERO;
// Fake player will always be at most maxDist blocks away from animal.
// If animal is closer to target, then we will be on target itself.
float maxDist = 3;
float maxDist = 5;
if(direction.lengthSqr() > (maxDist*maxDist)){
newPos = mobPosition.add(direction.normalize().scale(-maxDist));
}else{
//place slightly behind trough
newPos = througPos.add(direction.normalize().scale(-1));
}

// debug to visualize where fake player is
/*
ItemEntity e = new ItemEntity(level, newPos.x, newPos.y+2, newPos.z, Items.EMERALD.getDefaultInstance(), 0,0,0);
e.setNoGravity(true);
e.noPhysics =true;
level.addFreshEntity(e);
*/

foodHolder.moveTo(newPos.x, newPos.y, newPos.z, angles.x, angles.y);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class FeedingTroughModule extends ZetaModule {
public static double range = 10;

@Config(description = "Chance that an animal decides to look for a through. Closer it is to 1 the more performance it will take. Decreasing will make animals take longer to find one")
public static double lookChance = 0.005;
public static double lookChance = 0.01;

private static final WeakHashMap<Animal, TroughPointer> NEARBY_TROUGH_CACHE = new WeakHashMap<>();

Expand All @@ -103,29 +103,25 @@ public void onOrbSpawn(ZEntityJoinLevel event) {
// The "realPlayer" parameter represents a real player located by existing TemptingSensor/TemptGoal code.
// If there is a real player, and they are holding food, we don't swap them for a fakeplayer, so that animals path to
// real players before they consider pathing to the Trough.
// We now only call these if a valid realPlayer is not there, hence why we don't need that parameter anymore

public static @Nullable Player modifyTemptingSensor(@Nullable Player realPlayer, TemptingSensor sensor, Animal animal, ServerLevel level) {
return modifyTempt(realPlayer, level, animal, ((AccessorTemptingSensor) sensor).quark$getTemptations());
public static @Nullable Player modifyTemptingSensor(TemptingSensor sensor, Animal animal, ServerLevel level) {
return modifyTempt(level, animal, ((AccessorTemptingSensor) sensor).quark$getTemptations());
}

public static @Nullable Player modifyTemptGoal(@Nullable Player realPlayer, TemptGoal goal, Animal animal, ServerLevel level) {
return modifyTempt(realPlayer, level, animal, goal.items);
public static @Nullable Player modifyTemptGoal(TemptGoal goal, Animal animal, ServerLevel level) {
return modifyTempt(level, animal, goal.items);
}

private static @Nullable Player modifyTempt(@Nullable Player realPlayer, ServerLevel level, Animal animal, Ingredient temptations) {
private static @Nullable Player modifyTempt(ServerLevel level, Animal animal, Ingredient temptations) {
//early-exit conditions
if (!Quark.ZETA.modules.isEnabled(FeedingTroughModule.class) ||
!animal.canFallInLove() ||
animal.getAge() != 0
) {
return realPlayer;
return null;
}

//deference to real players
//TODO: this logic should not be here, should just be in vanilla code instead
if (realPlayer != null && (temptations.test(realPlayer.getMainHandItem()) || temptations.test(realPlayer.getOffhandItem())))
return realPlayer;

//do we already know about a nearby trough?
NEARBY_TROUGH_CACHE.entrySet().removeIf(p -> !p.getValue().valid(p.getKey()));

Expand Down Expand Up @@ -156,10 +152,12 @@ public void onOrbSpawn(ZEntityJoinLevel event) {
} else {
int error = 0;
}
}else{
int aa = 1;
}
}

return realPlayer;
return null;
}


Expand Down Expand Up @@ -199,15 +197,19 @@ boolean valid(Animal animal) {
return false;
}
if (eatCooldown != 0) return true;
if (foodHolder.isRemoved() || foodHolder.level() != animal.level() || pos.distSqr(animal.blockPosition()) > range * range) {
return false;
if (animal.isRemoved() || !animal.isAlive() || foodHolder.level() != animal.level() || pos.distSqr(animal.blockPosition()) > range * range) {
return false;
}
//check if it has food and tile is valid
if(animal.level().getBlockEntity(pos) instanceof FeedingTroughBlockEntity trough && !foodHolder.getMainHandItem().isEmpty()){
if(animal.level().getBlockEntity(pos) instanceof FeedingTroughBlockEntity trough){
//this should be called in tick but we save one tile call by doing this...
trough.updateFoodHolder(animal, temptations, foodHolder);
//if it still has food
return !foodHolder.getMainHandItem().isEmpty();
var v = !foodHolder.getMainHandItem().isEmpty();
if(!v){
int aa = 1;
}
return v;
}
return false;
}
Expand All @@ -216,7 +218,7 @@ void tryEatingOrTickCooldown(Animal animal) {
giveUpCooldown--;
if (eatCooldown == 0) {
//I wish this could be made smaller. Vanilla AI will not keep animals too close to player holding food
float feedDistance = 1.25f;
float feedDistance = 1.5f;
if (pos.distToCenterSqr(animal.position()) < (feedDistance * feedDistance)) {
if (animal.level().getBlockEntity(pos) instanceof FeedingTroughBlockEntity trough) {
switch (trough.tryFeedingAnimal(animal)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,12 @@ 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 && mob instanceof Animal animal) {
if(nextScheduledStart == 0L) {
nextScheduledStart = level.getGameTime() + level.random.nextInt(RATE);
} else if(level.getGameTime() >= nextScheduledStart)
player = FeedingTroughModule.modifyTemptGoal(player, (TemptGoal) (Object) this, animal, level);
if (player == null && mob.level() instanceof ServerLevel level && mob instanceof Animal animal) {
// here valid players with food have already been selected
player = FeedingTroughModule.modifyTemptGoal((TemptGoal) (Object) this, animal, level);
}
}

@Inject(method = "start", at = @At(value = "HEAD"))
private void updateSchedule(CallbackInfo ci) {
nextScheduledStart = mob.level().getGameTime() + mob.level().random.nextInt(RATE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
@Mixin(TemptingSensor.class)
public class TemptingSensorMixin {

@Unique private static final int RATE = 20; //TODO: I think this needs to be applied every tick

@ModifyExpressionValue(
method = "doTick(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/PathfinderMob;)V",
at = @At(value = "INVOKE", target = "Ljava/util/stream/Stream;collect(Ljava/util/stream/Collector;)Ljava/lang/Object;")
Expand All @@ -29,16 +27,14 @@ public class TemptingSensorMixin {

if(mob instanceof Animal animal) {
Player first = players.isEmpty() ? null : players.get(0);
Player replacement = FeedingTroughModule.modifyTemptingSensor(first, (TemptingSensor) (Object) this, animal, level);
// If first is there, it's already a valid temptation. We do not attempt to modify
if(first == null) {
Player replacement = FeedingTroughModule.modifyTemptingSensor((TemptingSensor) (Object) this, animal, level);

//Collectors.toList returns a mutable list, so it's okay to modify it. This is technically a Java implementation detail.
if(first != replacement)
if(players.isEmpty())
players.add(replacement);
else
players.set(0, replacement);
//Collectors.toList returns a mutable list, so it's okay to modify it. This is technically a Java implementation detail.
if (replacement != null) players.add(replacement);
}
}

return players;
}
}

0 comments on commit 4473217

Please sign in to comment.