Increase diff stability

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2023-09-22 02:57:13 +10:00
parent 8a3c8cfcd4
commit e903417936
27 changed files with 162 additions and 170 deletions

View File

@@ -598,8 +598,9 @@
+ this.setSecondsOnFire(entityCombustEvent.getDuration(), false);
+ }
+ // CraftBukkit end
+ }
+
}
- this.hurt(this.damageSources().lightningBolt(), 5.0F);
+ // CraftBukkit start
+ if (thisBukkitEntity instanceof Hanging) {
+ HangingBreakByEntityEvent hangingEvent = new HangingBreakByEntityEvent((Hanging) thisBukkitEntity, stormBukkitEntity);
@@ -608,9 +609,8 @@
+ if (hangingEvent.isCancelled()) {
+ return;
+ }
}
- this.hurt(this.damageSources().lightningBolt(), 5.0F);
+ }
+
+ if (this.fireImmune()) {
+ return;
+ }
@@ -672,14 +672,14 @@
- WorldServer.makeObsidianPlatform(worldserver);
+ if (worldserver.getTypeKey() == WorldDimension.END) { // CraftBukkit
+ WorldServer.makeObsidianPlatform(worldserver, this); // CraftBukkit
+ }
}
+ // CraftBukkit start - Forward the CraftEntity to the new entity
+ this.getBukkitEntity().setHandle(entity);
+ entity.bukkitEntity = this.getBukkitEntity();
+
+ if (this instanceof EntityInsentient) {
+ ((EntityInsentient) this).dropLeash(true, false); // Unleash to prevent duping of leads.
}
+ }
+ // CraftBukkit end
}

View File

