2020-07-17 18:05:50 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2020-06-27 20:02:39 +02:00
From: tr7zw <tr7zw@live.de>
2020-08-03 18:48:42 +02:00
Date: Fri, 31 Jul 2020 21:58:24 -0500
2020-06-27 20:02:39 +02:00
Subject: [PATCH] Option for simpler Villagers
diff --git a/src/main/java/net/minecraft/server/EntityVillager.java b/src/main/java/net/minecraft/server/EntityVillager.java
2021-01-21 11:58:52 +01:00
index eef51f8e5734b897164ca9514e7b49b2678416e6..2745cd0d98cfcf25a5304fa8ae0903028a283b25 100644
2020-06-27 20:02:39 +02:00
--- a/src/main/java/net/minecraft/server/EntityVillager.java
+++ b/src/main/java/net/minecraft/server/EntityVillager.java
2020-10-08 13:04:22 +02:00
@@ -31,6 +31,7 @@ import org.bukkit.event.entity.VillagerReplenishTradeEvent;
2020-06-27 20:02:39 +02:00
public class EntityVillager extends EntityVillagerAbstract implements ReputationHandler, VillagerDataHolder {
2020-08-03 18:48:42 +02:00
2020-12-02 07:35:11 +01:00
+ private boolean simplerVillagerBehavior = org.yatopiamc.yatopia.server.YatopiaConfig.simplerVillagerBehavior; // Yatopia - so we don't make them bork upon reload
2020-08-13 17:53:32 +02:00
private static final DataWatcherObject<VillagerData> br = DataWatcher.a(EntityVillager.class, DataWatcherRegistry.q);
public static final Map<Item, Integer> bp = ImmutableMap.of(Items.BREAD, 4, Items.POTATO, 1, Items.CARROT, 1, Items.BEETROOT, 1);
private static final Set<Item> bs = ImmutableSet.of(Items.BREAD, Items.POTATO, Items.CARROT, Items.WHEAT, Items.WHEAT_SEEDS, Items.BEETROOT, new Item[]{Items.BEETROOT_SEEDS});
2021-01-21 11:58:52 +01:00
@@ -67,8 +68,14 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
2020-08-15 20:20:57 +02:00
public EntityVillager(EntityTypes<? extends EntityVillager> entitytypes, World world, VillagerType villagertype) {
2020-06-27 20:02:39 +02:00
super(entitytypes, world);
2020-08-13 17:53:32 +02:00
this.by = new Reputation();
2020-08-15 20:20:57 +02:00
+ if (!simplerVillagerBehavior) {
2020-06-27 20:02:39 +02:00
((Navigation) this.getNavigation()).a(true);
this.getNavigation().d(true);
2020-08-15 20:20:57 +02:00
+ // Yatopia start
+ } else {
2020-08-03 18:48:42 +02:00
+ initPathfinder();
2020-06-27 20:02:39 +02:00
+ }
2020-08-13 17:53:32 +02:00
+ // Yatopia end
2020-08-15 20:20:57 +02:00
this.setCanPickupLoot(true);
2020-06-27 20:02:39 +02:00
this.setVillagerData(this.getVillagerData().withType(villagertype).withProfession(VillagerProfession.NONE));
2020-08-03 18:48:42 +02:00
this.brainTickOffset = getRandom().nextInt(100); // Purpur
2021-01-21 11:58:52 +01:00
@@ -89,6 +96,38 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
protected void initPathfinder() {
this.goalSelector.a(0, new PathfinderGoalHasRider(this)); // Purpur
if (world.purpurConfig.villagerFollowEmeraldBlock) this.goalSelector.a(3, new PathfinderGoalTempt(this, 1.0D, false, TEMPT_ITEMS));
+ // Yatopia Start
2020-08-13 17:53:32 +02:00
+ if (!simplerVillagerBehavior) {
+ // safety
+ return;
+ }
2020-06-27 20:02:39 +02:00
+ this.goalSelector.a(0, new PathfinderGoalFloat(this));
2020-12-02 07:35:11 +01:00
+ if (org.yatopiamc.yatopia.server.YatopiaConfig.villagersHideAtNight) {
2020-06-27 20:02:39 +02:00
+ 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));
2021-01-21 11:58:52 +01:00
+ // Yatopia End
}
2020-06-27 20:02:39 +02:00
@Override
2021-01-21 11:58:52 +01:00
@@ -114,6 +153,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
2020-06-27 20:02:39 +02:00
@Override
protected BehaviorController<?> a(Dynamic<?> dynamic) {
2020-08-13 17:53:32 +02:00
+ if (simplerVillagerBehavior) return super.a(dynamic); // Yatopia
2020-11-07 08:02:33 +01:00
BehaviorController<EntityVillager> behaviorcontroller = this.cK().a(dynamic);
2020-06-27 20:02:39 +02:00
this.a(behaviorcontroller);
2021-01-21 11:58:52 +01:00
@@ -212,10 +252,39 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
2020-06-27 20:02:39 +02:00
}
2021-01-21 11:58:52 +01:00
// Purpur end
2020-08-15 20:20:57 +02:00
2020-08-03 18:48:42 +02:00
+ // Yatopia start
2020-06-27 20:02:39 +02:00
+ private VillagerProfession getRandomProfession() {
2020-08-03 18:48:42 +02:00
+ 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;
+ }
2020-06-27 20:02:39 +02:00
+ }
2020-08-11 20:40:29 +02:00
+ // Yatopia end
2020-08-15 20:20:57 +02:00
+
2020-06-27 20:02:39 +02:00
@Override
protected void mobTick() { mobTick(false); }
2020-08-15 20:20:57 +02:00
protected void mobTick(boolean inactive) {
2020-11-26 10:52:33 +01:00
this.world.getMethodProfiler().enter("villagerBrain");
2020-08-03 18:48:42 +02:00
+ // Yatopia start
2020-08-11 20:40:29 +02:00
+ if (simplerVillagerBehavior && this.getVillagerData().getProfession() == VillagerProfession.NONE) {
2020-08-03 18:48:42 +02:00
+ this.setVillagerData(this.getVillagerData().withProfession(getRandomProfession()));
2020-08-11 20:40:29 +02:00
+ }
2020-08-13 17:53:32 +02:00
+ if (simplerVillagerBehavior && canRefresh()) restUses();
+ if (simplerVillagerBehavior) return;
2020-08-03 18:48:42 +02:00
+ // Yatopia end
2020-08-27 08:18:33 +02:00
// Purpur start
2021-01-21 11:58:52 +01:00
if (world.purpurConfig.villagerLobotomizeEnabled) inactive = inactive || isLobotomized();
2020-08-27 08:18:33 +02:00
boolean tick = (world.getTime() + brainTickOffset) % world.purpurConfig.villagerBrainTicks == 0;
2021-01-21 11:58:52 +01:00
@@ -338,6 +407,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
this.fl();
2020-06-27 20:02:39 +02:00
}
2020-08-13 17:53:32 +02:00
+ public final boolean canRefresh() { return fc(); } // Yatopia - OBFHELPER
2021-01-21 11:58:52 +01:00
private void fl() {
Iterator iterator = this.getOffers().iterator();
@@ -412,6 +482,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
2020-08-13 17:53:32 +02:00
return this.fn() && this.fm();
}
+ public final void restUses() { fo(); } // Yatopia - OBFHELPER
private void fo() {
int i = 2 - this.bD;
2021-01-21 11:58:52 +01:00
@@ -644,6 +715,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
2020-06-27 20:02:39 +02:00
}
private void a(Entity entity) {
2020-08-13 17:53:32 +02:00
+ if (simplerVillagerBehavior) return; // Yatopia
2020-06-27 20:02:39 +02:00
if (this.world instanceof WorldServer) {
2020-08-13 17:53:32 +02:00
Optional<List<EntityLiving>> optional = this.bg.getMemory(MemoryModuleType.VISIBLE_MOBS);
2020-06-27 20:02:39 +02:00
2021-01-21 11:58:52 +01:00
@@ -660,6 +732,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
2020-06-27 20:02:39 +02:00
}
public void a(MemoryModuleType<GlobalPos> memorymoduletype) {
2020-08-15 20:20:57 +02:00
+ if (simplerVillagerBehavior) return;
2020-06-27 20:02:39 +02:00
if (this.world instanceof WorldServer) {
MinecraftServer minecraftserver = ((WorldServer) this.world).getMinecraftServer();
2020-12-02 07:35:11 +01:00
diff --git a/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java b/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
index a790e1e5161d956ccc1023b0d4bcac647627150a..0f3803757a81c7ecaad48637ede8a3dc95b93f13 100644
--- a/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
+++ b/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
@@ -199,4 +199,11 @@ public class YatopiaConfig {
2020-09-01 08:38:17 +02:00
private static void itemStuckSleepTicks() {
itemStuckSleepTicks = getInt("settings.itemStuckSleepTicks", 1);
}
+
+ public static boolean simplerVillagerBehavior = false;
+ public static boolean villagersHideAtNight = false;
+ private static void villagerSettings() {
+ simplerVillagerBehavior = getBoolean("settings.villager.simplerVillagerBehavior", false);
+ villagersHideAtNight = getBoolean("settings.villager.villagersHideAtNight", false);
+ }
}