craftbukkit/nms-patches/net/minecraft/world/entity/npc/EntityVillager.patch

170 lines
10 KiB
Diff
Raw Normal View History

2021-03-16 09:00:00 +11:00
--- a/net/minecraft/world/entity/npc/EntityVillager.java
+++ b/net/minecraft/world/entity/npc/EntityVillager.java
2025-07-01 00:10:00 +10:00
@@ -92,6 +92,15 @@
2021-03-16 09:00:00 +11:00
import net.minecraft.world.phys.AxisAlignedBB;
2022-03-01 02:00:00 +11:00
import org.slf4j.Logger;
2021-03-09 08:47:33 +11:00
2016-05-10 21:47:39 +10:00
+// CraftBukkit start
2016-03-01 08:32:46 +11:00
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
2016-03-01 08:32:46 +11:00
+import org.bukkit.entity.Villager;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.entity.EntityTransformEvent;
2016-03-01 08:32:46 +11:00
+import org.bukkit.event.entity.VillagerReplenishTradeEvent;
2016-05-10 21:47:39 +10:00
+// CraftBukkit end
2021-03-09 08:47:33 +11:00
+
2019-04-23 12:00:00 +10:00
public class EntityVillager extends EntityVillagerAbstract implements ReputationHandler, VillagerDataHolder {
2022-03-01 02:00:00 +11:00
private static final Logger LOGGER = LogUtils.getLogger();
2025-07-01 00:10:00 +10:00
@@ -129,15 +138,18 @@
2025-03-26 03:05:00 +11:00
private boolean assignProfessionWhenSpawned;
private static final ImmutableList<MemoryModuleType<?>> MEMORY_TYPES = ImmutableList.of(MemoryModuleType.HOME, MemoryModuleType.JOB_SITE, MemoryModuleType.POTENTIAL_JOB_SITE, MemoryModuleType.MEETING_POINT, MemoryModuleType.NEAREST_LIVING_ENTITIES, MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, MemoryModuleType.VISIBLE_VILLAGER_BABIES, MemoryModuleType.NEAREST_PLAYERS, MemoryModuleType.NEAREST_VISIBLE_PLAYER, MemoryModuleType.NEAREST_VISIBLE_ATTACKABLE_PLAYER, MemoryModuleType.NEAREST_VISIBLE_WANTED_ITEM, MemoryModuleType.ITEM_PICKUP_COOLDOWN_TICKS, new MemoryModuleType[]{MemoryModuleType.WALK_TARGET, MemoryModuleType.LOOK_TARGET, MemoryModuleType.INTERACTION_TARGET, MemoryModuleType.BREED_TARGET, MemoryModuleType.PATH, MemoryModuleType.DOORS_TO_CLOSE, MemoryModuleType.NEAREST_BED, MemoryModuleType.HURT_BY, MemoryModuleType.HURT_BY_ENTITY, MemoryModuleType.NEAREST_HOSTILE, MemoryModuleType.SECONDARY_JOB_SITE, MemoryModuleType.HIDING_PLACE, MemoryModuleType.HEARD_BELL_TIME, MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE, MemoryModuleType.LAST_SLEPT, MemoryModuleType.LAST_WOKEN, MemoryModuleType.LAST_WORKED_AT_POI, MemoryModuleType.GOLEM_DETECTED_RECENTLY});
private static final ImmutableList<SensorType<? extends Sensor<? super EntityVillager>>> SENSOR_TYPES = ImmutableList.of(SensorType.NEAREST_LIVING_ENTITIES, SensorType.NEAREST_PLAYERS, SensorType.NEAREST_ITEMS, SensorType.NEAREST_BED, SensorType.HURT_BY, SensorType.VILLAGER_HOSTILES, SensorType.VILLAGER_BABIES, SensorType.SECONDARY_POIS, SensorType.GOLEM_DETECTED);
- public static final Map<MemoryModuleType<GlobalPos>, BiPredicate<EntityVillager, Holder<VillagePlaceType>>> POI_MEMORIES = ImmutableMap.of(MemoryModuleType.HOME, (BiPredicate) (entityvillager, holder) -> {
+ public static final Map<MemoryModuleType<GlobalPos>, BiPredicate<EntityVillager, Holder<VillagePlaceType>>> POI_MEMORIES = ImmutableMap.of(MemoryModuleType.HOME, (entityvillager, holder) -> { // CraftBukkit - decompile error
return holder.is(PoiTypes.HOME);
- }, MemoryModuleType.JOB_SITE, (BiPredicate) (entityvillager, holder) -> {
+ }, MemoryModuleType.JOB_SITE, (entityvillager, holder) -> { // CraftBukkit - decompile error
return ((VillagerProfession) entityvillager.getVillagerData().profession().value()).heldJobSite().test(holder);
- }, MemoryModuleType.POTENTIAL_JOB_SITE, (BiPredicate) (entityvillager, holder) -> {
+ }, MemoryModuleType.POTENTIAL_JOB_SITE, (entityvillager, holder) -> { // CraftBukkit - decompile error
return VillagerProfession.ALL_ACQUIRABLE_JOBS.test(holder);
- }, MemoryModuleType.MEETING_POINT, (BiPredicate) (entityvillager, holder) -> {
+ }, MemoryModuleType.MEETING_POINT, (entityvillager, holder) -> { // CraftBukkit - decompile error
return holder.is(PoiTypes.MEETING);
});
+ // CraftBukkit start
+ public long gossipDecayInterval = GOSSIP_DECAY_INTERVAL;
+ // CraftBukkit end
public EntityVillager(EntityTypes<? extends EntityVillager> entitytypes, World world) {
this(entitytypes, world, VillagerType.PLAINS);
2025-07-01 00:10:00 +10:00
@@ -150,7 +162,9 @@
2025-03-26 03:05:00 +11:00
public EntityVillager(EntityTypes<? extends EntityVillager> entitytypes, World world, Holder<VillagerType> holder) {
super(entitytypes, world);
2025-03-26 03:05:00 +11:00
this.foodLevel = 0;
- this.gossips = new Reputation();
+ // CraftBukkit start - add constructor parameter in Reputation
+ this.gossips = new Reputation(this);
+ // CraftBukkit end
2025-03-26 03:05:00 +11:00
this.lastGossipDecayTime = 0L;
this.villagerXp = 0;
this.lastRestockGameTime = 0L;
2025-07-01 00:10:00 +10:00
@@ -165,7 +179,7 @@
2019-04-23 12:00:00 +10:00
@Override
2021-11-22 09:00:00 +11:00
public BehaviorController<EntityVillager> getBrain() {
- return super.getBrain();
+ return (BehaviorController<EntityVillager>) super.getBrain(); // CraftBukkit - decompile error
2019-04-23 12:00:00 +10:00
}
2016-03-01 08:32:46 +11:00
2019-04-23 12:00:00 +10:00
@Override
2025-07-01 00:10:00 +10:00
@@ -250,7 +264,7 @@
2021-06-11 15:00:00 +10:00
this.increaseProfessionLevelOnUpdate = false;
}
- this.addEffect(new MobEffect(MobEffects.REGENERATION, 200, 0));
+ this.addEffect(new MobEffect(MobEffects.REGENERATION, 200, 0), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.VILLAGER_TRADE); // CraftBukkit
}
}
2025-07-01 00:10:00 +10:00
@@ -368,7 +382,13 @@
2025-03-26 03:05:00 +11:00
this.updateDemand();
2025-03-26 03:05:00 +11:00
for (MerchantRecipe merchantrecipe : this.getOffers()) {
- merchantrecipe.resetUses();
+ // CraftBukkit start
+ VillagerReplenishTradeEvent event = new VillagerReplenishTradeEvent((Villager) this.getBukkitEntity(), merchantrecipe.asBukkit());
+ Bukkit.getPluginManager().callEvent(event);
+ if (!event.isCancelled()) {
+ merchantrecipe.resetUses();
+ }
+ // CraftBukkit end
}
2023-03-15 03:30:00 +11:00
this.resendOffersToTradingPlayer();
2025-07-01 00:10:00 +10:00
@@ -427,7 +447,13 @@
2016-03-01 08:32:46 +11:00
2025-03-26 03:05:00 +11:00
if (i > 0) {
for (MerchantRecipe merchantrecipe : this.getOffers()) {
- merchantrecipe.resetUses();
2019-04-23 12:00:00 +10:00
+ // CraftBukkit start
+ VillagerReplenishTradeEvent event = new VillagerReplenishTradeEvent((Villager) this.getBukkitEntity(), merchantrecipe.asBukkit());
2019-04-23 12:00:00 +10:00
+ Bukkit.getPluginManager().callEvent(event);
+ if (!event.isCancelled()) {
+ merchantrecipe.resetUses();
2019-04-23 12:00:00 +10:00
+ }
+ // CraftBukkit end
}
2019-04-23 12:00:00 +10:00
}
2025-07-01 00:10:00 +10:00
@@ -500,7 +526,7 @@
2025-06-18 01:15:00 +10:00
this.entityData.set(EntityVillager.DATA_VILLAGER_DATA, (VillagerData) valueinput.read("VillagerData", VillagerData.CODEC).orElseGet(EntityVillager::createDefaultVillagerData));
this.foodLevel = valueinput.getByteOr("FoodLevel", (byte) 0);
2025-03-26 03:05:00 +11:00
this.gossips.clear();
2025-06-18 01:15:00 +10:00
- Optional optional = valueinput.read("Gossips", Reputation.CODEC);
+ Optional<Reputation> optional = valueinput.read("Gossips", Reputation.CODEC); // CraftBukkit - decompile error
2025-03-26 03:05:00 +11:00
Reputation reputation = this.gossips;
Objects.requireNonNull(this.gossips);
2025-07-01 00:10:00 +10:00
@@ -777,7 +803,7 @@
2024-10-23 02:15:00 +11:00
entitywitch1.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entitywitch1.blockPosition()), EntitySpawnReason.CONVERSION, (GroupDataEntity) null);
entitywitch1.setPersistenceRequired();
2022-12-08 03:00:00 +11:00
this.releaseAllPois();
2024-10-23 02:15:00 +11:00
- });
+ }, EntityTransformEvent.TransformReason.LIGHTNING, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); // CraftBukkit
if (entitywitch == null) {
super.thunderHit(worldserver, entitylightning);
2025-07-01 00:10:00 +10:00
@@ -825,7 +851,7 @@
2025-03-26 03:05:00 +11:00
@Override
protected void updateTrades() {
VillagerData villagerdata = this.getVillagerData();
- ResourceKey<VillagerProfession> resourcekey = (ResourceKey) villagerdata.profession().unwrapKey().orElse((Object) null);
+ ResourceKey<VillagerProfession> resourcekey = (ResourceKey) villagerdata.profession().unwrapKey().orElse(null); // CraftBukkit - decompile error
if (resourcekey != null) {
Int2ObjectMap<VillagerTrades.IMerchantRecipeOption[]> int2objectmap;
2025-07-01 00:10:00 +10:00
@@ -864,7 +890,7 @@
if (this.lastGossipDecayTime == 0L) {
this.lastGossipDecayTime = i;
- } else if (i >= this.lastGossipDecayTime + 24000L) {
+ } else if (i >= this.lastGossipDecayTime + gossipDecayInterval) { // CraftBukkit - use variable for decay interval
this.gossips.decay();
this.lastGossipDecayTime = i;
}
2025-07-01 00:10:00 +10:00
@@ -879,7 +905,7 @@
2024-10-23 02:15:00 +11:00
}).limit(5L).toList();
2019-06-21 20:00:00 +10:00
2022-06-08 02:00:00 +10:00
if (list1.size() >= j) {
2024-12-04 03:20:00 +11:00
- if (!SpawnUtil.trySpawnMob(EntityTypes.IRON_GOLEM, EntitySpawnReason.MOB_SUMMONED, worldserver, this.blockPosition(), 10, 8, 6, SpawnUtil.a.LEGACY_IRON_GOLEM, false).isEmpty()) {
+ if (!SpawnUtil.trySpawnMob(EntityTypes.IRON_GOLEM, EntitySpawnReason.MOB_SUMMONED, worldserver, this.blockPosition(), 10, 8, 6, SpawnUtil.a.LEGACY_IRON_GOLEM, false, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.VILLAGE_DEFENSE).isEmpty()) { // CraftBukkit
2022-06-08 02:00:00 +10:00
list.forEach(SensorGolemLastSeen::golemDetected);
}
}
2025-07-01 00:10:00 +10:00
@@ -892,15 +918,18 @@
@Override
public void onReputationEventFrom(ReputationEvent reputationevent, Entity entity) {
+ Villager.ReputationEvent bukkitReputationEvent = org.bukkit.craftbukkit.entity.CraftVillager.CraftReputationEvent.minecraftToBukkit(reputationevent); // CraftBukkit - convert event to bukkit
if (reputationevent == ReputationEvent.ZOMBIE_VILLAGER_CURED) {
- this.gossips.add(entity.getUUID(), ReputationType.MAJOR_POSITIVE, 20);
- this.gossips.add(entity.getUUID(), ReputationType.MINOR_POSITIVE, 25);
+ // CraftBukkit start - add change reason parameter
+ this.gossips.add(entity.getUUID(), ReputationType.MAJOR_POSITIVE, 20, bukkitReputationEvent);
+ this.gossips.add(entity.getUUID(), ReputationType.MINOR_POSITIVE, 25, bukkitReputationEvent);
+ // CraftBukkit end
} else if (reputationevent == ReputationEvent.TRADE) {
- this.gossips.add(entity.getUUID(), ReputationType.TRADING, 2);
+ this.gossips.add(entity.getUUID(), ReputationType.TRADING, 2, bukkitReputationEvent); // CraftBukkit - add change reason parameter
} else if (reputationevent == ReputationEvent.VILLAGER_HURT) {
- this.gossips.add(entity.getUUID(), ReputationType.MINOR_NEGATIVE, 25);
+ this.gossips.add(entity.getUUID(), ReputationType.MINOR_NEGATIVE, 25, bukkitReputationEvent); // CraftBukkit - add change reason parameter
} else if (reputationevent == ReputationEvent.VILLAGER_KILLED) {
- this.gossips.add(entity.getUUID(), ReputationType.MAJOR_NEGATIVE, 25);
+ this.gossips.add(entity.getUUID(), ReputationType.MAJOR_NEGATIVE, 25, bukkitReputationEvent); // CraftBukkit - add change reason parameter
}
}