@@ -703,7 +703,7 @@
+ }
+
+ f = (float) event.getFinalDamage();
+
+ // Resistance
+ if (event.getDamage(DamageModifier.RESISTANCE) < 0) {
+ float f3 = (float) -event.getDamage(DamageModifier.RESISTANCE);
@@ -726,7 +726,7 @@
+ float armorDamage = (float) (event.getDamage() + event.getDamage(DamageModifier.BLOCKING) + event.getDamage(DamageModifier.HARD_HAT));
+ this.hurtArmor(damagesource, armorDamage);
+ }
+
+ // Apply blocking code // PAIL: steal from above
+ if (event.getDamage(DamageModifier.BLOCKING) < 0) {
+ this.level().broadcastEntityEvent(this, (byte) 29); // SPIGOT-4635 - shield damage sound
@@ -847,7 +847,7 @@
this.setSharedFlag(7, flag);
}
@@ -3027,14 +3476,21 @@
@@ -3027,13 +3476,20 @@
@Override
public boolean isPickable() {
@@ -859,18 +859,17 @@
public boolean isPushable() {
- return this.isAlive() && !this.isSpectator() && !this.onClimbable();
+ return this.isAlive() && !this.isSpectator() && !this.onClimbable() && this.collides; // CraftBukkit
}
+ }
+
+ // CraftBukkit start - collidable API
+ @Override
+ public boolean canCollideWithBukkit(Entity entity) {
+ return isPushable() && this.collides != this.collidableExemptions.contains(entity.getUUID());
+ }
}
+ // CraftBukkit end
+
@Override
public float getYHeadRot() {
return this.yHeadRot;
@@ -3229,7 +3685,26 @@
} else {
if (!this.useItem.isEmpty() && this.isUsingItem()) {

View File

@@ -17,16 +17,15 @@
- double d1 = (double) this.pos.getX() + 0.5D - (double) this.direction.getStepX() * 0.46875D;
- double d2 = (double) this.pos.getY() + 0.5D - (double) this.direction.getStepY() * 0.46875D;
- double d3 = (double) this.pos.getZ() + 0.5D - (double) this.direction.getStepZ() * 0.46875D;
-
+ double d1 = (double) blockPosition.getX() + 0.5D - (double) direction.getStepX() * 0.46875D;
+ double d2 = (double) blockPosition.getY() + 0.5D - (double) direction.getStepY() * 0.46875D;
+ double d3 = (double) blockPosition.getZ() + 0.5D - (double) direction.getStepZ() * 0.46875D;
- this.setPosRaw(d1, d2, d3);
- double d4 = (double) this.getWidth();
- double d5 = (double) this.getHeight();
- double d6 = (double) this.getWidth();
- EnumDirection.EnumAxis enumdirection_enumaxis = this.direction.getAxis();
+ double d1 = (double) blockPosition.getX() + 0.5D - (double) direction.getStepX() * 0.46875D;
+ double d2 = (double) blockPosition.getY() + 0.5D - (double) direction.getStepY() * 0.46875D;
+ double d3 = (double) blockPosition.getZ() + 0.5D - (double) direction.getStepZ() * 0.46875D;
+
+ if (entity != null) {
+ entity.setPosRaw(d1, d2, d3);
+ }

View File

@@ -25,7 +25,10 @@
+ org.bukkit.Location location = getBukkitEntity().getLocation();
+ location.setPitch(player.getLocation().getPitch());
+ location.setYaw(player.getLocation().getYaw());
+
- if (entityendermite != null) {
- entityendermite.moveTo(entity.getX(), entity.getY(), entity.getZ(), entity.getYRot(), entity.getXRot());
- this.level().addFreshEntity(entityendermite);
+ PlayerTeleportEvent teleEvent = new PlayerTeleportEvent(player, player.getLocation(), location, PlayerTeleportEvent.TeleportCause.ENDER_PEARL);
+ Bukkit.getPluginManager().callEvent(teleEvent);
+
@@ -37,13 +40,6 @@
+ entityendermite.moveTo(entity.getX(), entity.getY(), entity.getZ(), entity.getYRot(), entity.getXRot());
+ this.level().addFreshEntity(entityendermite, CreatureSpawnEvent.SpawnReason.ENDER_PEARL);
+ }
+ }
- if (entityendermite != null) {
- entityendermite.moveTo(entity.getX(), entity.getY(), entity.getZ(), entity.getYRot(), entity.getXRot());
- this.level().addFreshEntity(entityendermite);
+ if (entity.isPassenger()) {
+ entity.stopRiding();
}
- }
@@ -51,15 +47,19 @@
- entityplayer.dismountTo(this.getX(), this.getY(), this.getZ());
- } else {
- entity.teleportTo(this.getX(), this.getY(), this.getZ());
- }
+ if (entity.isPassenger()) {
+ entity.stopRiding();
+ }
- entity.resetFallDistance();
- 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.resetFallDistance();
- entity.hurt(this.damageSources().fall(), 5.0F);
+ }
+ // CraftBukkit end
}
} else if (entity != null) {

View File

@@ -46,7 +46,10 @@
+ }
+ }
+ }
+
- while (iterator1.hasNext()) {
- MobEffect mobeffect = (MobEffect) iterator1.next();
- MobEffectList mobeffectlist = mobeffect.getEffect();
+ org.bukkit.event.entity.PotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPotionSplashEvent(this, affected);
+ if (!event.isCancelled() && list != null && !list.isEmpty()) { // do not process effects if there are no effects to process
+ Entity entity1 = this.getEffectSource();
@@ -54,11 +57,22 @@
+ if (!(victim instanceof CraftLivingEntity)) {
+ continue;
+ }
+
- if (mobeffectlist.isInstantenous()) {
- mobeffectlist.applyInstantenousEffect(this, this.getOwner(), entityliving, mobeffect.getAmplifier(), d1);
- } else {
- int i = mobeffect.mapDuration((j) -> {
- return (int) (d1 * (double) j + 0.5D);
- });
- MobEffect mobeffect1 = new MobEffect(mobeffectlist, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible());
+ EntityLiving entityliving = ((CraftLivingEntity) victim).getHandle();
+ double d1 = event.getIntensity(victim);
+ // CraftBukkit end
+
- if (!mobeffect1.endsWithin(20)) {
- entityliving.addEffect(mobeffect1, entity1);
- }
- }
+ Iterator iterator1 = list.iterator();
+
+ while (iterator1.hasNext()) {
@@ -80,23 +94,7 @@
+ return (int) (d1 * (double) j + 0.5D);
+ });
+ MobEffect mobeffect1 = new MobEffect(mobeffectlist, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible());
- while (iterator1.hasNext()) {
- MobEffect mobeffect = (MobEffect) iterator1.next();
- MobEffectList mobeffectlist = mobeffect.getEffect();
-
- if (mobeffectlist.isInstantenous()) {
- mobeffectlist.applyInstantenousEffect(this, this.getOwner(), entityliving, mobeffect.getAmplifier(), d1);
- } else {
- int i = mobeffect.mapDuration((j) -> {
- return (int) (d1 * (double) j + 0.5D);
- });
- MobEffect mobeffect1 = new MobEffect(mobeffectlist, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible());
-
- if (!mobeffect1.endsWithin(20)) {
- entityliving.addEffect(mobeffect1, entity1);
- }
- }
+
+ if (!mobeffect1.endsWithin(20)) {
+ entityliving.addEffect(mobeffect1, entity1, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.POTION_SPLASH); // CraftBukkit
}

View File

@@ -1,12 +1,12 @@
--- a/net/minecraft/world/entity/projectile/EntityShulkerBullet.java
+++ b/net/minecraft/world/entity/projectile/EntityShulkerBullet.java
@@ -60,8 +60,21 @@
@@ -60,7 +60,20 @@
this.finalTarget = entity;
this.currentMoveDirection = EnumDirection.UP;
this.selectNextMoveDirection(enumdirection_enumaxis);
+ projectileSource = (org.bukkit.entity.LivingEntity) entityliving.getBukkitEntity(); // CraftBukkit
}
+ }
+
+ // CraftBukkit start
+ public Entity getTarget() {
+ return this.finalTarget;
@@ -16,12 +16,11 @@
+ this.finalTarget = e;
+ this.currentMoveDirection = EnumDirection.UP;
+ this.selectNextMoveDirection(EnumDirection.EnumAxis.X);
+ }
}
+ // CraftBukkit end
+
@Override
public SoundCategory getSoundSource() {
return SoundCategory.HOSTILE;
@@ -225,7 +238,7 @@
MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResultOnMoveVector(this, this::canHitEntity);

View File

@@ -144,11 +144,6 @@
-
- while (iterator.hasNext()) {
- WeightedRandomEnchant weightedrandomenchant = (WeightedRandomEnchant) iterator.next();
-
- if (flag) {
- ItemEnchantedBook.addEnchantment(itemstack2, weightedrandomenchant);
- } else {
- itemstack2.enchant(weightedrandomenchant.enchantment, weightedrandomenchant.level);
+ // CraftBukkit start
+ for (Map.Entry<org.bukkit.enchantments.Enchantment, Integer> entry : event.getEnchantsToAdd().entrySet()) {
+ try {
@@ -158,7 +153,11 @@
+ if (nms == null) {
+ continue;
+ }
+
- if (flag) {
- ItemEnchantedBook.addEnchantment(itemstack2, weightedrandomenchant);
- } else {
- itemstack2.enchant(weightedrandomenchant.enchantment, weightedrandomenchant.level);
+ WeightedRandomEnchant weightedrandomenchant = new WeightedRandomEnchant(nms, entry.getValue());
+ ItemEnchantedBook.addEnchantment(itemstack2, weightedrandomenchant);
+ } else {

View File

@@ -16,7 +16,8 @@
private TileEntityEnderChest activeChest;
+ // CraftBukkit start
+ private final EntityHuman owner;
+
- public InventoryEnderChest() {
+ public InventoryHolder getBukkitOwner() {
+ return owner.getBukkitEntity();
+ }
@@ -25,8 +26,7 @@
+ public Location getLocation() {
+ return this.activeChest != null ? CraftLocation.toBukkit(this.activeChest.getBlockPos(), this.activeChest.getLevel().getWorld()) : null;
+ }
- public InventoryEnderChest() {
+
+ public InventoryEnderChest(EntityHuman owner) {
super(27);
+ this.owner = owner;

View File

@@ -21,7 +21,8 @@
+ World world = sourceblock.level();
+ org.bukkit.block.Block block = CraftBlock.at(world, sourceblock.pos());
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
+
- entityliving.setItemSlot(enumitemslot, itemstack1);
+ BlockDispenseArmorEvent event = new BlockDispenseArmorEvent(block, craftItem.clone(), (org.bukkit.craftbukkit.entity.CraftLivingEntity) entityliving.getBukkitEntity());
+ if (!BlockDispenser.eventFired) {
+ world.getCraftServer().getPluginManager().callEvent(event);
@@ -42,8 +43,7 @@
+ return true;
+ }
+ }
- entityliving.setItemSlot(enumitemslot, itemstack1);
+
+ entityliving.setItemSlot(enumitemslot, CraftItemStack.asNMSCopy(event.getItem()));
+ // CraftBukkit end
if (entityliving instanceof EntityInsentient) {

View File

@@ -100,11 +100,11 @@
+ // CraftBukkit start - store default return
+ boolean defaultReturn = (!this.mustSurvive() || iblockdata.canSurvive(blockactioncontext.getLevel(), blockactioncontext.getClickedPos())) && blockactioncontext.getLevel().isUnobstructed(iblockdata, blockactioncontext.getClickedPos(), voxelshapecollision);
+ org.bukkit.entity.Player player = (blockactioncontext.getPlayer() instanceof EntityPlayer) ? (org.bukkit.entity.Player) blockactioncontext.getPlayer().getBukkitEntity() : null;
+
+ BlockCanBuildEvent event = new BlockCanBuildEvent(CraftBlock.at(blockactioncontext.getLevel(), blockactioncontext.getClickedPos()), player, CraftBlockData.fromData(iblockdata), defaultReturn);
+ blockactioncontext.getLevel().getCraftServer().getPluginManager().callEvent(event);
- return (!this.mustSurvive() || iblockdata.canSurvive(blockactioncontext.getLevel(), blockactioncontext.getClickedPos())) && blockactioncontext.getLevel().isUnobstructed(iblockdata, blockactioncontext.getClickedPos(), voxelshapecollision);
+ BlockCanBuildEvent event = new BlockCanBuildEvent(CraftBlock.at(blockactioncontext.getLevel(), blockactioncontext.getClickedPos()), player, CraftBlockData.fromData(iblockdata), defaultReturn);
+ blockactioncontext.getLevel().getCraftServer().getPluginManager().callEvent(event);
+
+ return event.isBuildable();
+ // CraftBukkit end
}

View File

@@ -107,7 +107,7 @@
});
MinecraftKey minecraftkey = recipeholder.id();
RecipeHolder<?> recipeholder1 = (RecipeHolder) map1.put(minecraftkey, recipeholder);
@@ -182,8 +208,28 @@
@@ -182,9 +208,29 @@
}
});
this.recipes = ImmutableMap.copyOf(map);
@@ -122,8 +122,8 @@
+ }
+
+ return byName.remove(mcKey) != null;
+ }
+
}
+ public void clearRecipes() {
+ this.recipes = Maps.newHashMap();
+
@@ -132,8 +132,9 @@
+ }
+
+ this.byName = Maps.newHashMap();
}
+ }
+ // CraftBukkit end
+
public static <C extends IInventory, T extends IRecipe<C>> CraftingManager.a<C, T> createCheck(final Recipes<T> recipes) {
return new CraftingManager.a<C, T>() {
@Nullable

View File

@@ -7,11 +7,11 @@
- entity.getSelfAndPassengers().forEach(this::addFreshEntity);
+ // CraftBukkit start
+ this.addFreshEntityWithPassengers(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
}
+ }
+
+ default void addFreshEntityWithPassengers(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
+ entity.getSelfAndPassengers().forEach((e) -> this.addFreshEntity(e, reason));
+ }
}
+
+ @Override
+ default WorldServer getMinecraftWorld() {

View File

@@ -24,7 +24,7 @@
dropResources(iblockdata, world, blockposition, tileentity, entityhuman, itemstack);
}
@@ -504,16 +510,24 @@
@@ -504,17 +510,25 @@
return this.builtInRegistryHolder;
}
@@ -42,12 +42,13 @@
}
+ return 0;
+ }
+
}
+ public int getExpDrop(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) {
+ return 0;
}
+ }
+ // CraftBukkit end
+
public static final class a {
private final IBlockData first;

View File

@@ -16,7 +16,8 @@
- boolean flag1 = world.hasNeighborSignal(blockposition) || world.hasNeighborSignal(blockposition.relative(iblockdata.getValue(BlockDoor.HALF) == BlockPropertyDoubleBlockHalf.LOWER ? EnumDirection.UP : EnumDirection.DOWN));
+ // CraftBukkit start
+ BlockPosition otherHalf = blockposition.relative(iblockdata.getValue(BlockDoor.HALF) == BlockPropertyDoubleBlockHalf.LOWER ? EnumDirection.UP : EnumDirection.DOWN);
+
- if (!this.defaultBlockState().is(block) && flag1 != (Boolean) iblockdata.getValue(BlockDoor.POWERED)) {
+ org.bukkit.World bworld = world.getWorld();
+ org.bukkit.block.Block bukkitBlock = bworld.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ org.bukkit.block.Block blockTop = bworld.getBlockAt(otherHalf.getX(), otherHalf.getY(), otherHalf.getZ());
@@ -29,8 +30,7 @@
+ if (oldPower == 0 ^ power == 0) {
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bukkitBlock, oldPower, power);
+ world.getCraftServer().getPluginManager().callEvent(eventRedstone);
- if (!this.defaultBlockState().is(block) && flag1 != (Boolean) iblockdata.getValue(BlockDoor.POWERED)) {
+
+ boolean flag1 = eventRedstone.getNewCurrent() > 0;
+ // CraftBukkit end
if (flag1 != (Boolean) iblockdata.getValue(BlockDoor.OPEN)) {

View File

@@ -28,7 +28,7 @@
@Nullable
static MobEffectList filterEffect(@Nullable MobEffectList mobeffectlist) {
@@ -245,39 +259,78 @@
@@ -245,38 +259,77 @@
super.setRemoved();
}
@@ -93,9 +93,9 @@
}
+ return false;
}
}
+ }
+ }
+
+ private static void applyEffects(World world, BlockPosition blockposition, int i, @Nullable MobEffectList mobeffectlist, @Nullable MobEffectList mobeffectlist1) {
+ if (!world.isClientSide && mobeffectlist != null) {
+ double d0 = (double) (i * 10 + 10);
@@ -109,14 +109,13 @@
+ if (hasSecondaryEffect(i, mobeffectlist, mobeffectlist1)) {
+ applyEffect(list, mobeffectlist1, j, 0);
+ }
+ }
}
+
+ }
}
+ // CraftBukkit end
+
public static void playSound(World world, BlockPosition blockposition, SoundEffect soundeffect) {
world.playSound((EntityHuman) null, blockposition, soundeffect, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
@@ -312,7 +365,7 @@
if (nbttagcompound.contains(s, 8)) {
MinecraftKey minecraftkey = MinecraftKey.tryParse(nbttagcompound.getString(s));

View File

@@ -124,8 +124,9 @@
ItemStack itemstack = (ItemStack) nonnulllist.get(3);
+ InventoryHolder owner = tileentitybrewingstand.getOwner();
+ List<org.bukkit.inventory.ItemStack> brewResults = new ArrayList<>(3);
+
+ for (int i = 0; i < 3; ++i) {
for (int i = 0; i < 3; ++i) {
- nonnulllist.set(i, PotionBrewer.mix(itemstack, (ItemStack) nonnulllist.get(i)));
+ brewResults.add(i, CraftItemStack.asCraftMirror(PotionBrewer.mix(itemstack, (ItemStack) nonnulllist.get(i))));
+ }
+
@@ -137,9 +138,8 @@
+ }
+ }
+ // CraftBukkit end
for (int i = 0; i < 3; ++i) {
- nonnulllist.set(i, PotionBrewer.mix(itemstack, (ItemStack) nonnulllist.get(i)));
+
+ for (int i = 0; i < 3; ++i) {
+ // CraftBukkit start - validate index in case it is cleared by plugins
+ if (i < brewResults.size()) {
+ nonnulllist.set(i, CraftItemStack.asNMSCopy(brewResults.get(i)));