Allow leashing villagers

This commit is contained in:
William Blake Galbreath
2025-01-05 15:57:26 -08:00
committed by granny
parent 6075c3496c
commit b12c969bc5
8 changed files with 80 additions and 124 deletions

View File

@@ -17,6 +17,14 @@
public boolean noPhysics;
private boolean wasOnFire;
public final RandomSource random = SHARED_RANDOM; // Paper - Share random for entities to make them more random
@@ -2922,6 +_,7 @@
if (this.isAlive() && this instanceof Leashable leashable) {
if (leashable.getLeashHolder() == player) {
if (!this.level().isClientSide()) {
+ if (hand == InteractionHand.OFF_HAND && (level().purpurConfig.villagerCanBeLeashed || level().purpurConfig.wanderingTraderCanBeLeashed) && this instanceof net.minecraft.world.entity.npc.AbstractVillager) return InteractionResult.CONSUME; // Purpur - Allow leashing villagers
// CraftBukkit start - fire PlayerUnleashEntityEvent
// Paper start - Expand EntityUnleashEvent
org.bukkit.event.player.PlayerUnleashEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerUnleashEntityEvent(this, player, hand, !player.hasInfiniteMaterials());
@@ -4885,7 +_,7 @@
}

View File

@@ -0,0 +1,16 @@
--- a/net/minecraft/world/entity/npc/Villager.java
+++ b/net/minecraft/world/entity/npc/Villager.java
@@ -193,6 +_,13 @@
this.setVillagerData(this.getVillagerData().setType(villagerType).setProfession(VillagerProfession.NONE));
}
+ // Purpur start - Allow leashing villagers
+ @Override
+ public boolean canBeLeashed() {
+ return level().purpurConfig.villagerCanBeLeashed;
+ }
+ // Purpur end - Allow leashing villagers
+
@Override
public Brain<Villager> getBrain() {
return (Brain<Villager>)super.getBrain();

View File

@@ -0,0 +1,16 @@
--- a/net/minecraft/world/entity/npc/WanderingTrader.java
+++ b/net/minecraft/world/entity/npc/WanderingTrader.java
@@ -69,6 +_,13 @@
super(entityType, level);
}
+ // Purpur start - Allow leashing villagers
+ @Override
+ public boolean canBeLeashed() {
+ return level().purpurConfig.wanderingTraderCanBeLeashed;
+ }
+ // Purpur end - Allow leashing villagers
+
@Override
protected void registerGoals() {
this.goalSelector.addGoal(0, new FloatGoal(this));