SPIGOT-7300, #1180: Add new DamageSource API providing enhanced information about entity damage

By: Doc <nachito94@msn.com>
This commit is contained in:
CraftBukkit/Spigot
2024-02-11 09:54:25 +11:00
parent db4af65c2e
commit 49b5ee78bb
29 changed files with 640 additions and 310 deletions

View File

@@ -1,25 +1,24 @@
--- a/net/minecraft/world/damagesource/DamageSource.java
+++ b/net/minecraft/world/damagesource/DamageSource.java
@@ -20,6 +20,38 @@
@@ -20,6 +20,81 @@
private final Entity directEntity;
@Nullable
private final Vec3D damageSourcePosition;
+ // CraftBukkit start
+ private boolean sweep;
+ private boolean melting;
+ private boolean poison;
+
+ public boolean isSweep() {
+ return sweep;
+ }
+ @Nullable
+ private org.bukkit.block.Block directBlock; // The block that caused the damage. damageSourcePosition is not used for all block damages
+ private boolean withSweep = false;
+ private boolean melting = false;
+ private boolean poison = false;
+ private Entity customCausingEntity = null; // This field is a helper for when causing entity damage is not set by vanilla
+
+ public DamageSource sweep() {
+ this.sweep = true;
+ this.withSweep = true;
+ return this;
+ }
+
+ public boolean isMelting() {
+ return melting;
+ public boolean isSweep() {
+ return this.withSweep;
+ }
+
+ public DamageSource melting() {
@@ -27,15 +26,68 @@
+ return this;
+ }
+
+ public boolean isPoison() {
+ return poison;
+ public boolean isMelting() {
+ return this.melting;
+ }
+
+ public DamageSource poison() {
+ this.poison = true;
+ return this;
+ }
+
+ public boolean isPoison() {
+ return this.poison;
+ }
+
+ public Entity getCausingEntity() {
+ return (this.customCausingEntity != null) ? this.customCausingEntity : this.causingEntity;
+ }
+
+ public DamageSource customCausingEntity(Entity entity) {
+ DamageSource damageSource = this.cloneInstance();
+ damageSource.customCausingEntity = entity;
+ return damageSource;
+ }
+
+ public org.bukkit.block.Block getDirectBlock() {
+ return this.directBlock;
+ }
+
+ public DamageSource directBlock(net.minecraft.world.level.World world, net.minecraft.core.BlockPosition blockPosition) {
+ if (blockPosition == null || world == null) {
+ return this;
+ }
+ return directBlock(org.bukkit.craftbukkit.block.CraftBlock.at(world, blockPosition));
+ }
+
+ public DamageSource directBlock(org.bukkit.block.Block block) {
+ if (block == null) {
+ return this;
+ }
+ // Cloning the instance lets us return unique instances of DamageSource without affecting constants defined in DamageSources
+ DamageSource damageSource = this.cloneInstance();
+ damageSource.directBlock = block;
+ return damageSource;
+ }
+
+ private DamageSource cloneInstance() {
+ DamageSource damageSource = new DamageSource(this.type, this.directEntity, this.causingEntity, this.damageSourcePosition);
+ damageSource.directBlock = this.getDirectBlock();
+ damageSource.withSweep = this.isSweep();
+ damageSource.poison = this.isPoison();
+ damageSource.melting = this.isMelting();
+ return damageSource;
+ }
+ // CraftBukkit end
public String toString() {
return "DamageSource (" + this.type().msgId() + ")";
@@ -33,7 +108,7 @@
return this.causingEntity != this.directEntity;
}
- private DamageSource(Holder<DamageType> holder, @Nullable Entity entity, @Nullable Entity entity1, @Nullable Vec3D vec3d) {
+ public DamageSource(Holder<DamageType> holder, @Nullable Entity entity, @Nullable Entity entity1, @Nullable Vec3D vec3d) {
this.type = holder;
this.causingEntity = entity1;
this.directEntity = entity;

View File

@@ -5,8 +5,8 @@
private final DamageSource outsideBorder;
private final DamageSource genericKill;
+ // CraftBukkit start
+ public final DamageSource melting;
+ public final DamageSource poison;
+ private final DamageSource melting;
+ private final DamageSource poison;
public DamageSources(IRegistryCustom iregistrycustom) {
this.damageTypes = iregistrycustom.registryOrThrow(Registries.DAMAGE_TYPE);
@@ -16,3 +16,20 @@
this.inFire = this.source(DamageTypes.IN_FIRE);
this.lightningBolt = this.source(DamageTypes.LIGHTNING_BOLT);
this.onFire = this.source(DamageTypes.ON_FIRE);
@@ -81,6 +87,16 @@
return new DamageSource(this.damageTypes.getHolderOrThrow(resourcekey), entity, entity1);
}
+ // CraftBukkit start
+ public DamageSource melting() {
+ return this.melting;
+ }
+
+ public DamageSource poison() {
+ return this.poison;
+ }
+ // CraftBukkit end
+
public DamageSource inFire() {
return this.inFire;
}

View File

@@ -5,7 +5,7 @@
super.applyEffectTick(entityliving, i);
if (entityliving.getHealth() > 1.0F) {
- entityliving.hurt(entityliving.damageSources().magic(), 1.0F);
+ entityliving.hurt(entityliving.damageSources().poison, 1.0F); // CraftBukkit - DamageSource.MAGIC -> CraftEventFactory.POISON
+ entityliving.hurt(entityliving.damageSources().poison(), 1.0F); // CraftBukkit - DamageSource.MAGIC -> CraftEventFactory.POISON
}
}

View File

@@ -181,11 +181,12 @@
}
this.checkBelowWorld();
@@ -540,15 +668,48 @@
@@ -540,15 +668,47 @@
public void lavaHurt() {
if (!this.fireImmune()) {
- this.setSecondsOnFire(15);
- if (this.hurt(this.damageSources().lava(), 4.0F)) {
+ // CraftBukkit start - Fallen in lava TODO: this event spams!
+ if (this instanceof EntityLiving && remainingFireTicks <= 0) {
+ // not on fire yet
@@ -201,11 +202,10 @@
+ // This will be called every single tick the entity is in lava, so don't throw an event
+ this.setSecondsOnFire(15, false);
+ }
+ CraftEventFactory.blockDamage = (lastLavaContact) == null ? null : org.bukkit.craftbukkit.block.CraftBlock.at(level, lastLavaContact);
if (this.hurt(this.damageSources().lava(), 4.0F)) {
+
+ if (this.hurt(this.damageSources().lava().directBlock(level, lastLavaContact), 4.0F)) {
this.playSound(SoundEffects.GENERIC_BURN, 0.4F, 2.0F + this.random.nextFloat() * 0.4F);
}
+ CraftEventFactory.blockDamage = null;
+ // CraftBukkit end - we also don't throw an event unless the object in lava is living, to save on some event calls
}
@@ -231,7 +231,7 @@
int j = i * 20;
if (this instanceof EntityLiving) {
@@ -699,6 +860,28 @@
@@ -699,6 +859,28 @@
block.updateEntityAfterFallOn(this.level(), this);
}
@@ -260,7 +260,7 @@
if (this.onGround()) {
block.stepOn(this.level(), blockposition, iblockdata, this);
}
@@ -1026,6 +1209,20 @@
@@ -1026,6 +1208,20 @@
return SoundEffects.GENERIC_SPLASH;
}
@@ -281,7 +281,7 @@
protected void checkInsideBlocks() {
AxisAlignedBB axisalignedbb = this.getBoundingBox();
BlockPosition blockposition = BlockPosition.containing(axisalignedbb.minX + 1.0E-7D, axisalignedbb.minY + 1.0E-7D, axisalignedbb.minZ + 1.0E-7D);
@@ -1440,6 +1637,7 @@
@@ -1440,6 +1636,7 @@
this.yo = d1;
this.zo = d4;
this.setPos(d3, d1, d4);
@@ -289,7 +289,7 @@
}
public void moveTo(Vec3D vec3d) {
@@ -1634,6 +1832,12 @@
@@ -1634,6 +1831,12 @@
return false;
}
@@ -302,7 +302,7 @@
public void awardKillScore(Entity entity, int i, DamageSource damagesource) {
if (entity instanceof EntityPlayer) {
CriterionTriggers.ENTITY_KILLED_PLAYER.trigger((EntityPlayer) entity, this, damagesource);
@@ -1662,16 +1866,22 @@
@@ -1662,16 +1865,22 @@
}
public boolean saveAsPassenger(NBTTagCompound nbttagcompound) {
@@ -327,7 +327,7 @@
return true;
}
}
@@ -1682,16 +1892,38 @@
@@ -1682,16 +1891,38 @@
}
public NBTTagCompound saveWithoutId(NBTTagCompound nbttagcompound) {
@@ -370,7 +370,7 @@
nbttagcompound.put("Rotation", this.newFloatList(this.getYRot(), this.getXRot()));
nbttagcompound.putFloat("FallDistance", this.fallDistance);
nbttagcompound.putShort("Fire", (short) this.remainingFireTicks);
@@ -1699,7 +1931,28 @@
@@ -1699,7 +1930,28 @@
nbttagcompound.putBoolean("OnGround", this.onGround());
nbttagcompound.putBoolean("Invulnerable", this.invulnerable);
nbttagcompound.putInt("PortalCooldown", this.portalCooldown);
@@ -400,7 +400,7 @@
IChatBaseComponent ichatbasecomponent = this.getCustomName();
if (ichatbasecomponent != null) {
@@ -1748,7 +2001,7 @@
@@ -1748,7 +2000,7 @@
nbttagcompound.put("Tags", nbttaglist);
}
@@ -409,7 +409,7 @@
if (this.isVehicle()) {
nbttaglist = new NBTTagList();
iterator = this.getPassengers().iterator();
@@ -1757,7 +2010,7 @@
@@ -1757,7 +2009,7 @@
Entity entity = (Entity) iterator.next();
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
@@ -418,7 +418,7 @@
nbttaglist.add(nbttagcompound1);
}
}
@@ -1767,6 +2020,11 @@
@@ -1767,6 +2019,11 @@
}
}
@@ -430,7 +430,7 @@
return nbttagcompound;
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
@@ -1850,6 +2108,45 @@
@@ -1850,6 +2107,45 @@
} else {
throw new IllegalStateException("Entity has invalid position");
}
@@ -476,7 +476,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Entity being loaded");
@@ -1871,6 +2168,12 @@
@@ -1871,6 +2167,12 @@
return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null;
}
@@ -489,7 +489,7 @@
protected abstract void readAdditionalSaveData(NBTTagCompound nbttagcompound);
protected abstract void addAdditionalSaveData(NBTTagCompound nbttagcompound);
@@ -1925,9 +2228,22 @@
@@ -1925,9 +2227,22 @@
} else if (this.level().isClientSide) {
return null;
} else {
@@ -512,7 +512,7 @@
this.level().addFreshEntity(entityitem);
return entityitem;
}
@@ -2025,6 +2341,27 @@
@@ -2025,6 +2340,27 @@
if (!flag && (!this.canRide(entity) || !entity.canAddPassenger(this))) {
return false;
} else {
@@ -540,7 +540,7 @@
if (this.isPassenger()) {
this.stopRiding();
}
@@ -2058,7 +2395,7 @@
@@ -2058,7 +2394,7 @@
Entity entity = this.vehicle;
this.vehicle = null;
@@ -549,7 +549,7 @@
}
}
@@ -2089,10 +2426,38 @@
@@ -2089,10 +2425,38 @@
}
}
@@ -589,7 +589,7 @@
if (this.passengers.size() == 1 && this.passengers.get(0) == entity) {
this.passengers = ImmutableList.of();
} else {
@@ -2104,6 +2469,7 @@
@@ -2104,6 +2468,7 @@
entity.boardingCooldown = 60;
this.gameEvent(GameEvent.ENTITY_DISMOUNT, entity);
}
@@ -597,7 +597,7 @@
}
protected boolean canAddPassenger(Entity entity) {
@@ -2190,14 +2556,20 @@
@@ -2190,14 +2555,20 @@
if (this.isInsidePortal) {
MinecraftServer minecraftserver = worldserver.getServer();
@@ -621,7 +621,7 @@
this.level().getProfiler().pop();
}
@@ -2321,6 +2693,13 @@
@@ -2321,6 +2692,13 @@
}
public void setSwimming(boolean flag) {
@@ -635,7 +635,7 @@
this.setSharedFlag(4, flag);
}
@@ -2370,8 +2749,12 @@
@@ -2370,8 +2748,12 @@
return this.getTeam() != null ? this.getTeam().isAlliedTo(scoreboardteambase) : false;
}
@@ -649,7 +649,7 @@
}
public boolean getSharedFlag(int i) {
@@ -2390,7 +2773,7 @@
@@ -2390,7 +2772,7 @@
}
public int getMaxAirSupply() {
@@ -658,7 +658,7 @@
}
public int getAirSupply() {
@@ -2398,7 +2781,18 @@
@@ -2398,7 +2780,18 @@
}
public void setAirSupply(int i) {
@@ -678,7 +678,7 @@
}
public int getTicksFrozen() {
@@ -2425,11 +2819,41 @@
@@ -2425,11 +2818,40 @@
public void thunderHit(WorldServer worldserver, EntityLightning entitylightning) {
this.setRemainingFireTicks(this.remainingFireTicks + 1);
@@ -713,16 +713,15 @@
+ if (this.fireImmune()) {
+ return;
+ }
+ CraftEventFactory.entityDamage = entitylightning;
+ if (!this.hurt(this.damageSources().lightningBolt(), 5.0F)) {
+ CraftEventFactory.entityDamage = null;
+
+ if (!this.hurt(this.damageSources().lightningBolt().customCausingEntity(entitylightning), 5.0F)) {
+ return;
+ }
+ // CraftBukkit end
}
public void onAboveBubbleCol(boolean flag) {
@@ -2594,15 +3018,38 @@
@@ -2594,15 +3016,38 @@
@Nullable
public Entity changeDimension(WorldServer worldserver) {
@@ -763,7 +762,7 @@
this.level().getProfiler().popPush("reloading");
Entity entity = this.getType().create(worldserver);
@@ -2610,10 +3057,22 @@
@@ -2610,10 +3055,22 @@
entity.restoreFrom(this);
entity.moveTo(shapedetectorshape.pos.x, shapedetectorshape.pos.y, shapedetectorshape.pos.z, shapedetectorshape.yRot, entity.getXRot());
entity.setDeltaMovement(shapedetectorshape.speed);
@@ -789,7 +788,7 @@
}
this.removeAfterChangingDimensions();
@@ -2634,20 +3093,34 @@
@@ -2634,20 +3091,34 @@
@Nullable
protected ShapeDetectorShape findDimensionEntryPoint(WorldServer worldserver) {
@@ -829,7 +828,7 @@
IBlockData iblockdata = this.level().getBlockState(this.portalEntrancePos);
EnumDirection.EnumAxis enumdirection_enumaxis;
Vec3D vec3d;
@@ -2664,8 +3137,8 @@
@@ -2664,8 +3135,8 @@
vec3d = new Vec3D(0.5D, 0.0D, 0.0D);
}
@@ -840,7 +839,7 @@
}
} else {
BlockPosition blockposition1;
@@ -2675,8 +3148,14 @@
@@ -2675,8 +3146,14 @@
} else {
blockposition1 = worldserver.getHeightmapPos(HeightMap.Type.MOTION_BLOCKING_NO_LEAVES, worldserver.getSharedSpawnPos());
}
@@ -856,7 +855,7 @@
}
}
@@ -2684,8 +3163,23 @@
@@ -2684,8 +3161,23 @@
return BlockPortalShape.getRelativePosition(blockutil_rectangle, enumdirection_enumaxis, this.position(), this.getDimensions(this.getPose()));
}
@@ -882,7 +881,7 @@
}
public boolean canChangeDimensions() {
@@ -2806,6 +3300,12 @@
@@ -2806,6 +3298,12 @@
}
}
@@ -895,7 +894,7 @@
public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set<RelativeMovement> set, float f, float f1) {
float f2 = MathHelper.clamp(f1, -90.0F, 90.0F);
@@ -2825,7 +3325,11 @@
@@ -2825,7 +3323,11 @@
entity.moveTo(d0, d1, d2, f, f2);
entity.setYHeadRot(f);
this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION);
@@ -908,7 +907,7 @@
}
return true;
@@ -2931,7 +3435,26 @@
@@ -2931,7 +3433,26 @@
}
public final void setBoundingBox(AxisAlignedBB axisalignedbb) {
@@ -936,7 +935,7 @@
}
protected float getEyeHeight(EntityPose entitypose, EntitySize entitysize) {
@@ -3246,6 +3769,11 @@
@@ -3246,6 +3767,11 @@
vec3d = vec3d.add(vec3d1);
++k1;
}

