Fix EntityJoinWorldEvent not firing as expected: (#8033)

- Fix entities loaded from disk not getting the event.
- Fix vehicles with passengers getting the event twice.
This commit is contained in:
gigaherz authored and GitHub committed 2021-09-16 17:11:04 -07:00
1 parent 69136fce19
commit b01a217f45
4 files changed
+39 -19

No files matched your search

@@ -146,30 +146,16 @@
Entity entity = this.m_142646_().m_142694_(p_8854_.m_142081_());
if (entity != null) {
f_8566_.warn("Force-added player with duplicate UUID {}", (Object)p_8854_.m_142081_().toString());
@@ -747,6 +_,7 @@
@@ -746,7 +_,8 @@
this.m_143261_((ServerPlayer)entity, Entity.RemovalReason.DISCARDED);
}
this.f_143244_.m_157533_(p_8854_);
- this.f_143244_.m_157533_(p_8854_);
+ this.f_143244_.addNewEntityWithoutEvent(p_8854_);
+ p_8854_.onAddedToWorld();
}
private boolean m_8872_(Entity p_8873_) {
@@ -754,6 +_,7 @@
f_8566_.warn("Tried to add entity {} but it was marked as removed already", (Object)EntityType.m_20613_(p_8873_.m_6095_()));
return false;
} else {
+ if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityJoinWorldEvent(p_8873_, this))) return false;
return this.f_143244_.m_157533_(p_8873_);
}
}
@@ -762,6 +_,7 @@
if (p_8861_.m_142428_().map(Entity::m_142081_).anyMatch(this.f_143244_::m_157550_)) {
return false;
} else {
+ if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityJoinWorldEvent(p_8861_, this))) return false;
this.m_47205_(p_8861_);
return true;
}
@@ -790,10 +_,20 @@
}
@@ -0,0 +1,19 @@
--- a/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
+++ b/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
@@ -72,7 +_,16 @@
return this.m_157538_(p_157534_, false);
}
+ public boolean addNewEntityWithoutEvent(T entity) {
+ return this.addEntityWithoutEvent(entity, false);
+ }
+
private boolean m_157538_(T p_157539_, boolean p_157540_) {
+ if (p_157539_ instanceof Entity entity && net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.EntityJoinWorldEvent(entity, entity.f_19853_, p_157540_))) return false;
+ return addEntityWithoutEvent(p_157539_, p_157540_);
+ }
+
+ private boolean addEntityWithoutEvent(T p_157539_, boolean p_157540_) {
if (!this.m_157557_(p_157539_)) {
return false;
} else {
@@ -42,15 +42,30 @@ public class EntityJoinWorldEvent extends EntityEvent
{
private final Level world;
private final boolean loadedFromDisk;
public EntityJoinWorldEvent(Entity entity, Level world)
{
this(entity, world, false);
}
public EntityJoinWorldEvent(Entity entity, Level world, boolean loadedFromDisk)
{
super(entity);
this.world = world;
this.loadedFromDisk = loadedFromDisk;
}
public Level getWorld()
{
return world;
}
/**
* @return {@code true} if the entity was loaded from disk. On client entities, the info isn't available and this will always return {@code false}.
*/
public boolean loadedFromDisk()
{
return loadedFromDisk;
}
}
+1 -1
View File
@@ -35,7 +35,6 @@ net/minecraft/world/entity/item/ItemEntity.changeDimension(Lnet/minecraft/server
net/minecraft/world/entity/npc/AbstractVillager.changeDimension(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraftforge/common/util/ITeleporter;)Lnet/minecraft/world/entity/Entity;=|p_35295_,teleporter
net/minecraft/world/entity/player/Player.getDigSpeed(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;)F=|p_36282_,pos
net/minecraft/world/entity/projectile/ThrownEnderpearl.changeDimension(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraftforge/common/util/ITeleporter;)Lnet/minecraft/world/entity/Entity;=|p_37506_,teleporter
net/minecraft/world/entity/vehicle/AbstractMinecartContainer.changeDimension(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraftforge/common/util/ITeleporter;)Lnet/minecraft/world/entity/Entity;=|p_38246_,teleporter
net/minecraft/world/item/BoneMealItem.applyBonemeal(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/player/Player;)Z=|p_40628_,p_40629_,p_40630_,player
net/minecraft/world/item/DyeableHorseArmorItem.<init>(ILnet/minecraft/resources/ResourceLocation;Lnet/minecraft/world/item/Item$Properties;)V=|p_41110_,p_41111_,p_41112_
net/minecraft/world/item/HorseArmorItem.<init>(ILnet/minecraft/resources/ResourceLocation;Lnet/minecraft/world/item/Item$Properties;)V=|p_41364_,p_41111_,p_41366_
@@ -49,5 +48,6 @@ net/minecraft/world/level/block/FireBlock.tryCatchFire(Lnet/minecraft/world/leve
net/minecraft/world/level/block/FlowerPotBlock.<init>(Ljava/util/function/Supplier;Ljava/util/function/Supplier;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V=|emptyPot,p_53528_,properties
net/minecraft/world/level/block/LiquidBlock.<init>(Ljava/util/function/Supplier;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V=|p_54694_,p_54695_
net/minecraft/world/level/chunk/PalettedContainer.setBits(IZ)V=|p_63122_,forceBits
net/minecraft/world/level/entity/PersistentEntitySectionManager.addEntityWithoutEvent(Lnet/minecraft/world/level/entity/EntityAccess;Z)Z=|p_157539_,p_157540_
net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate.processEntityInfos(Lnet/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/levelgen/structure/templatesystem/StructurePlaceSettings;Ljava/util/List;)Ljava/util/List;=|template,p_215387_0_,p_215387_1_,p_215387_2_,p_215387_3_
net/minecraft/world/level/storage/loot/LootPool.<init>([Lnet/minecraft/world/level/storage/loot/entries/LootPoolEntryContainer;[Lnet/minecraft/world/level/storage/loot/predicates/LootItemCondition;[Lnet/minecraft/world/level/storage/loot/functions/LootItemFunction;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;Ljava/lang/String;)V=|p_165128_,p_165129_,p_165130_,p_165131_,p_165132_,name