mirror of
https://github.com/YatopiaMC/Yatopia.git
synced 2025-02-11 18:02:33 +01:00
This update had major internal changes, which took us 8 hours to figure out and resolve all things untill we have a successful build. YatopiaMC members wish you happy playing using Yatopia for your server software MAKE A BACKUP OF YOUR WORLD BEFORE RUNNING IT ON YOUR SERVER. YOU HAVE BEEN WARNED. People have reported to paper that after upgrading villagers are gone. There could be even more issues we are unknown of. MAKE A BACKUP OF YOUR WORLD BEFORE RUNNING IT ON YOUR SERVER. YOU HAVE BEEN WARNED. Co-authored-by: Ovydux <68059159+Ovydux@users.noreply.github.com> Co-authored-by: Simon Gardling <Titaniumtown@gmail.com> Co-authored-by: budgidiere <sgidiere@gmail.com>
170 lines
9.2 KiB
Diff
170 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/dev/tr7zw/yatopia/YatopiaConfig.java b/src/main/java/dev/tr7zw/yatopia/YatopiaConfig.java
|
|
index fb7551f79f3e2e7e834359ef701ff7e568882a7f..0566088538c2b99ff74a408b67a9edee4751f904 100644
|
|
--- a/src/main/java/dev/tr7zw/yatopia/YatopiaConfig.java
|
|
+++ b/src/main/java/dev/tr7zw/yatopia/YatopiaConfig.java
|
|
@@ -224,4 +224,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);
|
|
+ }
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/EntityVillager.java b/src/main/java/net/minecraft/server/EntityVillager.java
|
|
index 1b2e395cc141bf700e1f7c24fe8ee7dc68b25513..416d421c3ff49125cd540a6e360523775f034689 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityVillager.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityVillager.java
|
|
@@ -27,6 +27,7 @@ import org.bukkit.event.entity.VillagerReplenishTradeEvent;
|
|
|
|
public class EntityVillager extends EntityVillagerAbstract implements ReputationHandler, VillagerDataHolder {
|
|
|
|
+ private boolean simplerVillagerBehavior = dev.tr7zw.yatopia.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});
|
|
@@ -64,12 +65,52 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
|
|
super(entitytypes, world);
|
|
this.by = new Reputation();
|
|
((Navigation) this.getNavigation()).a(true);
|
|
+ if (!simplerVillagerBehavior) { // Yatopia
|
|
this.getNavigation().d(true);
|
|
this.setCanPickupLoot(true);
|
|
+ } else { // Yatopia start
|
|
+ initPathfinder();
|
|
+ }
|
|
+ // Yatopia end
|
|
this.setVillagerData(this.getVillagerData().withType(villagertype).withProfession(VillagerProfession.NONE));
|
|
this.brainTickOffset = getRandom().nextInt(100); // Purpur
|
|
}
|
|
|
|
+ // Yatopia start
|
|
+ @Override
|
|
+ protected void initPathfinder() {
|
|
+ if (!simplerVillagerBehavior) {
|
|
+ // safety
|
|
+ return;
|
|
+ }
|
|
+ this.goalSelector.a(0, new PathfinderGoalFloat(this));
|
|
+ if(dev.tr7zw.yatopia.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));
|
|
+ }
|
|
+
|
|
@Override
|
|
public BehaviorController<EntityVillager> getBehaviorController() {
|
|
return (BehaviorController<EntityVillager>) super.getBehaviorController(); // CraftBukkit - decompile error
|
|
@@ -82,6 +123,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.cJ().a(dynamic);
|
|
|
|
this.a(behaviorcontroller);
|
|
@@ -159,6 +201,27 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
|
|
super.inactiveTick();
|
|
}
|
|
// Spigot End
|
|
+ // 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); }
|
|
@@ -168,6 +231,13 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
|
|
boolean tick = (world.getTime() + brainTickOffset) % world.purpurConfig.villagerBrainTicks == 0;
|
|
if (world.getMinecraftServer().lagging ? tick : world.purpurConfig.villagerUseBrainTicksOnlyWhenLagging || tick)
|
|
// Purpur end
|
|
+ // Yatopia start
|
|
+ if (simplerVillagerBehavior && this.getVillagerData().getProfession() == VillagerProfession.NONE) {
|
|
+ this.setVillagerData(this.getVillagerData().withProfession(getRandomProfession()));
|
|
+ }
|
|
+ if (simplerVillagerBehavior && canRefresh()) restUses();
|
|
+ if (simplerVillagerBehavior) return;
|
|
+ // Yatopia end
|
|
if (!inactive) this.getBehaviorController().a((WorldServer) this.world, this); // CraftBukkit - decompile error // Paper
|
|
//this.world.getMethodProfiler().exit(); // Akarin - remove caller
|
|
if (this.bF) {
|
|
@@ -333,6 +403,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
|
|
return this.bD == 0 || this.bD < 2 && this.world.getTime() > this.bC + 2400L;
|
|
}
|
|
|
|
+ public final boolean canRefresh() { return fc(); } // Yatopia - OBFHELPER
|
|
public boolean fc() {
|
|
long i = this.bC + 12000L;
|
|
long j = this.world.getTime();
|
|
@@ -355,6 +426,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;
|
|
|
|
@@ -585,6 +657,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);
|
|
|
|
@@ -610,6 +683,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
|
|
}
|
|
|
|
public void a(MemoryModuleType<GlobalPos> memorymoduletype) {
|
|
+ if (simplerVillagerBehavior) return; // Yatopia
|
|
if (this.world instanceof WorldServer) {
|
|
MinecraftServer minecraftserver = ((WorldServer) this.world).getMinecraftServer();
|
|
|