170 lines
10 KiB
Diff
170 lines
10 KiB
Diff
--- a/net/minecraft/world/entity/npc/EntityVillager.java
|
|
+++ b/net/minecraft/world/entity/npc/EntityVillager.java
|
|
@@ -92,6 +92,15 @@
|
|
import net.minecraft.world.phys.AxisAlignedBB;
|
|
import org.slf4j.Logger;
|
|
|
|
+// CraftBukkit start
|
|
+import org.bukkit.Bukkit;
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
+import org.bukkit.entity.Villager;
|
|
+import org.bukkit.event.entity.EntityRemoveEvent;
|
|
+import org.bukkit.event.entity.EntityTransformEvent;
|
|
+import org.bukkit.event.entity.VillagerReplenishTradeEvent;
|
|
+// CraftBukkit end
|
|
+
|
|
public class EntityVillager extends EntityVillagerAbstract implements ReputationHandler, VillagerDataHolder {
|
|
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
|
@@ -129,15 +138,18 @@
|
|
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);
|
|
@@ -150,7 +162,9 @@
|
|
public EntityVillager(EntityTypes<? extends EntityVillager> entitytypes, World world, Holder<VillagerType> holder) {
|
|
super(entitytypes, world);
|
|
this.foodLevel = 0;
|
|
- this.gossips = new Reputation();
|
|
+ // CraftBukkit start - add constructor parameter in Reputation
|
|
+ this.gossips = new Reputation(this);
|
|
+ // CraftBukkit end
|
|
this.lastGossipDecayTime = 0L;
|
|
this.villagerXp = 0;
|
|
this.lastRestockGameTime = 0L;
|
|
@@ -165,7 +179,7 @@
|
|
|
|
@Override
|
|
public BehaviorController<EntityVillager> getBrain() {
|
|
- return super.getBrain();
|
|
+ return (BehaviorController<EntityVillager>) super.getBrain(); // CraftBukkit - decompile error
|
|
}
|
|
|
|
@Override
|
|
@@ -250,7 +264,7 @@
|
|
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
|
|
}
|
|
}
|
|
|
|
@@ -368,7 +382,13 @@
|
|
this.updateDemand();
|
|
|
|
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
|
|
}
|
|
|
|
this.resendOffersToTradingPlayer();
|
|
@@ -427,7 +447,13 @@
|
|
|
|
if (i > 0) {
|
|
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
|
|
}
|
|
}
|
|
|
|
@@ -500,7 +526,7 @@
|
|
this.entityData.set(EntityVillager.DATA_VILLAGER_DATA, (VillagerData) nbttagcompound.read("VillagerData", VillagerData.CODEC).orElseGet(EntityVillager::createDefaultVillagerData));
|
|
this.foodLevel = nbttagcompound.getByteOr("FoodLevel", (byte) 0);
|
|
this.gossips.clear();
|
|
- Optional optional = nbttagcompound.read("Gossips", Reputation.CODEC);
|
|
+ Optional<Reputation> optional = nbttagcompound.read("Gossips", Reputation.CODEC); // CraftBukkit - decompile error
|
|
Reputation reputation = this.gossips;
|
|
|
|
Objects.requireNonNull(this.gossips);
|
|
@@ -777,7 +803,7 @@
|
|
entitywitch1.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entitywitch1.blockPosition()), EntitySpawnReason.CONVERSION, (GroupDataEntity) null);
|
|
entitywitch1.setPersistenceRequired();
|
|
this.releaseAllPois();
|
|
- });
|
|
+ }, EntityTransformEvent.TransformReason.LIGHTNING, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); // CraftBukkit
|
|
|
|
if (entitywitch == null) {
|
|
super.thunderHit(worldserver, entitylightning);
|
|
@@ -825,7 +851,7 @@
|
|
@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;
|
|
@@ -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;
|
|
}
|
|
@@ -879,7 +905,7 @@
|
|
}).limit(5L).toList();
|
|
|
|
if (list1.size() >= j) {
|
|
- 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
|
|
list.forEach(SensorGolemLastSeen::golemDetected);
|
|
}
|
|
}
|
|
@@ -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
|
|
}
|
|
|
|
}
|