Yatopia/patches/server/0024-Option-for-simpler-Villagers.patch
2020-07-17 18:05:50 +02:00

188 lines
9.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Fri, 19 Jun 2020 19:21:35 +0200
Subject: [PATCH] Option for simpler Villagers
Option to extremly simplefy the villager AI.
diff --git a/src/main/java/de/tr7zw/yapfa/YapfaConfig.java b/src/main/java/de/tr7zw/yapfa/YapfaConfig.java
index a158e9dc8b295f13c7ab73747cecd4c8dccce66f..aea46527b5be9ea4d06d7d68c6b9a8aec0b7e4c9 100644
--- a/src/main/java/de/tr7zw/yapfa/YapfaConfig.java
+++ b/src/main/java/de/tr7zw/yapfa/YapfaConfig.java
@@ -221,4 +221,14 @@ public class YapfaConfig {
itemStuckSleepTicks = getInt("settings.itemStuckSleepTicks", 1);
}
+ public static boolean simplerVillagerBehavior = false;
+ private static void simplerVillagerBehavior() {
+ simplerVillagerBehavior = getBoolean("settings.villager.simplerVillagerBehavior", false);
+ }
+
+ public static boolean villagersHideAtNight = false;
+ private static void villagersHideAtNight() {
+ villagersHideAtNight = getBoolean("settings.villager.villagersHideAtNight", false);
+ }
+
}
\ No newline at end of file
diff --git a/src/main/java/net/minecraft/server/EntityVillager.java b/src/main/java/net/minecraft/server/EntityVillager.java
index bf019043a9338aca8d91da809f1d5520531386e7..5db697b66d813ef63a8aed8d12667c3e710cd2df 100644
--- a/src/main/java/net/minecraft/server/EntityVillager.java
+++ b/src/main/java/net/minecraft/server/EntityVillager.java
@@ -7,6 +7,8 @@ import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.DynamicOps;
+
+import de.tr7zw.yapfa.YapfaConfig;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import java.util.Collection;
import java.util.Iterator;
@@ -30,7 +32,9 @@ import org.bukkit.event.entity.VillagerReplenishTradeEvent;
// CraftBukkit end
public class EntityVillager extends EntityVillagerAbstract implements ReputationHandler, VillagerDataHolder {
-
+
+ //YAPFA
+ private boolean simplerVillagerBehavior = YapfaConfig.simplerVillagerBehavior; //get this during villager creation so a reloaded config doesn't get them into an invalid state
private static final DataWatcherObject<VillagerData> by = DataWatcher.a(EntityVillager.class, DataWatcherRegistry.q);
public static final Map<Item, Integer> bw = ImmutableMap.of(Items.BREAD, 4, Items.POTATO, 1, Items.CARROT, 1, Items.BEETROOT, 1);
private static final Set<Item> bz = ImmutableSet.of(Items.BREAD, Items.POTATO, Items.CARROT, Items.WHEAT, Items.WHEAT_SEEDS, Items.BEETROOT, new Item[]{Items.BEETROOT_SEEDS});
@@ -66,12 +70,49 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
public EntityVillager(EntityTypes<? extends EntityVillager> entitytypes, World world, VillagerType villagertype) {
super(entitytypes, world);
this.bF = new Reputation();
+ if(!simplerVillagerBehavior) {
((Navigation) this.getNavigation()).a(true);
this.getNavigation().d(true);
+ }else {
+ initPathfinder();
+ }
this.setCanPickupLoot(true);
this.setVillagerData(this.getVillagerData().withType(villagertype).withProfession(VillagerProfession.NONE));
}
+ //YAPFA start
+ @Override
+ protected void initPathfinder() {
+ if(!simplerVillagerBehavior)return;
+ this.goalSelector.a(0, new PathfinderGoalFloat(this));
+ if(YapfaConfig.villagersHideAtNight) {
+ this.goalSelector.a(0, new PathfinderGoalUseItem<>(this, PotionUtil.a(new ItemStack(Items.POTION), Potions.INVISIBILITY), SoundEffects.ENTITY_WANDERING_TRADER_DISAPPEARED, (entityvillagertrader) -> {
+ return !this.world.isDay() && !entityvillagertrader.isInvisible();
+ }));
+ this.goalSelector.a(0, new PathfinderGoalUseItem<>(this, new ItemStack(Items.MILK_BUCKET), SoundEffects.ENTITY_WANDERING_TRADER_REAPPEARED, (entityvillagertrader) -> {
+ return this.world.isDay() && entityvillagertrader.isInvisible();
+ }));
+ }
+ this.goalSelector.a(1, new PathfinderGoalTradeWithPlayer(this));
+ this.goalSelector.a(1, new PathfinderGoalAvoidTarget<>(this, EntityZombie.class, 8.0F, 0.5D, 0.5D));
+ this.goalSelector.a(1, new PathfinderGoalAvoidTarget<>(this, EntityEvoker.class, 12.0F, 0.5D, 0.5D));
+ this.goalSelector.a(1, new PathfinderGoalAvoidTarget<>(this, EntityVindicator.class, 8.0F, 0.5D, 0.5D));
+ this.goalSelector.a(1, new PathfinderGoalAvoidTarget<>(this, EntityVex.class, 8.0F, 0.5D, 0.5D));
+ this.goalSelector.a(1, new PathfinderGoalAvoidTarget<>(this, EntityPillager.class, 15.0F, 0.5D, 0.5D));
+ this.goalSelector.a(1, new PathfinderGoalAvoidTarget<>(this, EntityIllagerIllusioner.class, 12.0F, 0.5D, 0.5D));
+ this.goalSelector.a(1, new PathfinderGoalPanic(this, 0.5D));
+ this.goalSelector.a(1, new PathfinderGoalLookAtTradingPlayer(this));
+ this.goalSelector.a(2, new PathfinderGoalStrollVillageGolem(this, 0.6D));
+ this.goalSelector.a(3, new PathfinderGoalMoveThroughVillage(this, 0.6D, false, 4, () -> {
+ return false;
+ }));
+ this.goalSelector.a(4, new PathfinderGoalMoveTowardsRestriction(this, 0.35D));
+ this.goalSelector.a(8, new PathfinderGoalRandomStrollLand(this, 0.35D));
+ this.goalSelector.a(9, new PathfinderGoalInteract(this, EntityHuman.class, 3.0F, 1.0F));
+ this.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this, EntityInsentient.class, 8.0F));
+ }
+ //YAPFA end
+
@Override
public BehaviorController<EntityVillager> getBehaviorController() {
return (BehaviorController<EntityVillager>) super.getBehaviorController(); // CraftBukkit - decompile error
@@ -84,6 +125,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
@Override
protected BehaviorController<?> a(Dynamic<?> dynamic) {
+ if(simplerVillagerBehavior)return super.a(dynamic); //YAPFA Don't use behaviorcontroller for simple Villagers
BehaviorController<EntityVillager> behaviorcontroller = this.cJ().a(dynamic);
this.a(behaviorcontroller);
@@ -162,10 +204,43 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
}
// Spigot End
+ // YAPFA start
+ private VillagerProfession getRandomProfession() {
+ int type = random.nextInt(13);
+ switch(type) {
+ case 0: return VillagerProfession.ARMORER;
+ case 1: return VillagerProfession.BUTCHER;
+ case 2: return VillagerProfession.CARTOGRAPHER;
+ case 3: return VillagerProfession.CLERIC;
+ case 4: return VillagerProfession.FARMER;
+ case 5: return VillagerProfession.FISHERMAN;
+ case 6: return VillagerProfession.FLETCHER;
+ case 7: return VillagerProfession.LEATHERWORKER;
+ case 8: return VillagerProfession.LIBRARIAN;
+ case 9: return VillagerProfession.MASON;
+ case 10: return VillagerProfession.SHEPHERD;
+ case 11: return VillagerProfession.TOOLSMITH;
+ case 12: return VillagerProfession.WEAPONSMITH;
+ default: return VillagerProfession.FARMER;
+ }
+ }
+
+ // YAPFA end
+
@Override
protected void mobTick() { mobTick(false); }
protected void mobTick(boolean inactive) {
+ // YAPFA start
+ if(simplerVillagerBehavior && this.getVillagerData().getProfession() == VillagerProfession.NONE)
+ this.setVillagerData(this.getVillagerData().withProfession(getRandomProfession()));
+ if(simplerVillagerBehavior) {
+ if (canRefresh()) {
+ restUses();
+ }
+ }
+ // YAPFA end
this.world.getMethodProfiler().enter("villagerBrain");
+ if(!simplerVillagerBehavior) // YAPFA
if (!inactive) this.getBehaviorController().a((WorldServer) this.world, this); // CraftBukkit - decompile error // Paper
if (this.bM) {
this.bM = false;
@@ -296,6 +371,8 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
return true;
}
+ public void restUses() {fb();} // YAPFA obf helper
+
public void fb() {
this.fp();
Iterator iterator = this.getOffers().iterator();
@@ -330,6 +407,8 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
return this.bK == 0 || this.bK < 2 && this.world.getTime() > this.bJ + 2400L;
}
+ public boolean canRefresh() {return fc();} // YAPFA obf helper
+
public boolean fc() {
long i = this.bJ + 12000L;
long j = this.world.getTime();
@@ -577,6 +656,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
}
private void a(Entity entity) {
+ if(simplerVillagerBehavior)return; // YAPFA
if (this.world instanceof WorldServer) {
Optional<List<EntityLiving>> optional = this.bn.getMemory(MemoryModuleType.VISIBLE_MOBS);
@@ -593,6 +673,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
}
public void a(MemoryModuleType<GlobalPos> memorymoduletype) {
+ if(simplerVillagerBehavior)return; // YAPFA
if (this.world instanceof WorldServer) {
MinecraftServer minecraftserver = ((WorldServer) this.world).getMinecraftServer();