View File

@@ -16,7 +16,7 @@
if (!this.level().isClientSide) {
if (this.level().getBiome(this.blockPosition()).is(BiomeTags.SNOW_GOLEM_MELTS)) {
- this.hurt(this.damageSources().onFire(), 1.0F);
+ this.hurt(this.damageSources().melting, 1.0F); // CraftBukkit - DamageSource.BURN -> CraftEventFactory.MELTING
+ this.hurt(this.damageSources().melting(), 1.0F); // CraftBukkit - DamageSources.ON_FIRE -> CraftEventFactory.MELTING
}
if (!this.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) {

View File

@@ -10,17 +10,16 @@
}
}
@@ -334,7 +336,9 @@
@@ -334,7 +336,7 @@
@Override
public void thunderHit(WorldServer worldserver, EntityLightning entitylightning) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.entityDamage = entitylightning; // CraftBukkit
this.hurt(this.damageSources().lightningBolt(), Float.MAX_VALUE);
+ org.bukkit.craftbukkit.event.CraftEventFactory.entityDamage = null; // CraftBukkit
- this.hurt(this.damageSources().lightningBolt(), Float.MAX_VALUE);
+ this.hurt(this.damageSources().lightningBolt().customCausingEntity(entitylightning), Float.MAX_VALUE); // CraftBukkit
}
@Override
@@ -491,12 +495,14 @@
@@ -491,12 +493,14 @@
} else if (this.turtle.layEggCounter > this.adjustedTickDelay(200)) {
World world = this.turtle.level();

View File

@@ -43,13 +43,3 @@
if (this.level().setBlock(blockposition, this.blockState, 3)) {
((WorldServer) this.level()).getChunkSource().chunkMap.broadcast(this, new PacketPlayOutBlockChange(blockposition, this.level().getBlockState(blockposition)));
this.discard();
@@ -255,7 +272,9 @@
float f2 = (float) Math.min(MathHelper.floor((float) i * this.fallDamagePerDistance), this.fallDamageMax);
this.level().getEntities((Entity) this, this.getBoundingBox(), predicate).forEach((entity) -> {
+ CraftEventFactory.entityDamage = this; // CraftBukkit
entity.hurt(damagesource2, f2);
+ CraftEventFactory.entityDamage = null; // CraftBukkit
});
boolean flag = this.blockState.is(TagsBlock.ANVIL);

View File

@@ -14,7 +14,7 @@
public class EntityEnderPearl extends EntityProjectileThrowable {
public EntityEnderPearl(EntityTypes<? extends EntityEnderPearl> entitytypes, World world) {
@@ -54,23 +61,36 @@
@@ -54,23 +61,34 @@
EntityPlayer entityplayer = (EntityPlayer) entity;
if (entityplayer.connection.isAcceptingMessages() && entityplayer.level() == this.level() && !entityplayer.isSleeping()) {
@@ -56,15 +56,13 @@
- entity.hurt(this.damageSources().fall(), 5.0F);
+ entityplayer.connection.teleport(teleEvent.getTo());
+ entity.resetFallDistance();
+ CraftEventFactory.entityDamage = this;
+ entity.hurt(this.damageSources().fall(), 5.0F);
+ CraftEventFactory.entityDamage = null;
+ entity.hurt(this.damageSources().fall().customCausingEntity(this), 5.0F); // CraftBukkit
+ }
+ // CraftBukkit end
this.level().playSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), SoundEffects.PLAYER_TELEPORT, SoundCategory.PLAYERS);
}
} else if (entity != null) {
@@ -100,7 +120,7 @@
@@ -100,7 +118,7 @@
public Entity changeDimension(WorldServer worldserver) {
Entity entity = this.getOwner();

View File

@@ -1,12 +1,11 @@
--- a/net/minecraft/world/entity/projectile/EntityEvokerFangs.java
+++ b/net/minecraft/world/entity/projectile/EntityEvokerFangs.java
@@ -129,7 +129,9 @@
@@ -129,7 +129,7 @@
if (entityliving.isAlive() && !entityliving.isInvulnerable() && entityliving != entityliving1) {
if (entityliving1 == null) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.entityDamage = this; // CraftBukkit
entityliving.hurt(this.damageSources().magic(), 6.0F);
+ org.bukkit.craftbukkit.event.CraftEventFactory.entityDamage = null; // CraftBukkit
- entityliving.hurt(this.damageSources().magic(), 6.0F);
+ entityliving.hurt(this.damageSources().magic().customCausingEntity(this), 6.0F); // CraftBukkit
} else {
if (entityliving1.isAlliedTo((Entity) entityliving)) {
return;

View File

@@ -1,15 +1,6 @@
--- a/net/minecraft/world/entity/projectile/EntityFireworks.java
+++ b/net/minecraft/world/entity/projectile/EntityFireworks.java
@@ -28,6 +28,8 @@
import net.minecraft.world.phys.MovingObjectPositionEntity;
import net.minecraft.world.phys.Vec3D;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
public class EntityFireworks extends IProjectile implements ItemSupplier {
public static final DataWatcherObject<ItemStack> DATA_ID_FIREWORKS_ITEM = DataWatcher.defineId(EntityFireworks.class, DataWatcherRegistry.ITEM_STACK);
@@ -143,7 +145,7 @@
@@ -143,7 +143,7 @@
MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResultOnMoveVector(this, this::canHitEntity);
if (!this.noPhysics) {
@@ -18,7 +9,7 @@
this.hasImpulse = true;
}
@@ -158,7 +160,11 @@
@@ -158,7 +158,11 @@
}
if (!this.level().isClientSide && this.life > this.lifetime) {
@@ -31,7 +22,7 @@
}
}
@@ -174,7 +180,11 @@
@@ -174,7 +178,11 @@
protected void onHitEntity(MovingObjectPositionEntity movingobjectpositionentity) {
super.onHitEntity(movingobjectpositionentity);
if (!this.level().isClientSide) {
@@ -44,7 +35,7 @@
}
}
@@ -184,7 +194,11 @@
@@ -184,7 +192,11 @@
this.level().getBlockState(blockposition).entityInside(this.level(), blockposition, this);
if (!this.level().isClientSide() && this.hasExplosion()) {
@@ -57,23 +48,3 @@
}
super.onHitBlock(movingobjectpositionblock);
@@ -210,7 +224,9 @@
if (f > 0.0F) {
if (this.attachedToEntity != null) {
+ CraftEventFactory.entityDamage = this; // CraftBukkit
this.attachedToEntity.hurt(this.damageSources().fireworks(this, this.getOwner()), 5.0F + (float) (nbttaglist.size() * 2));
+ CraftEventFactory.entityDamage = null; // CraftBukkit
}
double d0 = 5.0D;
@@ -237,7 +253,9 @@
if (flag) {
float f1 = f * (float) Math.sqrt((5.0D - (double) this.distanceTo(entityliving)) / 5.0D);
+ CraftEventFactory.entityDamage = this; // CraftBukkit
entityliving.hurt(this.damageSources().fireworks(this, this.getOwner()), f1);
+ CraftEventFactory.entityDamage = null; // CraftBukkit
}
}
}

View File

@@ -28,7 +28,7 @@
public static DamageSource getDefaultDamageSource(World world, @Nullable Entity entity) {
return world.damageSources().explosion(entity, getIndirectSourceEntityInternal(entity));
@@ -85,7 +99,7 @@
@@ -85,17 +99,18 @@
this.hitPlayers = Maps.newHashMap();
this.level = world;
this.source = entity;
@@ -37,7 +37,11 @@
this.x = d0;
this.y = d1;
this.z = d2;
@@ -96,6 +110,7 @@
this.fire = flag;
this.blockInteraction = explosion_effect;
- this.damageSource = damagesource == null ? world.damageSources().explosion(this) : damagesource;
+ this.damageSource = damagesource == null ? world.damageSources().explosion(this).customCausingEntity(entity) : damagesource.customCausingEntity(entity); // CraftBukkit - handle source entity
this.damageCalculator = explosiondamagecalculator == null ? this.makeDamageCalculator(entity) : explosiondamagecalculator;
this.smallExplosionParticles = particleparam;
this.largeExplosionParticles = particleparam1;
this.explosionSound = soundeffect;
@@ -57,7 +61,7 @@
this.level.gameEvent(this.source, GameEvent.EXPLODE, new Vec3D(this.x, this.y, this.z));
Set<BlockPosition> set = Sets.newHashSet();
boolean flag = true;
@@ -228,7 +248,37 @@
@@ -228,7 +248,35 @@
d9 /= d11;
d10 /= d11;
if (this.damageCalculator.shouldDamageEntity(this, entity)) {
@@ -74,7 +78,6 @@
+ continue;
+ }
+
+ CraftEventFactory.entityDamage = source;
+ entity.lastDamageCancelled = false;
+
+ if (entity instanceof EntityEnderDragon) {
@@ -88,7 +91,6 @@
+ entity.hurt(this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity));
+ }
+
+ CraftEventFactory.entityDamage = null;
+ if (entity.lastDamageCancelled) { // SPIGOT-5339, SPIGOT-6252, SPIGOT-6777: Skip entity if damage event was cancelled
+ continue;
+ }
@@ -96,7 +98,7 @@
}
double d12 = (1.0D - d7) * (double) getSeenPercent(vec3d, entity);
@@ -247,6 +297,14 @@
@@ -247,6 +295,14 @@
d10 *= d13;
Vec3D vec3d1 = new Vec3D(d8, d9, d10);
@@ -111,7 +113,7 @@
entity.setDeltaMovement(entity.getDeltaMovement().add(vec3d1));
if (entity instanceof EntityHuman) {
EntityHuman entityhuman = (EntityHuman) entity;
@@ -287,9 +345,63 @@
@@ -287,9 +343,63 @@
SystemUtils.shuffle(this.toBlow, this.level.random);
ObjectListIterator objectlistiterator = this.toBlow.iterator();
@@ -175,7 +177,7 @@
this.level.getBlockState(blockposition).onExplosionHit(this.level, blockposition, this, (itemstack, blockposition1) -> {
addOrAppendStack(list, itemstack, blockposition1);
@@ -314,7 +426,11 @@
@@ -314,7 +424,11 @@
BlockPosition blockposition1 = (BlockPosition) objectlistiterator1.next();
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockposition1).isAir() && this.level.getBlockState(blockposition1.below()).isSolidRender(this.level, blockposition1.below())) {
@@ -188,7 +190,7 @@
}
}
}
@@ -322,6 +438,7 @@
@@ -322,6 +436,7 @@
}
private static void addOrAppendStack(List<Pair<ItemStack, BlockPosition>> list, ItemStack itemstack, BlockPosition blockposition) {

View File

@@ -18,13 +18,12 @@
IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockCactus.AGE, 0);
worldserver.setBlock(blockposition, iblockdata1, 4);
@@ -119,7 +121,9 @@
@@ -119,7 +121,7 @@
@Override
public void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ CraftEventFactory.blockDamage = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); // CraftBukkit
entity.hurt(world.damageSources().cactus(), 1.0F);
+ CraftEventFactory.blockDamage = null; // CraftBukkit
- entity.hurt(world.damageSources().cactus(), 1.0F);
+ entity.hurt(world.damageSources().cactus().directBlock(world, blockposition), 1.0F); // CraftBukkit
}
@Override

