From 1a87363c8ed52d6e46ecbfdeac763a24fe6335d9 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Fri, 29 Dec 2023 15:40:00 -0500 Subject: [PATCH 1/3] remove dupe entry & update to match main branch --- contributors.properties | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/contributors.properties b/contributors.properties index 081c8f1b83..6d26b06331 100644 --- a/contributors.properties +++ b/contributors.properties @@ -881,7 +881,6 @@ jeniuslu=2 Bobisnotap=1 Rosenator=2 MrBons4i=2 -VolrathStormborn=2 Lorykeee=2 TheMelon27=2 YYMB=2 @@ -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 From 52194253fae3e5f321061ee32acf9ae6ad995310 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Fri, 29 Dec 2023 17:58:54 -0500 Subject: [PATCH 2/3] fix remap handler --- src/main/java/org/violetmoon/quark/QuarkRemapHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/violetmoon/quark/QuarkRemapHandler.java b/src/main/java/org/violetmoon/quark/QuarkRemapHandler.java index b937b40456..ed1079eeea 100644 --- a/src/main/java/org/violetmoon/quark/QuarkRemapHandler.java +++ b/src/main/java/org/violetmoon/quark/QuarkRemapHandler.java @@ -18,7 +18,8 @@ public class QuarkRemapHandler { private static final Map 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"); } From f8330c3483e02b9c28febf9f0ba48b43f29361c3 Mon Sep 17 00:00:00 2001 From: MehVahdJukaar Date: Sat, 30 Dec 2023 15:40:49 +0200 Subject: [PATCH 3/3] fixed feeding trough --- .../block/be/FeedingTroughBlockEntity.java | 12 +++++- .../module/FeedingTroughModule.java | 38 ++++++++++--------- .../quark/mixin/mixins/TemptGoalMixin.java | 17 ++------- .../mixin/mixins/TemptingSensorMixin.java | 16 +++----- 4 files changed, 40 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/violetmoon/quark/content/automation/block/be/FeedingTroughBlockEntity.java b/src/main/java/org/violetmoon/quark/content/automation/block/be/FeedingTroughBlockEntity.java index 8a32089421..614c72b5ec 100644 --- a/src/main/java/org/violetmoon/quark/content/automation/block/be/FeedingTroughBlockEntity.java +++ b/src/main/java/org/violetmoon/quark/content/automation/block/be/FeedingTroughBlockEntity.java @@ -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; @@ -63,7 +65,7 @@ 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{ @@ -71,6 +73,14 @@ public void updateFoodHolder(Animal mob, Ingredient temptations, FakePlayer food 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; } diff --git a/src/main/java/org/violetmoon/quark/content/automation/module/FeedingTroughModule.java b/src/main/java/org/violetmoon/quark/content/automation/module/FeedingTroughModule.java index 49f2fbcb2a..8eacfd6876 100644 --- a/src/main/java/org/violetmoon/quark/content/automation/module/FeedingTroughModule.java +++ b/src/main/java/org/violetmoon/quark/content/automation/module/FeedingTroughModule.java @@ -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 NEARBY_TROUGH_CACHE = new WeakHashMap<>(); @@ -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())); @@ -156,10 +152,12 @@ public void onOrbSpawn(ZEntityJoinLevel event) { } else { int error = 0; } + }else{ + int aa = 1; } } - return realPlayer; + return null; } @@ -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; } @@ -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)) { diff --git a/src/main/java/org/violetmoon/quark/mixin/mixins/TemptGoalMixin.java b/src/main/java/org/violetmoon/quark/mixin/mixins/TemptGoalMixin.java index 6b2f28ad00..55fdcd9bae 100644 --- a/src/main/java/org/violetmoon/quark/mixin/mixins/TemptGoalMixin.java +++ b/src/main/java/org/violetmoon/quark/mixin/mixins/TemptGoalMixin.java @@ -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 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); - } } diff --git a/src/main/java/org/violetmoon/quark/mixin/mixins/TemptingSensorMixin.java b/src/main/java/org/violetmoon/quark/mixin/mixins/TemptingSensorMixin.java index 98c773764d..853b5b8f78 100644 --- a/src/main/java/org/violetmoon/quark/mixin/mixins/TemptingSensorMixin.java +++ b/src/main/java/org/violetmoon/quark/mixin/mixins/TemptingSensorMixin.java @@ -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;") @@ -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; } }