Yatopia/patches/server/0017-Option-for-simpler-Villagers.patch
Simon Gardling 36030ef022
Updated Upstream and Sidestream(s) (Paper/Tuinity/Purpur/Airplane/Empirecraft) (#392)
* Updated Upstream and Sidestream(s) (Paper/Tuinity/Purpur/Airplane/Empirecraft)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
13a476e15 Deprecate PlayerLeaveBedEvent#setBedSpawn
3a1d95c71 [Auto] Updated Upstream (CraftBukkit)
d4dcc1a2e Updated Upstream (CraftBukkit)
e886d8118 Updated Upstream ()
8bc0c6c31 Updated Upstream (CraftBukkit/Spigot) (#5169)
002f65b8b living entity allow attribute registration (#4723)
69a5c67b1 fix calling setSize on dead slimes causing invincibility (fixes #5137) (#5168)

Tuinity Changes:
502d57b Updated Upstream (Paper)
87e0cd9 Print exceptions for light scheduling

Purpur Changes:
7fc2d31 Updated Upstream (Paper & Tuinity)

Airplane Changes:
d7d1626 Remove multithreaded entity tracker
677ec73 Ensure armor change event is on main thread
c07d254 Fix crash
ec7605c Updated Upstream (Tuinity)
2768f39 Update DEAR commit message
e975972 Multithreaded entity tracking
98244f9 Updated Upstream (Tuinity)
44b2499 Larger headings
2c4a7fb Merge pull request #6 from Encode42/master
cc19631 More changes
beba27a Badges and variables
0aeaf12 Improve readability, grammar, etc.

Empirecraft Changes:
bbc8d297 Updated Paper

* Updated Upstream and Sidestream(s) (Paper/Origami)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
3dadd97bb [CI-SKIP] [Meta] Exempt more labels from being marked as stale (#5142)
36a72cad3 [Auto] Updated Upstream (Bukkit/CraftBukkit/Spigot)

Origami Changes:
168394a Access config after loading it... fixes velocity auto offline-mode
c47b182 Add velocity to automatic offline mode
2021-02-08 10:31:51 -05:00

169 lines
9.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Fri, 31 Jul 2020 21:58:24 -0500
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
index 5fc57e2e2afe383ddc9b6d4db714a678c881fa77..b6ae5a18ab1748f71956c2d323eb1011854bd854 100644
--- a/src/main/java/net/minecraft/server/EntityVillager.java
+++ b/src/main/java/net/minecraft/server/EntityVillager.java
@@ -31,6 +31,7 @@ import org.bukkit.event.entity.VillagerReplenishTradeEvent;
public class EntityVillager extends EntityVillagerAbstract implements ReputationHandler, VillagerDataHolder {
+ private boolean simplerVillagerBehavior = org.yatopiamc.yatopia.server.YatopiaConfig.simplerVillagerBehavior; // Yatopia - so we don't make them bork upon reload
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});
@@ -67,8 +68,14 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
public EntityVillager(EntityTypes<? extends EntityVillager> entitytypes, World world, VillagerType villagertype) {
super(entitytypes, world);
this.by = new Reputation();
+ if (!simplerVillagerBehavior) {
((Navigation) this.getNavigation()).a(true);
this.getNavigation().d(true);
+ // Yatopia start
+ } else {
+ initPathfinder();
+ }
+ // Yatopia end
this.setCanPickupLoot(true);
this.setVillagerData(this.getVillagerData().withType(villagertype).withProfession(VillagerProfession.NONE));
this.brainTickOffset = getRandom().nextInt(100); // Purpur
@@ -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
+ if (!simplerVillagerBehavior) {
+ // safety
+ return;
+ }
+ this.goalSelector.a(0, new PathfinderGoalFloat(this));
+ if (org.yatopiamc.yatopia.server.YatopiaConfig.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));
+ // Yatopia End
}
@Override
@@ -114,6 +153,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
@Override
protected BehaviorController<?> a(Dynamic<?> dynamic) {
+ if (simplerVillagerBehavior) return super.a(dynamic); // Yatopia
BehaviorController<EntityVillager> behaviorcontroller = this.cK().a(dynamic);
this.a(behaviorcontroller);
@@ -213,11 +253,39 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
// Purpur end
private int behaviorTick = 0;
+ // Yatopia 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;
+ }
+ }
+ // Yatopia end
@Override
protected void mobTick() { mobTick(false); }
protected void mobTick(boolean inactive) {
this.world.getMethodProfiler().enter("villagerBrain");
+ // Yatopia start
+ if (simplerVillagerBehavior && this.getVillagerData().getProfession() == VillagerProfession.NONE) {
+ this.setVillagerData(this.getVillagerData().withProfession(getRandomProfession()));
+ }
+ if (simplerVillagerBehavior && canRefresh()) restUses();
+ if (simplerVillagerBehavior) return;
+ // Yatopia end
// Purpur start
if (world.purpurConfig.villagerLobotomizeEnabled) inactive = inactive || isLobotomized();
boolean tick = (world.getTime() + brainTickOffset) % world.purpurConfig.villagerBrainTicks == 0;
@@ -344,6 +412,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
this.fl();
}
+ public final boolean canRefresh() { return fc(); } // Yatopia - OBFHELPER
private void fl() {
Iterator iterator = this.getOffers().iterator();
@@ -418,6 +487,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
return this.fn() && this.fm();
}
+ public final void restUses() { fo(); } // Yatopia - OBFHELPER
private void fo() {
int i = 2 - this.bD;
@@ -650,6 +720,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
}
private void a(Entity entity) {
+ if (simplerVillagerBehavior) return; // Yatopia
if (this.world instanceof WorldServer) {
Optional<List<EntityLiving>> optional = this.bg.getMemory(MemoryModuleType.VISIBLE_MOBS);
@@ -666,6 +737,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
}
public void a(MemoryModuleType<GlobalPos> memorymoduletype) {
+ if (simplerVillagerBehavior) return;
if (this.world instanceof WorldServer) {
MinecraftServer minecraftserver = ((WorldServer) this.world).getMinecraftServer();
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 {
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);
+ }
}