View File

@@ -1,27 +1,15 @@
--- a/net/minecraft/world/level/block/BlockCampfire.java
+++ b/net/minecraft/world/level/block/BlockCampfire.java
@@ -50,6 +50,10 @@
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
import net.minecraft.world.phys.shapes.VoxelShapes;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlock;
+// CraftBukkit end
+
public class BlockCampfire extends BlockTileEntity implements IBlockWaterlogged {
public static final MapCodec<BlockCampfire> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -106,7 +110,9 @@
@@ -106,7 +106,7 @@
@Override
public void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
if ((Boolean) iblockdata.getValue(BlockCampfire.LIT) && entity instanceof EntityLiving && !EnchantmentManager.hasFrostWalker((EntityLiving) entity)) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.blockDamage = CraftBlock.at(world, blockposition); // CraftBukkit
entity.hurt(world.damageSources().inFire(), (float) this.fireDamage);
+ org.bukkit.craftbukkit.event.CraftEventFactory.blockDamage = null; // CraftBukkit
- entity.hurt(world.damageSources().inFire(), (float) this.fireDamage);
+ entity.hurt(world.damageSources().inFire().directBlock(world, blockposition), (float) this.fireDamage); // CraftBukkit
}
super.entityInside(iblockdata, world, blockposition, entity);
@@ -216,6 +222,11 @@
@@ -216,6 +216,11 @@
BlockPosition blockposition = movingobjectpositionblock.getBlockPos();
if (!world.isClientSide && iprojectile.isOnFire() && iprojectile.mayInteract(world, blockposition) && !(Boolean) iblockdata.getValue(BlockCampfire.LIT) && !(Boolean) iblockdata.getValue(BlockCampfire.WATERLOGGED)) {

View File

@@ -1,12 +1,11 @@
--- a/net/minecraft/world/level/block/BlockMagma.java
+++ b/net/minecraft/world/level/block/BlockMagma.java
@@ -30,7 +30,9 @@
@@ -30,7 +30,7 @@
@Override
public void stepOn(World world, BlockPosition blockposition, IBlockData iblockdata, Entity entity) {
if (!entity.isSteppingCarefully() && entity instanceof EntityLiving && !EnchantmentManager.hasFrostWalker((EntityLiving) entity)) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.blockDamage = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); // CraftBukkit
entity.hurt(world.damageSources().hotFloor(), 1.0F);
+ org.bukkit.craftbukkit.event.CraftEventFactory.blockDamage = null; // CraftBukkit
- entity.hurt(world.damageSources().hotFloor(), 1.0F);
+ entity.hurt(world.damageSources().hotFloor().directBlock(world, blockposition), 1.0F); // CraftBukkit
}
super.stepOn(world, blockposition, iblockdata, entity);

View File

@@ -1,12 +1,11 @@
--- a/net/minecraft/world/level/block/BlockSweetBerryBush.java
+++ b/net/minecraft/world/level/block/BlockSweetBerryBush.java
@@ -28,6 +28,14 @@
@@ -28,6 +28,13 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+// CraftBukkit start
+import java.util.Collections;
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.player.PlayerHarvestBlockEvent;
@@ -15,7 +14,7 @@
public class BlockSweetBerryBush extends BlockPlant implements IBlockFragilePlantElement {
public static final MapCodec<BlockSweetBerryBush> CODEC = simpleCodec(BlockSweetBerryBush::new);
@@ -69,7 +77,7 @@
@@ -69,7 +76,7 @@
if (i < 3 && randomsource.nextInt(5) == 0 && worldserver.getRawBrightness(blockposition.above(), 0) >= 9) {
IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockSweetBerryBush.AGE, i + 1);
@@ -24,17 +23,16 @@
worldserver.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1));
}
@@ -84,7 +92,9 @@
@@ -84,7 +91,7 @@
double d1 = Math.abs(entity.getZ() - entity.zOld);
if (d0 >= 0.003000000026077032D || d1 >= 0.003000000026077032D) {
+ CraftEventFactory.blockDamage = CraftBlock.at(world, blockposition); // CraftBukkit
entity.hurt(world.damageSources().sweetBerryBush(), 1.0F);
+ CraftEventFactory.blockDamage = null; // CraftBukkit
- entity.hurt(world.damageSources().sweetBerryBush(), 1.0F);
+ entity.hurt(world.damageSources().sweetBerryBush().directBlock(world, blockposition), 1.0F); // CraftBukkit
}
}
@@ -101,7 +111,15 @@
@@ -101,7 +108,15 @@
} else if (i > 1) {
int j = 1 + world.random.nextInt(2);

View File

@@ -1,40 +1,27 @@
--- a/net/minecraft/world/level/block/PointedDripstoneBlock.java
+++ b/net/minecraft/world/level/block/PointedDripstoneBlock.java
@@ -43,6 +43,11 @@
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
import net.minecraft.world.phys.shapes.VoxelShapes;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+// CraftBukkit end
+
public class PointedDripstoneBlock extends Block implements Fallable, IBlockWaterlogged {
public static final MapCodec<PointedDripstoneBlock> CODEC = simpleCodec(PointedDripstoneBlock::new);
@@ -132,6 +137,11 @@
@@ -132,6 +132,11 @@
BlockPosition blockposition = movingobjectpositionblock.getBlockPos();
if (iprojectile.mayInteract(world, blockposition) && iprojectile.mayBreak(world) && iprojectile instanceof EntityThrownTrident && iprojectile.getDeltaMovement().length() > 0.6D) {
+ // CraftBukkit start
+ if (!CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState())) {
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState())) {
+ return;
+ }
+ // CraftBukkit end
world.destroyBlock(blockposition, true);
}
@@ -141,7 +151,9 @@
@@ -141,7 +146,7 @@
@Override
public void fallOn(World world, IBlockData iblockdata, BlockPosition blockposition, Entity entity, float f) {
if (iblockdata.getValue(PointedDripstoneBlock.TIP_DIRECTION) == EnumDirection.UP && iblockdata.getValue(PointedDripstoneBlock.THICKNESS) == DripstoneThickness.TIP) {
+ CraftEventFactory.blockDamage = CraftBlock.at(world, blockposition); // CraftBukkit
entity.causeFallDamage(f + 2.0F, 2.0F, world.damageSources().stalagmite());
+ CraftEventFactory.blockDamage = null; // CraftBukkit
- entity.causeFallDamage(f + 2.0F, 2.0F, world.damageSources().stalagmite());
+ entity.causeFallDamage(f + 2.0F, 2.0F, world.damageSources().stalagmite().directBlock(world, blockposition)); // CraftBukkit
} else {
super.fallOn(world, iblockdata, blockposition, entity, f);
}
@@ -386,15 +398,15 @@
@@ -386,15 +391,15 @@
if (isUnmergedTipWithDirection(iblockdata, enumdirection.getOpposite())) {
createMergedTips(iblockdata, worldserver, blockposition1);
} else if (iblockdata.isAir() || iblockdata.is(Blocks.WATER)) {
@@ -53,7 +40,7 @@
}
private static void createMergedTips(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) {
@@ -409,8 +421,8 @@
@@ -409,8 +414,8 @@
blockposition1 = blockposition.below();
}
@@ -64,7 +51,7 @@
}
public static void spawnDripParticle(World world, BlockPosition blockposition, IBlockData iblockdata) {
@@ -443,7 +455,7 @@
@@ -443,7 +448,7 @@
return (BlockPosition) findBlockVertical(generatoraccess, blockposition, enumdirection.getAxisDirection(), bipredicate, (iblockdata1) -> {
return isTip(iblockdata1, flag);
@@ -73,7 +60,7 @@
}
}
@@ -559,7 +571,7 @@
@@ -559,7 +564,7 @@
return canDripThrough(world, blockposition1, iblockdata);
};
@@ -82,7 +69,7 @@
}
@Nullable
@@ -568,7 +580,7 @@
@@ -568,7 +573,7 @@
return canDripThrough(world, blockposition1, iblockdata);
};

View File

@@ -1,18 +1,6 @@
--- a/net/minecraft/world/level/block/entity/TileEntityConduit.java
+++ b/net/minecraft/world/level/block/entity/TileEntityConduit.java
@@ -27,6 +27,11 @@
import net.minecraft.world.phys.AxisAlignedBB;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+// CraftBukkit end
+
public class TileEntityConduit extends TileEntity {
private static final int BLOCK_REFRESH_RATE = 2;
@@ -201,7 +206,7 @@
@@ -201,7 +201,7 @@
EntityHuman entityhuman = (EntityHuman) iterator.next();
if (blockposition.closerThan(entityhuman.blockPosition(), (double) j) && entityhuman.isInWaterOrRain()) {
@@ -21,18 +9,16 @@
}
}
@@ -230,8 +235,13 @@
@@ -230,8 +230,11 @@
}
if (tileentityconduit.destroyTarget != null) {
- world.playSound((EntityHuman) null, tileentityconduit.destroyTarget.getX(), tileentityconduit.destroyTarget.getY(), tileentityconduit.destroyTarget.getZ(), SoundEffects.CONDUIT_ATTACK_TARGET, SoundCategory.BLOCKS, 1.0F, 1.0F);
- tileentityconduit.destroyTarget.hurt(world.damageSources().magic(), 4.0F);
+ // CraftBukkit start
+ CraftEventFactory.blockDamage = CraftBlock.at(world, blockposition);
+ if (tileentityconduit.destroyTarget.hurt(world.damageSources().magic(), 4.0F)) {
+ world.playSound((EntityHuman) null, tileentityconduit.destroyTarget.getX(), tileentityconduit.destroyTarget.getY(), tileentityconduit.destroyTarget.getZ(), SoundEffects.CONDUIT_ATTACK_TARGET, SoundCategory.BLOCKS, 1.0F, 1.0F);
+ if (tileentityconduit.destroyTarget.hurt(world.damageSources().magic().directBlock(world, blockposition), 4.0F)) { // CraftBukkit
+ world.playSound(null, tileentityconduit.destroyTarget.getX(), tileentityconduit.destroyTarget.getY(), tileentityconduit.destroyTarget.getZ(), SoundEffects.CONDUIT_ATTACK_TARGET, SoundCategory.BLOCKS, 1.0F, 1.0F);
+ }
+ CraftEventFactory.blockDamage = null;
+ // CraftBukkit end
}