diff --git a/docs/README.md b/docs/README.md
index 95932edc..0a5bffe1 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -1,15 +1,15 @@
-
Youer 1.21.1
+
Youer 1.21.2
The project is experimental, we are not available, and it is expected that it will not be released stably until after 1.21.2 or 1.22.
### Minecraft NeoForge Hybrid server implementing the Spigot/Bukkit API
-[![](https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fci.codemc.io%2Fjob%2FMohistMC%2Fjob%2FYouer-1.21.1)](https://ci.codemc.io/job/MohistMC/job/Youer-1.21.1)
+[![](https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fci.codemc.io%2Fjob%2FMohistMC%2Fjob%2FYouer-1.21.2)](https://ci.codemc.io/job/MohistMC/job/Youer-1.21.2)
[![](https://img.shields.io/github/stars/MohistMC/Mohist.svg?label=Stars&logo=github)](https://github.com/MohistMC/Mohist/stargazers)
-[![](https://img.shields.io/badge/NeoForge-21.1.4-brightgreen.svg?colorB=26303d)](https://neoforged.net/)
+[![](https://img.shields.io/badge/NeoForge-21.2.0-brightgreen.svg?colorB=26303d)](https://neoforged.net/)
[![](https://img.shields.io/badge/JDK-21.0.3-brightgreen.svg?colorB=469C00&logo=java)](https://www.azul.com/downloads/?version=java-21-lts#zulu)
-[![](https://img.shields.io/badge/Gradle-8.3-brightgreen.svg?colorB=469C00&logo=gradle)](https://docs.gradle.org/8.3/release-notes.html)
+[![](https://img.shields.io/badge/Gradle-8.10.2-brightgreen.svg?colorB=469C00&logo=gradle)](https://docs.gradle.org/8.10.2/release-notes.html)
[![](https://img.shields.io/bstats/servers/6762?label=bStats)](https://bstats.org/plugin/server-implementation/Mohist/6762)
[![](https://badges.crowdin.net/mohist/localized.svg)](https://crowdin.com/project/mohist)
[![](https://img.shields.io/discord/311256119005937665.svg?color=%237289da&label=Discord&logo=discord&logoColor=%237289da)](https://discord.gg/mohistmc)
@@ -21,7 +21,7 @@
Progress
------
-- [x] Rectify NeoForge([**bdda6d296d**](https://github.com/neoforged/NeoForge/commit/bdda6d296d))
+- [x] Rectify NeoForge([**91303b6970**](https://github.com/neoforged/NeoForge/commit/91303b6970))
- [ ] Start patch
* [x] Bukkit([**69fa4695**](https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/69fa4695))
* [ ] CraftBukkit([**661afb43c**](https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/commits/661afb43c))
diff --git a/gradle.properties b/gradle.properties
index dda819ee..79248906 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -9,15 +9,15 @@ org.gradle.debug=false
java_version=21
-minecraft_version=1.21.1
-neoform_version=20240808.144430
+minecraft_version=1.21.2
+neoform_version=20241022.151510
# on snapshot versions, used to prefix the version
-neoforge_snapshot_next_stable=22.0
+neoforge_snapshot_next_stable=21.3
mergetool_version=2.0.0
accesstransformers_version=10.0.1
coremods_version=6.0.4
-eventbus_version=8.0.1
+eventbus_version=8.0.2
modlauncher_version=11.0.4
securejarhandler_version=3.0.8
bootstraplauncher_version=2.0.2
@@ -25,13 +25,12 @@ asm_version=9.7
installer_version=2.1.+
mixin_version=0.15.2+mixin.0.8.7
terminalconsoleappender_version=1.3.0
-jline_version=3.12.+
nightconfig_version=3.8.0
jetbrains_annotations_version=24.0.1
slf4j_api_version=2.0.7
apache_maven_artifact_version=3.8.5
jarjar_version=0.4.1
-fancy_mod_loader_version=4.0.24
+fancy_mod_loader_version=4.0.29
mojang_logging_version=1.1.1
log4j_version=2.22.1
guava_version=31.1.2-jre
@@ -54,4 +53,5 @@ neogradle.subsystems.conventions.sourcesets.automatic-inclusion=false
neogradle.subsystems.conventions.enabled=false
neogradle.subsystems.tools.jst=net.neoforged.jst:jst-cli-bundle:1.0.45
+
neoforge_version=21.0.52-beta
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 0aaefbca..df97d72b 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
diff --git a/nms-patches/net/minecraft/CrashReport.patch b/nms-patches/net/minecraft/CrashReport.patch
new file mode 100644
index 00000000..0c5cb0b0
--- /dev/null
+++ b/nms-patches/net/minecraft/CrashReport.patch
@@ -0,0 +1,10 @@
+--- a/net/minecraft/CrashReport.java
++++ b/net/minecraft/CrashReport.java
+@@ -36,6 +36,7 @@
+ public CrashReport(String s, Throwable throwable) {
+ this.title = s;
+ this.exception = throwable;
++ this.systemReport.setDetail("CraftBukkit Information", new org.bukkit.craftbukkit.CraftCrashReport()); // CraftBukkit
+ }
+
+ public String getTitle() {
diff --git a/nms-patches/net/minecraft/advancements/AdvancementHolder.patch b/nms-patches/net/minecraft/advancements/AdvancementHolder.patch
new file mode 100644
index 00000000..1b57fcdb
--- /dev/null
+++ b/nms-patches/net/minecraft/advancements/AdvancementHolder.patch
@@ -0,0 +1,25 @@
+--- a/net/minecraft/advancements/AdvancementHolder.java
++++ b/net/minecraft/advancements/AdvancementHolder.java
+@@ -6,6 +6,11 @@
+ import net.minecraft.network.codec.StreamCodec;
+ import net.minecraft.resources.MinecraftKey;
+
++// CraftBukkit start
++import org.bukkit.craftbukkit.advancement.CraftAdvancement;
++import org.bukkit.craftbukkit.util.CraftNamespacedKey;
++// CraftBukkit end
++
+ public record AdvancementHolder(MinecraftKey id, Advancement value) {
+
+ public static final StreamCodec
STREAM_CODEC = StreamCodec.composite(MinecraftKey.STREAM_CODEC, AdvancementHolder::id, Advancement.STREAM_CODEC, AdvancementHolder::value, AdvancementHolder::new);
+@@ -38,4 +43,10 @@
+ public String toString() {
+ return this.id.toString();
+ }
++
++ // CraftBukkit start
++ public final org.bukkit.advancement.Advancement toBukkit() {
++ return new CraftAdvancement(this);
++ }
++ // CraftBukkit end
+ }
diff --git a/nms-patches/net/minecraft/advancements/AdvancementTree.patch b/nms-patches/net/minecraft/advancements/AdvancementTree.patch
new file mode 100644
index 00000000..a09551db
--- /dev/null
+++ b/nms-patches/net/minecraft/advancements/AdvancementTree.patch
@@ -0,0 +1,11 @@
+--- a/net/minecraft/advancements/AdvancementTree.java
++++ b/net/minecraft/advancements/AdvancementTree.java
+@@ -77,7 +77,7 @@
+ }
+ }
+
+- AdvancementTree.LOGGER.info("Loaded {} advancements", this.nodes.size());
++ // AdvancementTree.LOGGER.info("Loaded {} advancements", this.nodes.size()); // CraftBukkit - moved to AdvancementDataWorld#reload
+ }
+
+ private boolean tryInsert(AdvancementHolder advancementholder) {
diff --git a/nms-patches/net/minecraft/commands/CommandDispatcher.patch b/nms-patches/net/minecraft/commands/CommandDispatcher.patch
index ff91e67a..8f5612fb 100644
--- a/nms-patches/net/minecraft/commands/CommandDispatcher.patch
+++ b/nms-patches/net/minecraft/commands/CommandDispatcher.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/commands/CommandDispatcher.java
+++ b/net/minecraft/commands/CommandDispatcher.java
-@@ -135,6 +135,14 @@
+@@ -139,6 +139,14 @@
import net.minecraft.world.level.GameRules;
import org.slf4j.Logger;
@@ -15,7 +15,7 @@
public class CommandDispatcher {
private static final ThreadLocal> CURRENT_EXECUTION_CONTEXT = new ThreadLocal();
-@@ -147,6 +155,7 @@
+@@ -151,6 +159,7 @@
private final com.mojang.brigadier.CommandDispatcher dispatcher = new com.mojang.brigadier.CommandDispatcher();
public CommandDispatcher(CommandDispatcher.ServerType commanddispatcher_servertype, CommandBuildContext commandbuildcontext) {
@@ -23,7 +23,7 @@
CommandAdvancement.register(this.dispatcher);
CommandAttribute.register(this.dispatcher, commandbuildcontext);
CommandExecute.register(this.dispatcher, commandbuildcontext);
-@@ -247,6 +256,11 @@
+@@ -252,6 +261,11 @@
CommandPublish.register(this.dispatcher);
}
@@ -35,7 +35,7 @@
this.dispatcher.setConsumer(ExecutionCommandSource.resultConsumer());
}
-@@ -257,18 +271,65 @@
+@@ -262,18 +276,65 @@
return new ParseResults(commandcontextbuilder1, parseresults.getReader(), parseresults.getExceptions());
}
@@ -95,7 +95,7 @@
+ public void performCommand(ParseResults parseresults, String s, String label) { // CraftBukkit
CommandListenerWrapper commandlistenerwrapper = (CommandListenerWrapper) parseresults.getContext().getSource();
- commandlistenerwrapper.getServer().getProfiler().push(() -> {
+ Profiler.get().push(() -> {
return "/" + s;
});
- ContextChain contextchain = finishParsing(parseresults, s, commandlistenerwrapper);
@@ -103,7 +103,7 @@
try {
if (contextchain != null) {
-@@ -302,7 +363,7 @@
+@@ -307,7 +368,7 @@
}
@Nullable
@@ -112,7 +112,7 @@
try {
validateParseResults(parseresults);
return (ContextChain) ContextChain.tryFlatten(parseresults.getContext().build(s)).orElseThrow(() -> {
-@@ -313,7 +374,7 @@
+@@ -318,7 +379,7 @@
if (commandsyntaxexception.getInput() != null && commandsyntaxexception.getCursor() >= 0) {
int i = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor());
IChatMutableComponent ichatmutablecomponent = IChatBaseComponent.empty().withStyle(EnumChatFormat.GRAY).withStyle((chatmodifier) -> {
@@ -121,7 +121,7 @@
});
if (i > 10) {
-@@ -363,7 +424,7 @@
+@@ -368,7 +429,7 @@
executioncontext1.close();
} finally {
@@ -130,7 +130,7 @@
}
} else {
consumer.accept(executioncontext);
-@@ -372,11 +433,36 @@
+@@ -377,11 +438,36 @@
}
public void sendCommands(EntityPlayer entityplayer) {
@@ -168,7 +168,7 @@
entityplayer.connection.send(new PacketPlayOutCommands(rootcommandnode));
}
-@@ -387,7 +473,7 @@
+@@ -392,7 +478,7 @@
CommandNode commandnode2 = (CommandNode) iterator.next();
if (commandnode2.canUse(commandlistenerwrapper)) {
@@ -177,7 +177,7 @@
argumentbuilder.requires((icompletionprovider) -> {
return true;
-@@ -410,7 +496,7 @@
+@@ -415,7 +501,7 @@
argumentbuilder.redirect((CommandNode) map.get(argumentbuilder.getRedirect()));
}
@@ -186,7 +186,7 @@
map.put(commandnode2, commandnode3);
commandnode1.addChild(commandnode3);
-@@ -471,7 +557,7 @@
+@@ -481,7 +567,7 @@
}
private HolderLookup.b.a createLookup(final HolderLookup.b holderlookup_b) {
diff --git a/nms-patches/net/minecraft/commands/CommandListenerWrapper.patch b/nms-patches/net/minecraft/commands/CommandListenerWrapper.patch
index 092f48ad..940733b4 100644
--- a/nms-patches/net/minecraft/commands/CommandListenerWrapper.patch
+++ b/nms-patches/net/minecraft/commands/CommandListenerWrapper.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/commands/CommandListenerWrapper.java
+++ b/net/minecraft/commands/CommandListenerWrapper.java
-@@ -44,6 +44,8 @@
+@@ -46,6 +46,8 @@
import net.minecraft.world.phys.Vec2F;
import net.minecraft.world.phys.Vec3D;
@@ -9,7 +9,7 @@
public class CommandListenerWrapper implements ExecutionCommandSource, ICompletionProvider {
public static final SimpleCommandExceptionType ERROR_NOT_PLAYER = new SimpleCommandExceptionType(IChatBaseComponent.translatable("permissions.requires.player"));
-@@ -63,6 +65,7 @@
+@@ -65,6 +67,7 @@
private final Vec2F rotation;
private final CommandSigningContext signingContext;
private final TaskChainer chatMessageChainer;
@@ -17,7 +17,7 @@
public CommandListenerWrapper(ICommandListener icommandlistener, Vec3D vec3d, Vec2F vec2f, WorldServer worldserver, int i, String s, IChatBaseComponent ichatbasecomponent, MinecraftServer minecraftserver, @Nullable Entity entity) {
this(icommandlistener, vec3d, vec2f, worldserver, i, s, ichatbasecomponent, minecraftserver, entity, false, CommandResultCallback.EMPTY, ArgumentAnchor.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(minecraftserver));
-@@ -169,9 +172,23 @@
+@@ -171,9 +174,23 @@
@Override
public boolean hasPermission(int i) {
@@ -41,16 +41,16 @@
public Vec3D getPosition() {
return this.worldPosition;
}
-@@ -300,7 +317,7 @@
+@@ -302,7 +319,7 @@
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
-- if (entityplayer != this.source && this.server.getPlayerList().isOp(entityplayer.getGameProfile())) {
-+ if (entityplayer != this.source && entityplayer.getBukkitEntity().hasPermission("minecraft.admin.command_feedback")) { // CraftBukkit
+- if (entityplayer.commandSource() != this.source && this.server.getPlayerList().isOp(entityplayer.getGameProfile())) {
++ if (entityplayer.commandSource() != this.source && entityplayer.getBukkitEntity().hasPermission("minecraft.admin.command_feedback")) { // CraftBukkit
entityplayer.sendSystemMessage(ichatmutablecomponent);
}
}
-@@ -393,4 +410,10 @@
+@@ -400,4 +417,10 @@
public boolean isSilent() {
return this.silent;
}
diff --git a/nms-patches/net/minecraft/core/cauldron/CauldronInteraction.patch b/nms-patches/net/minecraft/core/cauldron/CauldronInteraction.patch
index 4e271a50..d9fb2ed9 100644
--- a/nms-patches/net/minecraft/core/cauldron/CauldronInteraction.patch
+++ b/nms-patches/net/minecraft/core/cauldron/CauldronInteraction.patch
@@ -1,8 +1,8 @@
--- a/net/minecraft/core/cauldron/CauldronInteraction.java
+++ b/net/minecraft/core/cauldron/CauldronInteraction.java
-@@ -34,9 +34,15 @@
- import net.minecraft.world.level.block.state.IBlockData;
+@@ -36,14 +36,20 @@
import net.minecraft.world.level.gameevent.GameEvent;
+ import net.minecraft.world.level.material.Fluid;
+// CraftBukkit start
+import org.bukkit.event.block.CauldronLevelChangeEvent;
@@ -11,27 +11,28 @@
public interface CauldronInteraction {
Map INTERACTIONS = new Object2ObjectArrayMap();
-+ // CraftBukkit start - decompile error
-+ /*
- Codec CODEC;
- CauldronInteraction.a EMPTY;
- CauldronInteraction.a WATER;
-@@ -48,6 +54,8 @@
- CauldronInteraction SHULKER_BOX;
- CauldronInteraction BANNER;
- CauldronInteraction DYED_ITEM;
-+ */
+- Codec CODEC;
+- CauldronInteraction.a EMPTY;
+- CauldronInteraction.a WATER;
+- CauldronInteraction.a LAVA;
+- CauldronInteraction.a POWDER_SNOW;
++ // CraftBukkit start - decompile errors
++ Codec CODEC = Codec.stringResolver(CauldronInteraction.a::name, CauldronInteraction.INTERACTIONS::get);
++ CauldronInteraction.a EMPTY = newInteractionMap("empty");
++ CauldronInteraction.a WATER = newInteractionMap("water");
++ CauldronInteraction.a LAVA = newInteractionMap("lava");
++ CauldronInteraction.a POWDER_SNOW = newInteractionMap("powder_snow");
+ // CraftBukkit end
static CauldronInteraction.a newInteractionMap(String s) {
Object2ObjectOpenHashMap- object2objectopenhashmap = new Object2ObjectOpenHashMap();
-@@ -72,12 +80,17 @@
+@@ -68,12 +74,17 @@
if (potioncontents != null && potioncontents.is(Potions.WATER)) {
if (!world.isClientSide) {
+ // CraftBukkit start
+ if (!LayeredCauldronBlock.changeLevel(iblockdata, world, blockposition, Blocks.WATER_CAULDRON.defaultBlockState(), entityhuman, CauldronLevelChangeEvent.ChangeReason.BOTTLE_EMPTY)) {
-+ return ItemInteractionResult.SUCCESS;
++ return EnumInteractionResult.SUCCESS;
+ }
+ // CraftBukkit end
Item item = itemstack.getItem();
@@ -44,13 +45,13 @@
world.playSound((EntityHuman) null, blockposition, SoundEffects.BOTTLE_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PLACE, blockposition);
}
-@@ -97,12 +110,17 @@
+@@ -93,12 +104,17 @@
});
map1.put(Items.GLASS_BOTTLE, (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> {
if (!world.isClientSide) {
+ // CraftBukkit start
+ if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.BOTTLE_FILL)) {
-+ return ItemInteractionResult.SUCCESS;
++ return EnumInteractionResult.SUCCESS;
+ }
+ // CraftBukkit end
Item item = itemstack.getItem();
@@ -63,13 +64,13 @@
world.playSound((EntityHuman) null, blockposition, SoundEffects.BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PICKUP, blockposition);
}
-@@ -117,10 +135,15 @@
+@@ -113,10 +129,15 @@
if (potioncontents != null && potioncontents.is(Potions.WATER)) {
if (!world.isClientSide) {
+ // CraftBukkit start
+ if (!LayeredCauldronBlock.changeLevel(iblockdata, world, blockposition, iblockdata.cycle(LayeredCauldronBlock.LEVEL), entityhuman, CauldronLevelChangeEvent.ChangeReason.BOTTLE_EMPTY)) {
-+ return ItemInteractionResult.SUCCESS;
++ return EnumInteractionResult.SUCCESS;
+ }
+ // CraftBukkit end
entityhuman.setItemInHand(enumhand, ItemLiquidUtil.createFilledResult(itemstack, entityhuman, new ItemStack(Items.GLASS_BOTTLE)));
@@ -80,13 +81,13 @@
world.playSound((EntityHuman) null, blockposition, SoundEffects.BOTTLE_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PLACE, blockposition);
}
-@@ -198,12 +221,17 @@
- return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
+@@ -194,12 +215,17 @@
+ return EnumInteractionResult.TRY_WITH_EMPTY_HAND;
} else {
if (!world.isClientSide) {
+ // CraftBukkit start
+ if (!LayeredCauldronBlock.changeLevel(iblockdata, world, blockposition, Blocks.CAULDRON.defaultBlockState(), entityhuman, CauldronLevelChangeEvent.ChangeReason.BUCKET_FILL)) {
-+ return ItemInteractionResult.SUCCESS;
++ return EnumInteractionResult.SUCCESS;
+ }
+ // CraftBukkit end
Item item = itemstack.getItem();
@@ -99,13 +100,13 @@
world.playSound((EntityHuman) null, blockposition, soundeffect, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PICKUP, blockposition);
}
-@@ -214,12 +242,17 @@
+@@ -210,12 +236,17 @@
- static ItemInteractionResult emptyBucket(World world, BlockPosition blockposition, EntityHuman entityhuman, EnumHand enumhand, ItemStack itemstack, IBlockData iblockdata, SoundEffect soundeffect) {
+ static EnumInteractionResult emptyBucket(World world, BlockPosition blockposition, EntityHuman entityhuman, EnumHand enumhand, ItemStack itemstack, IBlockData iblockdata, SoundEffect soundeffect) {
if (!world.isClientSide) {
+ // CraftBukkit start
+ if (!LayeredCauldronBlock.changeLevel(iblockdata, world, blockposition, iblockdata, entityhuman, CauldronLevelChangeEvent.ChangeReason.BUCKET_EMPTY)) {
-+ return ItemInteractionResult.SUCCESS;
++ return EnumInteractionResult.SUCCESS;
+ }
+ // CraftBukkit end
Item item = itemstack.getItem();
@@ -118,113 +119,74 @@
world.playSound((EntityHuman) null, blockposition, soundeffect, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PLACE, blockposition);
}
-@@ -227,76 +260,89 @@
- return ItemInteractionResult.sidedSuccess(world.isClientSide);
- }
-
-- static {
-- Function function = CauldronInteraction.a::name;
-- Map map = CauldronInteraction.INTERACTIONS;
--
-- Objects.requireNonNull(map);
-- CODEC = Codec.stringResolver(function, map::get);
-- EMPTY = newInteractionMap("empty");
-- WATER = newInteractionMap("water");
-- LAVA = newInteractionMap("lava");
-- POWDER_SNOW = newInteractionMap("powder_snow");
-- FILL_WATER = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> {
-+ // CraftBukkit start - decompile errors
-+ // static {
-+ Codec CODEC = Codec.stringResolver(CauldronInteraction.a::name, CauldronInteraction.INTERACTIONS::get);
-+ CauldronInteraction.a EMPTY = newInteractionMap("empty");
-+ CauldronInteraction.a WATER = newInteractionMap("water");
-+ CauldronInteraction.a LAVA = newInteractionMap("lava");
-+ CauldronInteraction.a POWDER_SNOW = newInteractionMap("powder_snow");
-+ CauldronInteraction FILL_WATER = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> {
- return emptyBucket(world, blockposition, entityhuman, enumhand, itemstack, (IBlockData) Blocks.WATER_CAULDRON.defaultBlockState().setValue(LayeredCauldronBlock.LEVEL, 3), SoundEffects.BUCKET_EMPTY);
- };
-- FILL_LAVA = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> {
-+ CauldronInteraction FILL_LAVA = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> {
- return emptyBucket(world, blockposition, entityhuman, enumhand, itemstack, Blocks.LAVA_CAULDRON.defaultBlockState(), SoundEffects.BUCKET_EMPTY_LAVA);
- };
-- FILL_POWDER_SNOW = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> {
-+ CauldronInteraction FILL_POWDER_SNOW = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> {
- return emptyBucket(world, blockposition, entityhuman, enumhand, itemstack, (IBlockData) Blocks.POWDER_SNOW_CAULDRON.defaultBlockState().setValue(LayeredCauldronBlock.LEVEL, 3), SoundEffects.BUCKET_EMPTY_POWDER_SNOW);
- };
-- SHULKER_BOX = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> {
-+ CauldronInteraction SHULKER_BOX = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> {
-+ // CraftBukkit end
- Block block = Block.byItem(itemstack.getItem());
-
- if (!(block instanceof BlockShulkerBox)) {
- return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
- } else {
- if (!world.isClientSide) {
-+ // CraftBukkit start
-+ if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.SHULKER_WASH)) {
-+ return ItemInteractionResult.SUCCESS;
-+ }
-+ // CraftBukkit end
- ItemStack itemstack1 = itemstack.transmuteCopy(Blocks.SHULKER_BOX, 1);
-
- entityhuman.setItemInHand(enumhand, ItemLiquidUtil.createFilledResult(itemstack, entityhuman, itemstack1, false));
- entityhuman.awardStat(StatisticList.CLEAN_SHULKER_BOX);
-- LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition);
-+ // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit
- }
+@@ -242,11 +273,16 @@
+ return EnumInteractionResult.TRY_WITH_EMPTY_HAND;
+ } else {
+ if (!world.isClientSide) {
++ // CraftBukkit start
++ if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.SHULKER_WASH)) {
++ return EnumInteractionResult.SUCCESS;
++ }
++ // CraftBukkit end
+ ItemStack itemstack1 = itemstack.transmuteCopy(Blocks.SHULKER_BOX, 1);
- return ItemInteractionResult.sidedSuccess(world.isClientSide);
+ entityhuman.setItemInHand(enumhand, ItemLiquidUtil.createFilledResult(itemstack, entityhuman, itemstack1, false));
+ entityhuman.awardStat(StatisticList.CLEAN_SHULKER_BOX);
+- LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition);
++ // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit
}
- };
-- BANNER = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> {
-+ CauldronInteraction BANNER = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { // CraftBukkit - decompile error
- BannerPatternLayers bannerpatternlayers = (BannerPatternLayers) itemstack.getOrDefault(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY);
-
- if (bannerpatternlayers.layers().isEmpty()) {
- return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
- } else {
- if (!world.isClientSide) {
-+ // CraftBukkit start
-+ if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.BANNER_WASH)) {
-+ return ItemInteractionResult.SUCCESS;
-+ }
-+ // CraftBukkit end
- ItemStack itemstack1 = itemstack.copyWithCount(1);
- itemstack1.set(DataComponents.BANNER_PATTERNS, bannerpatternlayers.removeLast());
- entityhuman.setItemInHand(enumhand, ItemLiquidUtil.createFilledResult(itemstack, entityhuman, itemstack1, false));
- entityhuman.awardStat(StatisticList.CLEAN_BANNER);
-- LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition);
-+ // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit
- }
+ return EnumInteractionResult.SUCCESS;
+@@ -260,12 +296,17 @@
+ return EnumInteractionResult.TRY_WITH_EMPTY_HAND;
+ } else {
+ if (!world.isClientSide) {
++ // CraftBukkit start
++ if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.BANNER_WASH)) {
++ return EnumInteractionResult.SUCCESS;
++ }
++ // CraftBukkit end
+ ItemStack itemstack1 = itemstack.copyWithCount(1);
- return ItemInteractionResult.sidedSuccess(world.isClientSide);
+ itemstack1.set(DataComponents.BANNER_PATTERNS, bannerpatternlayers.removeLast());
+ entityhuman.setItemInHand(enumhand, ItemLiquidUtil.createFilledResult(itemstack, entityhuman, itemstack1, false));
+ entityhuman.awardStat(StatisticList.CLEAN_BANNER);
+- LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition);
++ // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit
}
- };
-- DYED_ITEM = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> {
-+ CauldronInteraction DYED_ITEM = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { // CraftBukkit - decompile error
- if (!itemstack.is(TagsItem.DYEABLE)) {
- return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
- } else if (!itemstack.has(DataComponents.DYED_COLOR)) {
- return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
- } else {
- if (!world.isClientSide) {
-+ // CraftBukkit start
-+ if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.ARMOR_WASH)) {
-+ return ItemInteractionResult.SUCCESS;
-+ }
-+ // CraftBukkit end
- itemstack.remove(DataComponents.DYED_COLOR);
- entityhuman.awardStat(StatisticList.CLEAN_ARMOR);
-- LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition);
-+ // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit
- }
- return ItemInteractionResult.sidedSuccess(world.isClientSide);
+ return EnumInteractionResult.SUCCESS;
+@@ -279,9 +320,14 @@
+ return EnumInteractionResult.TRY_WITH_EMPTY_HAND;
+ } else {
+ if (!world.isClientSide) {
++ // CraftBukkit start
++ if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.ARMOR_WASH)) {
++ return EnumInteractionResult.SUCCESS;
++ }
++ // CraftBukkit end
+ itemstack.remove(DataComponents.DYED_COLOR);
+ entityhuman.awardStat(StatisticList.CLEAN_ARMOR);
+- LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition);
++ // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit
}
- };
-- }
-+ // } // CraftBukkit - decompile error
+
+ return EnumInteractionResult.SUCCESS;
+@@ -294,6 +340,8 @@
+ return fluid.is(TagsFluid.WATER);
+ }
+
++ // CraftBukkit start - decompile errors
++ /*
+ static {
+ Function function = CauldronInteraction.a::name;
+ Map map = CauldronInteraction.INTERACTIONS;
+@@ -305,6 +353,8 @@
+ LAVA = newInteractionMap("lava");
+ POWDER_SNOW = newInteractionMap("powder_snow");
+ }
++ */
++ // CraftBukkit end
public static record a(String name, Map
- map) {
diff --git a/nms-patches/net/minecraft/core/component/DataComponentPatch.patch b/nms-patches/net/minecraft/core/component/DataComponentPatch.patch
new file mode 100644
index 00000000..5e70217b
--- /dev/null
+++ b/nms-patches/net/minecraft/core/component/DataComponentPatch.patch
@@ -0,0 +1,63 @@
+--- a/net/minecraft/core/component/DataComponentPatch.java
++++ b/net/minecraft/core/component/DataComponentPatch.java
+@@ -61,7 +61,7 @@
+ }
+ }
+
+- return reference2objectmap;
++ return (Reference2ObjectMap) reference2objectmap; // CraftBukkit - decompile error
+ });
+ public static final StreamCodec STREAM_CODEC = new StreamCodec() {
+ public DataComponentPatch decode(RegistryFriendlyByteBuf registryfriendlybytebuf) {
+@@ -144,7 +144,7 @@
+ }
+
+ private static void encodeComponent(RegistryFriendlyByteBuf registryfriendlybytebuf, DataComponentType datacomponenttype, Object object) {
+- datacomponenttype.streamCodec().encode(registryfriendlybytebuf, object);
++ datacomponenttype.streamCodec().encode(registryfriendlybytebuf, (T) object); // CraftBukkit - decompile error
+ }
+ };
+ private static final String REMOVED_PREFIX = "!";
+@@ -271,6 +271,42 @@
+
+ a() {}
+
++ // CraftBukkit start
++ public void copy(DataComponentPatch orig) {
++ this.map.putAll(orig.map);
++ }
++
++ public void clear(DataComponentType> type) {
++ this.map.remove(type);
++ }
++
++ public boolean isSet(DataComponentType> type) {
++ return map.containsKey(type);
++ }
++
++ public boolean isEmpty() {
++ return this.map.isEmpty();
++ }
++
++ @Override
++ public boolean equals(Object object) {
++ if (this == object) {
++ return true;
++ }
++
++ if (object instanceof DataComponentPatch.a patch) {
++ return this.map.equals(patch.map);
++ }
++
++ return false;
++ }
++
++ @Override
++ public int hashCode() {
++ return this.map.hashCode();
++ }
++ // CraftBukkit end
++
+ public DataComponentPatch.a set(DataComponentType datacomponenttype, T t0) {
+ this.map.put(datacomponenttype, Optional.of(t0));
+ return this;
diff --git a/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorBoat.patch b/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorBoat.patch
index e0360bdb..9bef9068 100644
--- a/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorBoat.patch
+++ b/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorBoat.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/core/dispenser/DispenseBehaviorBoat.java
+++ b/net/minecraft/core/dispenser/DispenseBehaviorBoat.java
-@@ -13,6 +13,12 @@
+@@ -12,6 +12,12 @@
import net.minecraft.world.level.block.BlockDispenser;
import net.minecraft.world.phys.Vec3D;
@@ -12,13 +12,11 @@
+
public class DispenseBehaviorBoat extends DispenseBehaviorItem {
- private final DispenseBehaviorItem defaultDispenseItemBehavior;
-@@ -51,13 +57,41 @@
+ private final DispenseBehaviorItem defaultDispenseItemBehavior = new DispenseBehaviorItem();
+@@ -43,14 +49,40 @@
d4 = 0.0D;
}
-- Object object = this.isChestBoat ? new ChestBoat(worldserver, d1, d2 + d4, d3) : new EntityBoat(worldserver, d1, d2 + d4, d3);
-+ // Object object = this.isChestBoat ? new ChestBoat(worldserver, d1, d2 + d4, d3) : new EntityBoat(worldserver, d1, d2 + d4, d3);
+ // CraftBukkit start
+ ItemStack itemstack1 = itemstack.split(1);
+ org.bukkit.block.Block block = CraftBlock.at(worldserver, sourceblock.pos());
@@ -44,17 +42,18 @@
+ return itemstack;
+ }
+ }
-+
-+ EntityBoat object = this.isChestBoat ? new ChestBoat(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ()) : new EntityBoat(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ());
+ // CraftBukkit end
+ AbstractBoat abstractboat = (AbstractBoat) this.type.create(worldserver, EntitySpawnReason.DISPENSER);
- EntityTypes.createDefaultStackConfig(worldserver, itemstack, (EntityHuman) null).accept(object);
- ((EntityBoat) object).setVariant(this.type);
- ((EntityBoat) object).setYRot(enumdirection.toYRot());
-- worldserver.addFreshEntity((Entity) object);
-- itemstack.shrink(1);
-+ if (!worldserver.addFreshEntity((Entity) object)) itemstack.grow(1); // CraftBukkit
-+ // itemstack.shrink(1); // CraftBukkit - handled during event processing
- return itemstack;
- }
+ if (abstractboat != null) {
+- abstractboat.setInitialPos(d1, d2 + d4, d3);
++ abstractboat.setInitialPos(event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ()); // CraftBukkit
+ EntityTypes.createDefaultStackConfig(worldserver, itemstack, (EntityHuman) null).accept(abstractboat);
+ abstractboat.setYRot(enumdirection.toYRot());
+- worldserver.addFreshEntity(abstractboat);
+- itemstack.shrink(1);
++ if (!worldserver.addFreshEntity(abstractboat)) itemstack.grow(1); // CraftBukkit
++ // itemstack.shrink(1); // CraftBukkit - handled during event processing
+ }
+ return itemstack;
diff --git a/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorProjectile.patch b/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorProjectile.patch
index cad1f786..17073b18 100644
--- a/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorProjectile.patch
+++ b/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorProjectile.patch
@@ -14,11 +14,12 @@
public class DispenseBehaviorProjectile extends DispenseBehaviorItem {
private final ProjectileItem projectileItem;
-@@ -32,9 +39,38 @@
+@@ -31,8 +38,37 @@
+ EnumDirection enumdirection = (EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING);
IPosition iposition = this.dispenseConfig.positionFunction().getDispensePosition(sourceblock, enumdirection);
- IProjectile iprojectile = this.projectileItem.asProjectile(worldserver, iposition, itemstack, enumdirection);
-- this.projectileItem.shoot(iprojectile, (double) enumdirection.getStepX(), (double) enumdirection.getStepY(), (double) enumdirection.getStepZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty());
+- IProjectile.spawnProjectileUsingShoot(this.projectileItem.asProjectile(worldserver, iposition, itemstack, enumdirection), worldserver, itemstack, (double) enumdirection.getStepX(), (double) enumdirection.getStepY(), (double) enumdirection.getStepZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty());
+- itemstack.shrink(1);
+ // CraftBukkit start
+ // this.projectileItem.shoot(iprojectile, (double) enumdirection.getStepX(), (double) enumdirection.getStepY(), (double) enumdirection.getStepZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty());
+ ItemStack itemstack1 = itemstack.split(1);
@@ -46,12 +47,10 @@
+ }
+ }
+
-+ this.projectileItem.shoot(iprojectile, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty());
++ IProjectile iprojectile = IProjectile.spawnProjectileUsingShoot(this.projectileItem.asProjectile(worldserver, iposition, itemstack, enumdirection), worldserver, itemstack, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty());
+ ((Entity) iprojectile).projectileSource = new org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource(sourceblock.blockEntity());
-+ // CraftBukkit end
- worldserver.addFreshEntity(iprojectile);
-- itemstack.shrink(1);
+ // itemstack.shrink(1); // CraftBukkit - Handled during event processing
++ // CraftBukkit end
return itemstack;
}
diff --git a/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorShears.patch b/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorShears.patch
index ff8376c9..6e092687 100644
--- a/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorShears.patch
+++ b/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorShears.patch
@@ -45,8 +45,8 @@
if (!worldserver.isClientSide()) {
BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING));
-- this.setSuccess(tryShearBeehive(worldserver, blockposition) || tryShearLivingEntity(worldserver, blockposition));
-+ this.setSuccess(tryShearBeehive(worldserver, blockposition) || tryShearLivingEntity(worldserver, blockposition, bukkitBlock, craftItem)); // CraftBukkit
+- this.setSuccess(tryShearBeehive(worldserver, blockposition) || tryShearLivingEntity(worldserver, blockposition, itemstack));
++ this.setSuccess(tryShearBeehive(worldserver, blockposition) || tryShearLivingEntity(worldserver, blockposition, itemstack, bukkitBlock, craftItem)); // CraftBukkit
if (this.isSuccess()) {
itemstack.hurtAndBreak(1, worldserver, (EntityPlayer) null, (item) -> {
});
@@ -54,8 +54,8 @@
return false;
}
-- private static boolean tryShearLivingEntity(WorldServer worldserver, BlockPosition blockposition) {
-+ private static boolean tryShearLivingEntity(WorldServer worldserver, BlockPosition blockposition, org.bukkit.block.Block bukkitBlock, CraftItemStack craftItem) { // CraftBukkit - add args
+- private static boolean tryShearLivingEntity(WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack) {
++ private static boolean tryShearLivingEntity(WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, org.bukkit.block.Block bukkitBlock, CraftItemStack craftItem) { // CraftBukkit - add args
List list = worldserver.getEntitiesOfClass(EntityLiving.class, new AxisAlignedBB(blockposition), IEntitySelector.NO_SPECTATORS);
Iterator iterator = list.iterator();
@@ -68,6 +68,6 @@
+ continue;
+ }
+ // CraftBukkit end
- ishearable.shear(SoundCategory.BLOCKS);
+ ishearable.shear(worldserver, SoundCategory.BLOCKS, itemstack);
worldserver.gameEvent((Entity) null, (Holder) GameEvent.SHEAR, blockposition);
return true;
diff --git a/nms-patches/net/minecraft/world/item/ItemArmor.patch b/nms-patches/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.patch
similarity index 77%
rename from nms-patches/net/minecraft/world/item/ItemArmor.patch
rename to nms-patches/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.patch
index 1c25dc58..4052a9e3 100644
--- a/nms-patches/net/minecraft/world/item/ItemArmor.patch
+++ b/nms-patches/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.patch
@@ -1,28 +1,29 @@
---- a/net/minecraft/world/item/ItemArmor.java
-+++ b/net/minecraft/world/item/ItemArmor.java
-@@ -29,6 +29,12 @@
+--- a/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.java
++++ b/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.java
+@@ -10,6 +10,13 @@
import net.minecraft.world.level.block.BlockDispenser;
import net.minecraft.world.phys.AxisAlignedBB;
+// CraftBukkit start
++import net.minecraft.world.level.World;
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.block.BlockDispenseArmorEvent;
+// CraftBukkit end
+
- public class ItemArmor extends Item implements Equipable {
+ public class EquipmentDispenseItemBehavior extends DispenseBehaviorItem {
- public static final IDispenseBehavior DISPENSE_ITEM_BEHAVIOR = new DispenseBehaviorItem() {
-@@ -51,8 +57,34 @@
- EntityLiving entityliving = (EntityLiving) list.get(0);
+ public static final EquipmentDispenseItemBehavior INSTANCE = new EquipmentDispenseItemBehavior();
+@@ -34,7 +41,34 @@
EnumItemSlot enumitemslot = entityliving.getEquipmentSlotForItem(itemstack);
ItemStack itemstack1 = itemstack.split(1);
+
+- entityliving.setItemSlot(enumitemslot, itemstack1);
+ // CraftBukkit start
+ 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);
@@ -38,7 +39,7 @@
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
-+ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != ItemArmor.DISPENSE_ITEM_BEHAVIOR) {
++ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != EquipmentDispenseItemBehavior.INSTANCE) {
+ idispensebehavior.dispense(sourceblock, eventStack);
+ return true;
+ }
@@ -47,5 +48,5 @@
+ entityliving.setItemSlot(enumitemslot, CraftItemStack.asNMSCopy(event.getItem()));
+ // CraftBukkit end
if (entityliving instanceof EntityInsentient) {
- ((EntityInsentient) entityliving).setDropChance(enumitemslot, 2.0F);
- ((EntityInsentient) entityliving).setPersistenceRequired();
+ EntityInsentient entityinsentient = (EntityInsentient) entityliving;
+
diff --git a/nms-patches/net/minecraft/core/dispenser/IDispenseBehavior.patch b/nms-patches/net/minecraft/core/dispenser/IDispenseBehavior.patch
index 054da80d..502a05bc 100644
--- a/nms-patches/net/minecraft/core/dispenser/IDispenseBehavior.patch
+++ b/nms-patches/net/minecraft/core/dispenser/IDispenseBehavior.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/core/dispenser/IDispenseBehavior.java
+++ b/net/minecraft/core/dispenser/IDispenseBehavior.java
-@@ -67,6 +67,22 @@
+@@ -63,6 +63,22 @@
import net.minecraft.world.phys.MovingObjectPositionBlock;
import org.slf4j.Logger;
@@ -23,7 +23,7 @@
public interface IDispenseBehavior {
Logger LOGGER = LogUtils.getLogger();
-@@ -94,14 +110,42 @@
+@@ -90,14 +106,42 @@
EnumDirection enumdirection = (EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING);
EntityTypes> entitytypes = ((ItemMonsterEgg) itemstack.getItem()).getType(itemstack);
@@ -55,7 +55,7 @@
+ }
+
try {
- entitytypes.spawn(sourceblock.level(), itemstack, (EntityHuman) null, sourceblock.pos().relative(enumdirection), EnumMobSpawn.DISPENSER, enumdirection != EnumDirection.UP, false);
+ entitytypes.spawn(sourceblock.level(), itemstack, (EntityHuman) null, sourceblock.pos().relative(enumdirection), EntitySpawnReason.DISPENSER, enumdirection != EnumDirection.UP, false);
} catch (Exception exception) {
- null.LOGGER.error("Error while dispensing spawn egg from dispenser at {}", sourceblock.pos(), exception);
+ LOGGER.error("Error while dispensing spawn egg from dispenser at {}", sourceblock.pos(), exception); // CraftBukkit - decompile error
@@ -68,7 +68,7 @@
sourceblock.level().gameEvent((Entity) null, (Holder) GameEvent.ENTITY_PLACE, sourceblock.pos());
return itemstack;
}
-@@ -120,13 +164,41 @@
+@@ -116,13 +160,41 @@
EnumDirection enumdirection = (EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING);
BlockPosition blockposition = sourceblock.pos().relative(enumdirection);
WorldServer worldserver = sourceblock.level();
@@ -103,7 +103,7 @@
Consumer consumer = EntityTypes.appendDefaultStackConfig((entityarmorstand) -> {
entityarmorstand.setYRot(enumdirection.toYRot());
}, worldserver, itemstack, (EntityHuman) null);
- EntityArmorStand entityarmorstand = (EntityArmorStand) EntityTypes.ARMOR_STAND.spawn(worldserver, consumer, blockposition, EnumMobSpawn.DISPENSER, false, false);
+ EntityArmorStand entityarmorstand = (EntityArmorStand) EntityTypes.ARMOR_STAND.spawn(worldserver, consumer, blockposition, EntitySpawnReason.DISPENSER, false, false);
if (entityarmorstand != null) {
- itemstack.shrink(1);
@@ -111,7 +111,7 @@
}
return itemstack;
-@@ -145,7 +217,34 @@
+@@ -141,7 +213,34 @@
});
if (!list.isEmpty()) {
@@ -137,7 +137,7 @@
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
-+ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != ItemArmor.DISPENSE_ITEM_BEHAVIOR) {
++ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != EquipmentDispenseItemBehavior.INSTANCE) {
+ idispensebehavior.dispense(sourceblock, eventStack);
+ return itemstack;
+ }
@@ -147,44 +147,7 @@
this.setSuccess(true);
return itemstack;
} else {
-@@ -172,7 +271,35 @@
- entityhorseabstract = (EntityHorseAbstract) iterator1.next();
- } while (!entityhorseabstract.isBodyArmorItem(itemstack) || entityhorseabstract.isWearingBodyArmor() || !entityhorseabstract.isTamed());
-
-- entityhorseabstract.setBodyArmorItem(itemstack.split(1));
-+ // CraftBukkit start
-+ ItemStack itemstack1 = itemstack.split(1);
-+ WorldServer world = sourceblock.level();
-+ org.bukkit.block.Block block = CraftBlock.at(world, sourceblock.pos());
-+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
-+
-+ BlockDispenseArmorEvent event = new BlockDispenseArmorEvent(block, craftItem.clone(), (org.bukkit.craftbukkit.entity.CraftLivingEntity) entityhorseabstract.getBukkitEntity());
-+ if (!BlockDispenser.eventFired) {
-+ world.getCraftServer().getPluginManager().callEvent(event);
-+ }
-+
-+ if (event.isCancelled()) {
-+ itemstack.grow(1);
-+ return itemstack;
-+ }
-+
-+ if (!event.getItem().equals(craftItem)) {
-+ itemstack.grow(1);
-+ // Chain to handler for new item
-+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
-+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
-+ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != ItemArmor.DISPENSE_ITEM_BEHAVIOR) {
-+ idispensebehavior.dispense(sourceblock, eventStack);
-+ return itemstack;
-+ }
-+ }
-+
-+ entityhorseabstract.setBodyArmorItem(CraftItemStack.asNMSCopy(event.getItem()));
-+ // CraftBukkit end
- this.setSuccess(true);
- return itemstack;
- }
-@@ -215,9 +342,35 @@
+@@ -166,9 +265,35 @@
}
entityhorsechestedabstract = (EntityHorseChestedAbstract) iterator1.next();
@@ -210,7 +173,7 @@
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
-+ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != ItemArmor.DISPENSE_ITEM_BEHAVIOR) {
++ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != EquipmentDispenseItemBehavior.INSTANCE) {
+ idispensebehavior.dispense(sourceblock, eventStack);
+ return itemstack;
+ }
@@ -222,7 +185,7 @@
this.setSuccess(true);
return itemstack;
}
-@@ -249,6 +402,38 @@
+@@ -202,6 +327,38 @@
BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING));
WorldServer worldserver = sourceblock.level();
@@ -261,7 +224,7 @@
if (dispensiblecontaineritem.emptyContents((EntityHuman) null, worldserver, blockposition, (MovingObjectPositionBlock) null)) {
dispensiblecontaineritem.checkExtraContent((EntityHuman) null, worldserver, itemstack, blockposition);
return this.consumeWithRemainder(sourceblock, itemstack, new ItemStack(Items.BUCKET));
-@@ -276,7 +461,7 @@
+@@ -229,7 +386,7 @@
Block block = iblockdata.getBlock();
if (block instanceof IFluidSource ifluidsource) {
@@ -270,7 +233,7 @@
if (itemstack1.isEmpty()) {
return super.execute(sourceblock, itemstack);
-@@ -284,6 +469,32 @@
+@@ -237,6 +394,32 @@
worldserver.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PICKUP, blockposition);
Item item = itemstack1.getItem();
@@ -303,7 +266,7 @@
return this.consumeWithRemainder(sourceblock, itemstack, new ItemStack(item));
}
} else {
-@@ -296,16 +507,44 @@
+@@ -249,16 +432,44 @@
protected ItemStack execute(SourceBlock sourceblock, ItemStack itemstack) {
WorldServer worldserver = sourceblock.level();
@@ -351,7 +314,7 @@
BlockTNT.explode(worldserver, blockposition);
worldserver.removeBlock(blockposition, false);
} else {
-@@ -330,12 +569,62 @@
+@@ -283,12 +494,62 @@
this.setSuccess(true);
WorldServer worldserver = sourceblock.level();
BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING));
@@ -414,7 +377,7 @@
return itemstack;
}
-@@ -345,12 +634,41 @@
+@@ -298,12 +559,41 @@
protected ItemStack execute(SourceBlock sourceblock, ItemStack itemstack) {
WorldServer worldserver = sourceblock.level();
BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING));
@@ -458,7 +421,7 @@
return itemstack;
}
});
-@@ -375,6 +693,30 @@
+@@ -314,6 +604,30 @@
EnumDirection enumdirection = (EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING);
BlockPosition blockposition = sourceblock.pos().relative(enumdirection);
@@ -489,7 +452,7 @@
if (worldserver.isEmptyBlock(blockposition) && BlockWitherSkull.canSpawnMob(worldserver, blockposition, itemstack)) {
worldserver.setBlock(blockposition, (IBlockData) Blocks.WITHER_SKELETON_SKULL.defaultBlockState().setValue(BlockSkull.ROTATION, RotationSegment.convertToSegment(enumdirection)), 3);
worldserver.gameEvent((Entity) null, (Holder) GameEvent.BLOCK_PLACE, blockposition);
-@@ -400,6 +742,30 @@
+@@ -339,6 +653,30 @@
BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING));
BlockPumpkinCarved blockpumpkincarved = (BlockPumpkinCarved) Blocks.CARVED_PUMPKIN;
@@ -520,7 +483,7 @@
if (worldserver.isEmptyBlock(blockposition) && blockpumpkincarved.canSpawnGolem(worldserver, blockposition)) {
if (!worldserver.isClientSide) {
worldserver.setBlock(blockposition, blockpumpkincarved.defaultBlockState(), 3);
-@@ -438,6 +804,30 @@
+@@ -377,6 +715,30 @@
BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING));
IBlockData iblockdata = worldserver.getBlockState(blockposition);
@@ -551,7 +514,7 @@
if (iblockdata.is(TagsBlock.BEEHIVES, (blockbase_blockdata) -> {
return blockbase_blockdata.hasProperty(BlockBeehive.HONEY_LEVEL) && blockbase_blockdata.getBlock() instanceof BlockBeehive;
}) && (Integer) iblockdata.getValue(BlockBeehive.HONEY_LEVEL) >= 5) {
-@@ -487,6 +877,31 @@
+@@ -426,6 +788,31 @@
this.setSuccess(false);
return itemstack;
} else {
@@ -574,7 +537,7 @@
+ // Chain to handler for new item
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
-+ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != ItemArmor.DISPENSE_ITEM_BEHAVIOR) {
++ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != EquipmentDispenseItemBehavior.INSTANCE) {
+ idispensebehavior.dispense(sourceblock, eventStack);
+ return itemstack;
+ }
diff --git a/nms-patches/net/minecraft/core/dispenser/MinecartDispenseItemBehavior.patch b/nms-patches/net/minecraft/core/dispenser/MinecartDispenseItemBehavior.patch
new file mode 100644
index 00000000..5ea81d2e
--- /dev/null
+++ b/nms-patches/net/minecraft/core/dispenser/MinecartDispenseItemBehavior.patch
@@ -0,0 +1,59 @@
+--- a/net/minecraft/core/dispenser/MinecartDispenseItemBehavior.java
++++ b/net/minecraft/core/dispenser/MinecartDispenseItemBehavior.java
+@@ -16,6 +16,12 @@
+ import net.minecraft.world.level.block.state.properties.BlockPropertyTrackPosition;
+ import net.minecraft.world.phys.Vec3D;
+
++// CraftBukkit start
++import org.bukkit.craftbukkit.block.CraftBlock;
++import org.bukkit.craftbukkit.inventory.CraftItemStack;
++import org.bukkit.event.block.BlockDispenseEvent;
++// CraftBukkit end
++
+ public class MinecartDispenseItemBehavior extends DispenseBehaviorItem {
+
+ private final DispenseBehaviorItem defaultDispenseItemBehavior = new DispenseBehaviorItem();
+@@ -62,11 +68,40 @@
+ }
+
+ Vec3D vec3d1 = new Vec3D(d0, d1 + d3, d2);
+- EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, vec3d1.x, vec3d1.y, vec3d1.z, this.entityType, EntitySpawnReason.DISPENSER, itemstack, (EntityHuman) null);
++ // CraftBukkit start
++ // EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, vec3d1.x, vec3d1.y, vec3d1.z, this.entityType, EntitySpawnReason.DISPENSER, itemstack, (EntityHuman) null);
++ ItemStack itemstack1 = itemstack.split(1);
++ org.bukkit.block.Block block2 = CraftBlock.at(worldserver, sourceblock.pos());
++ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
++
++ BlockDispenseEvent event = new BlockDispenseEvent(block2, craftItem.clone(), new org.bukkit.util.Vector(vec3d1.x, vec3d1.y, vec3d1.z));
++ if (!BlockDispenser.eventFired) {
++ worldserver.getCraftServer().getPluginManager().callEvent(event);
++ }
++
++ if (event.isCancelled()) {
++ itemstack.grow(1);
++ return itemstack;
++ }
++
++ if (!event.getItem().equals(craftItem)) {
++ itemstack.grow(1);
++ // Chain to handler for new item
++ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
++ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
++ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) {
++ idispensebehavior.dispense(sourceblock, eventStack);
++ return itemstack;
++ }
++ }
++
++ itemstack1 = CraftItemStack.asNMSCopy(event.getItem());
++ EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), this.entityType, EntitySpawnReason.DISPENSER, itemstack1, (EntityHuman) null);
+
+ if (entityminecartabstract != null) {
+- worldserver.addFreshEntity(entityminecartabstract);
+- itemstack.shrink(1);
++ if (!worldserver.addFreshEntity(entityminecartabstract)) itemstack.grow(1);
++ // itemstack.shrink(1); // CraftBukkit - handled during event processing
++ // CraftBukkit end
+ }
+
+ return itemstack;
diff --git a/nms-patches/net/minecraft/nbt/NBTCompressedStreamTools.patch b/nms-patches/net/minecraft/nbt/NBTCompressedStreamTools.patch
new file mode 100644
index 00000000..e7fb3c79
--- /dev/null
+++ b/nms-patches/net/minecraft/nbt/NBTCompressedStreamTools.patch
@@ -0,0 +1,7 @@
+--- a/net/minecraft/nbt/NBTCompressedStreamTools.java
++++ b/net/minecraft/nbt/NBTCompressedStreamTools.java
+@@ -1,3 +1,4 @@
++// mc-dev import
+ package net.minecraft.nbt;
+
+ import java.io.BufferedOutputStream;
diff --git a/nms-patches/net/minecraft/nbt/NBTTagByteArray.patch b/nms-patches/net/minecraft/nbt/NBTTagByteArray.patch
new file mode 100644
index 00000000..1bd3e4da
--- /dev/null
+++ b/nms-patches/net/minecraft/nbt/NBTTagByteArray.patch
@@ -0,0 +1,7 @@
+--- a/net/minecraft/nbt/NBTTagByteArray.java
++++ b/net/minecraft/nbt/NBTTagByteArray.java
+@@ -1,3 +1,4 @@
++// mc-dev import
+ package net.minecraft.nbt;
+
+ import java.io.DataInput;
diff --git a/nms-patches/net/minecraft/nbt/NBTTagIntArray.patch b/nms-patches/net/minecraft/nbt/NBTTagIntArray.patch
new file mode 100644
index 00000000..d62cce3d
--- /dev/null
+++ b/nms-patches/net/minecraft/nbt/NBTTagIntArray.patch
@@ -0,0 +1,7 @@
+--- a/net/minecraft/nbt/NBTTagIntArray.java
++++ b/net/minecraft/nbt/NBTTagIntArray.java
+@@ -1,3 +1,4 @@
++// mc-dev import
+ package net.minecraft.nbt;
+
+ import java.io.DataInput;
diff --git a/nms-patches/net/minecraft/network/PacketDataSerializer.patch b/nms-patches/net/minecraft/network/PacketDataSerializer.patch
index 37573090..459f0978 100644
--- a/nms-patches/net/minecraft/network/PacketDataSerializer.patch
+++ b/nms-patches/net/minecraft/network/PacketDataSerializer.patch
@@ -51,7 +51,7 @@
BitSet bitset = this.readFixedBitSet(ae.length);
EnumSet enumset = EnumSet.noneOf(oclass);
-@@ -482,7 +482,7 @@
+@@ -498,7 +498,7 @@
}
public > T readEnum(Class oclass) {
@@ -60,7 +60,7 @@
}
public PacketDataSerializer writeEnum(Enum> oenum) {
-@@ -549,7 +549,7 @@
+@@ -565,7 +565,7 @@
try {
NBTCompressedStreamTools.writeAnyTag((NBTBase) nbtbase, new ByteBufOutputStream(bytebuf));
diff --git a/nms-patches/net/minecraft/network/chat/IChatBaseComponent.patch b/nms-patches/net/minecraft/network/chat/IChatBaseComponent.patch
index 95c8733e..783abb4d 100644
--- a/nms-patches/net/minecraft/network/chat/IChatBaseComponent.patch
+++ b/nms-patches/net/minecraft/network/chat/IChatBaseComponent.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/network/chat/IChatBaseComponent.java
+++ b/net/minecraft/network/chat/IChatBaseComponent.java
-@@ -36,7 +36,22 @@
+@@ -38,7 +38,22 @@
import net.minecraft.util.FormattedString;
import net.minecraft.world.level.ChunkCoordIntPair;
diff --git a/nms-patches/net/minecraft/server/AdvancementDataPlayer.patch b/nms-patches/net/minecraft/server/AdvancementDataPlayer.patch
index 87812ef5..ef25110a 100644
--- a/nms-patches/net/minecraft/server/AdvancementDataPlayer.patch
+++ b/nms-patches/net/minecraft/server/AdvancementDataPlayer.patch
@@ -15,4 +15,4 @@
+ this.player.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.player.PlayerAdvancementDoneEvent(this.player.getBukkitEntity(), advancementholder.toBukkit())); // CraftBukkit
advancementholder.value().rewards().grant(this.player);
advancementholder.value().display().ifPresent((advancementdisplay) -> {
- if (advancementdisplay.shouldAnnounceChat() && this.player.level().getGameRules().getBoolean(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)) {
+ if (advancementdisplay.shouldAnnounceChat() && this.player.serverLevel().getGameRules().getBoolean(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)) {
diff --git a/nms-patches/net/minecraft/server/AdvancementDataWorld.patch b/nms-patches/net/minecraft/server/AdvancementDataWorld.patch
index be95a05a..258a729f 100644
--- a/nms-patches/net/minecraft/server/AdvancementDataWorld.patch
+++ b/nms-patches/net/minecraft/server/AdvancementDataWorld.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/AdvancementDataWorld.java
+++ b/net/minecraft/server/AdvancementDataWorld.java
-@@ -27,11 +27,15 @@
+@@ -21,10 +21,14 @@
import net.minecraft.util.profiling.GameProfilerFiller;
import org.slf4j.Logger;
@@ -8,18 +8,17 @@
+import java.util.HashMap;
+// CraftBukkit end
+
- public class AdvancementDataWorld extends ResourceDataJson {
+ public class AdvancementDataWorld extends ResourceDataJson {
private static final Logger LOGGER = LogUtils.getLogger();
- public static final Gson GSON = (new GsonBuilder()).create();
- public Map advancements = Map.of();
+ public Map advancements = new HashMap<>(); // CraftBukkit - SPIGOT-7734: mutable
private AdvancementTree tree = new AdvancementTree();
private final HolderLookup.a registries;
-@@ -55,7 +59,7 @@
- }
-
+@@ -40,7 +44,7 @@
+ this.validate(minecraftkey, advancement);
+ builder.put(minecraftkey, new AdvancementHolder(minecraftkey, advancement));
});
- this.advancements = builder.buildOrThrow();
+ this.advancements = new HashMap<>(builder.buildOrThrow()); // CraftBukkit - SPIGOT-7734: mutable
diff --git a/nms-patches/net/minecraft/server/CustomFunctionData.patch b/nms-patches/net/minecraft/server/CustomFunctionData.patch
index 21f7645c..419c9c3e 100644
--- a/nms-patches/net/minecraft/server/CustomFunctionData.patch
+++ b/nms-patches/net/minecraft/server/CustomFunctionData.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/CustomFunctionData.java
+++ b/net/minecraft/server/CustomFunctionData.java
-@@ -36,7 +36,7 @@
+@@ -37,7 +37,7 @@
}
public CommandDispatcher getDispatcher() {
diff --git a/nms-patches/net/minecraft/server/DispenserRegistry.patch b/nms-patches/net/minecraft/server/DispenserRegistry.patch
index 723d6d05..5d9a0815 100644
--- a/nms-patches/net/minecraft/server/DispenserRegistry.patch
+++ b/nms-patches/net/minecraft/server/DispenserRegistry.patch
@@ -1,7 +1,7 @@
--- a/net/minecraft/server/DispenserRegistry.java
+++ b/net/minecraft/server/DispenserRegistry.java
-@@ -28,6 +28,12 @@
- import net.minecraft.world.level.block.BlockFire;
+@@ -29,6 +29,12 @@
+ import net.minecraft.world.level.block.state.BlockBase;
import org.slf4j.Logger;
+// CraftBukkit start
@@ -13,7 +13,7 @@
public class DispenserRegistry {
public static final PrintStream STDOUT = System.out;
-@@ -39,6 +45,23 @@
+@@ -40,6 +46,23 @@
public static void bootStrap() {
if (!DispenserRegistry.isBootstrapped) {
@@ -37,7 +37,7 @@
DispenserRegistry.isBootstrapped = true;
Instant instant = Instant.now();
-@@ -58,6 +81,69 @@
+@@ -59,6 +82,69 @@
wrapStreams();
DispenserRegistry.bootstrapDuration.set(Duration.between(instant, Instant.now()).toMillis());
}
diff --git a/nms-patches/net/minecraft/server/Main.patch b/nms-patches/net/minecraft/server/Main.patch
index 01bf23ca..43088e1c 100644
--- a/nms-patches/net/minecraft/server/Main.patch
+++ b/nms-patches/net/minecraft/server/Main.patch
@@ -135,7 +135,7 @@
worldstem = (WorldStem) SystemUtils.blockUntilDone((executor) -> {
return WorldLoader.load(worldloader_c, (worldloader_a) -> {
+ worldLoader.set(worldloader_a); // CraftBukkit
- IRegistry iregistry = worldloader_a.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM);
+ IRegistry iregistry = worldloader_a.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM);
if (dynamic1 != null) {
@@ -199,7 +248,7 @@
@@ -150,7 +150,7 @@
@@ -207,7 +256,7 @@
DedicatedServerProperties dedicatedserverproperties = dedicatedserversettings.getProperties();
- worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(), worldloader_a.dataConfiguration());
+ worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(worldloader_a.dataConfiguration().enabledFeatures()), worldloader_a.dataConfiguration());
- worldoptions = optionset.has(optionspec3) ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions;
+ worldoptions = optionset.has("bonusChest") ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions; // CraftBukkit
worlddimensions = dedicatedserverproperties.createDimensions(worldloader_a.datapackWorldgen());
@@ -213,5 +213,5 @@
- Main.LOGGER.info("Forcing world upgrade!");
+ Main.LOGGER.info("Forcing world upgrade! {}", convertable_conversionsession.getLevelId()); // CraftBukkit
WorldUpgrader worldupgrader = new WorldUpgrader(convertable_conversionsession, datafixer, iregistrycustom, flag, flag1);
- IChatBaseComponent ichatbasecomponent = null;
+ try {
diff --git a/nms-patches/net/minecraft/server/MinecraftServer.patch b/nms-patches/net/minecraft/server/MinecraftServer.patch
index 9aa65086..fd9dbabc 100644
--- a/nms-patches/net/minecraft/server/MinecraftServer.patch
+++ b/nms-patches/net/minecraft/server/MinecraftServer.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
-@@ -173,13 +173,38 @@
+@@ -180,13 +180,38 @@
import net.minecraft.world.phys.Vec3D;
import org.slf4j.Logger;
@@ -29,7 +29,7 @@
+import org.bukkit.event.server.ServerLoadEvent;
+// CraftBukkit end
+
- public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant implements ServerInfo, ChunkIOErrorReporter, ICommandListener, AutoCloseable {
+ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant implements ServerInfo, ChunkIOErrorReporter, ICommandListener {
public static final Logger LOGGER = LogUtils.getLogger();
public static final String VANILLA_BRAND = "vanilla";
@@ -40,9 +40,9 @@
private static final int OVERLOADED_TICKS_THRESHOLD = 20;
private static final long OVERLOADED_WARNING_INTERVAL_NANOS = 10L * TimeRange.NANOSECONDS_PER_SECOND;
private static final int OVERLOADED_TICKS_WARNING_INTERVAL = 100;
-@@ -266,6 +291,19 @@
- private volatile boolean isSaving;
- private static final AtomicReference fatalException = new AtomicReference();
+@@ -277,6 +302,19 @@
+ private final SuppressedExceptionCollector suppressedExceptions;
+ private final DiscontinuousFrame tickFrame;
+ // CraftBukkit start
+ public final WorldLoader.a worldLoader;
@@ -60,7 +60,7 @@
public static
S spin(Function function) {
AtomicReference atomicreference = new AtomicReference();
Thread thread = new Thread(() -> {
-@@ -279,14 +317,14 @@
+@@ -290,14 +328,14 @@
thread.setPriority(8);
}
@@ -76,19 +76,19 @@
+ public MinecraftServer(OptionSet options, WorldLoader.a worldLoader, Thread thread, Convertable.ConversionSession convertable_conversionsession, ResourcePackRepository resourcepackrepository, WorldStem worldstem, Proxy proxy, DataFixer datafixer, Services services, WorldLoadListenerFactory worldloadlistenerfactory) {
super("Server");
this.metricsRecorder = InactiveMetricsRecorder.INSTANCE;
- this.profiler = this.metricsRecorder.getProfiler();
-@@ -309,7 +347,7 @@
- this.customBossEvents = new BossBattleCustomData();
+ this.onMetricsRecordingStopped = (methodprofilerresults) -> {
+@@ -321,7 +359,7 @@
+ this.suppressedExceptions = new SuppressedExceptionCollector();
this.registries = worldstem.registries();
this.worldData = worldstem.worldData();
-- if (!this.registries.compositeAccess().registryOrThrow(Registries.LEVEL_STEM).containsKey(WorldDimension.OVERWORLD)) {
-+ if (false && !this.registries.compositeAccess().registryOrThrow(Registries.LEVEL_STEM).containsKey(WorldDimension.OVERWORLD)) { // CraftBukkit - initialised later
+- if (!this.registries.compositeAccess().lookupOrThrow(Registries.LEVEL_STEM).containsKey(WorldDimension.OVERWORLD)) {
++ if (false && !this.registries.compositeAccess().lookupOrThrow(Registries.LEVEL_STEM).containsKey(WorldDimension.OVERWORLD)) { // CraftBukkit - initialised later
throw new IllegalStateException("Missing Overworld dimension data");
} else {
this.proxy = proxy;
-@@ -334,6 +372,33 @@
- this.executor = SystemUtils.backgroundExecutor();
- this.potionBrewing = PotionBrewer.bootstrap(this.worldData.enabledFeatures());
+@@ -349,6 +387,33 @@
+ this.fuelValues = FuelValues.vanillaBurnTimes(this.registries.compositeAccess(), this.worldData.enabledFeatures());
+ this.tickFrame = TracyClient.createDiscontinuousFrame("Server Tick");
}
+ // CraftBukkit start
+ this.options = options;
@@ -120,7 +120,7 @@
}
private void readScoreboard(WorldPersistentData worldpersistentdata) {
-@@ -342,7 +407,7 @@
+@@ -357,7 +422,7 @@
protected abstract boolean initServer() throws IOException;
@@ -129,7 +129,7 @@
if (!JvmProfiler.INSTANCE.isRunning()) {
;
}
-@@ -350,12 +415,8 @@
+@@ -365,12 +430,8 @@
boolean flag = false;
ProfiledDuration profiledduration = JvmProfiler.INSTANCE.onWorldLoadedStarted();
@@ -143,19 +143,19 @@
if (profiledduration != null) {
profiledduration.finish();
}
-@@ -372,23 +433,217 @@
+@@ -387,23 +448,217 @@
protected void forceDifficulty() {}
- protected void createLevels(WorldLoadListener worldloadlistener) {
- IWorldDataServer iworlddataserver = this.worldData.overworldData();
- boolean flag = this.worldData.isDebugWorld();
-- IRegistry iregistry = this.registries.compositeAccess().registryOrThrow(Registries.LEVEL_STEM);
+- IRegistry iregistry = this.registries.compositeAccess().lookupOrThrow(Registries.LEVEL_STEM);
- WorldOptions worldoptions = this.worldData.worldGenOptions();
- long i = worldoptions.seed();
- long j = BiomeManager.obfuscateSeed(i);
- List list = ImmutableList.of(new MobSpawnerPhantom(), new MobSpawnerPatrol(), new MobSpawnerCat(), new VillageSiege(), new MobSpawnerTrader(iworlddataserver));
-- WorldDimension worlddimension = (WorldDimension) iregistry.get(WorldDimension.OVERWORLD);
+- WorldDimension worlddimension = (WorldDimension) iregistry.getValue(WorldDimension.OVERWORLD);
- WorldServer worldserver = new WorldServer(this, this.executor, this.storageSource, iworlddataserver, World.OVERWORLD, worlddimension, worldloadlistener, flag, j, list, true, (RandomSequences) null);
+ // CraftBukkit start
+ private void loadWorld0(String s) {
@@ -164,7 +164,7 @@
- this.levels.put(World.OVERWORLD, worldserver);
- WorldPersistentData worldpersistentdata = worldserver.getDataStorage();
+ IRegistryCustom.Dimension iregistrycustom_dimension = this.registries.compositeAccess();
-+ IRegistry dimensions = iregistrycustom_dimension.registryOrThrow(Registries.LEVEL_STEM);
++ IRegistry dimensions = iregistrycustom_dimension.lookupOrThrow(Registries.LEVEL_STEM);
+ for (WorldDimension worldDimension : dimensions) {
+ ResourceKey dimensionKey = dimensions.getResourceKey(worldDimension).get();
@@ -276,7 +276,7 @@
+
+ WorldDataServer worlddata;
+ WorldLoader.a worldloader_a = this.worldLoader;
-+ IRegistry iregistry = worldloader_a.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM);
++ IRegistry iregistry = worldloader_a.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM);
+ if (dynamic != null) {
+ LevelDataAndDimensions leveldataanddimensions = Convertable.getLevelDataAndDimensions(dynamic, worldloader_a.dataConfiguration(), iregistry, worldloader_a.datapackWorldgen());
+
@@ -293,7 +293,7 @@
+ } else {
+ DedicatedServerProperties dedicatedserverproperties = ((DedicatedServer) this).getProperties();
+
-+ worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(), worldloader_a.dataConfiguration());
++ worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(worldloader_a.dataConfiguration().enabledFeatures()), worldloader_a.dataConfiguration());
+ worldoptions = options.has("bonusChest") ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions;
+ worlddimensions = dedicatedserverproperties.createDimensions(worldloader_a.datapackWorldgen());
+ }
@@ -316,7 +316,7 @@
+ long i = worldoptions.seed();
+ long j = BiomeManager.obfuscateSeed(i);
+ List list = ImmutableList.of(new MobSpawnerPhantom(), new MobSpawnerPatrol(), new MobSpawnerCat(), new VillageSiege(), new MobSpawnerTrader(iworlddataserver));
-+ WorldDimension worlddimension = (WorldDimension) dimensions.get(dimensionKey);
++ WorldDimension worlddimension = (WorldDimension) dimensions.getValue(dimensionKey);
+
+ org.bukkit.generator.WorldInfo worldInfo = new org.bukkit.craftbukkit.generator.CraftWorldInfo(iworlddataserver, worldSession, org.bukkit.World.Environment.getEnvironment(dimension), worlddimension.type().value());
+ if (biomeProvider == null && gen != null) {
@@ -375,7 +375,7 @@
if (!iworlddataserver.isInitialized()) {
try {
-@@ -412,30 +667,8 @@
+@@ -427,30 +682,8 @@
iworlddataserver.setInitialized(true);
}
@@ -407,7 +407,7 @@
private static void setInitialSpawn(WorldServer worldserver, IWorldDataServer iworlddataserver, boolean flag, boolean flag1) {
if (flag1) {
-@@ -443,6 +676,21 @@
+@@ -458,6 +691,21 @@
} else {
ChunkProviderServer chunkproviderserver = worldserver.getChunkSource();
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(chunkproviderserver.randomState().sampler().findSpawnPosition());
@@ -428,8 +428,8 @@
+ // CraftBukkit end
int i = chunkproviderserver.getGenerator().getSpawnHeight(worldserver);
- if (i < worldserver.getMinBuildHeight()) {
-@@ -501,8 +749,11 @@
+ if (i < worldserver.getMinY()) {
+@@ -516,8 +764,11 @@
iworlddataserver.setGameType(EnumGamemode.SPECTATOR);
}
@@ -443,7 +443,7 @@
MinecraftServer.LOGGER.info("Preparing start region for dimension {}", worldserver.dimension().location());
BlockPosition blockposition = worldserver.getSharedSpawnPos();
-@@ -512,20 +763,22 @@
+@@ -527,20 +778,22 @@
this.nextTickTimeNanos = SystemUtils.getNanos();
worldserver.setDefaultSpawnPos(blockposition, worldserver.getSharedSpawnAngle());
@@ -474,7 +474,7 @@
ForcedChunk forcedchunk = (ForcedChunk) worldserver1.getDataStorage().get(ForcedChunk.factory(), "chunks");
if (forcedchunk != null) {
-@@ -540,10 +793,17 @@
+@@ -555,10 +808,17 @@
}
}
@@ -488,14 +488,14 @@
- this.updateMobSpawningFlags();
+ // CraftBukkit start
+ // this.updateMobSpawningFlags();
-+ worldserver.setSpawnSettings(this.isSpawningMonsters(), this.isSpawningAnimals());
++ worldserver.setSpawnSettings(this.isSpawningMonsters());
+
+ this.forceTicks = false;
+ // CraftBukkit end
}
public EnumGamemode getDefaultGameType() {
-@@ -573,12 +833,16 @@
+@@ -588,12 +848,16 @@
worldserver.save((IProgressUpdate) null, flag1, worldserver.noSave && !flag2);
}
@@ -512,7 +512,7 @@
if (flag1) {
Iterator iterator1 = this.getAllLevels().iterator();
-@@ -613,18 +877,40 @@
+@@ -628,18 +892,40 @@
this.stopServer();
}
@@ -553,7 +553,7 @@
}
MinecraftServer.LOGGER.info("Saving worlds");
-@@ -712,7 +998,7 @@
+@@ -727,7 +1013,7 @@
}
this.nextTickTimeNanos = SystemUtils.getNanos();
@@ -562,7 +562,7 @@
this.status = this.buildServerStatus();
while (this.running) {
-@@ -729,6 +1015,7 @@
+@@ -744,6 +1030,7 @@
if (j > MinecraftServer.OVERLOADED_THRESHOLD_NANOS + 20L * i && this.nextTickTimeNanos - this.lastOverloadWarningNanos >= MinecraftServer.OVERLOADED_WARNING_INTERVAL_NANOS + 100L * i) {
long k = j / i;
@@ -570,15 +570,15 @@
MinecraftServer.LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", j / TimeRange.NANOSECONDS_PER_MILLISECOND, k);
this.nextTickTimeNanos += k * i;
this.lastOverloadWarningNanos = this.nextTickTimeNanos;
-@@ -742,6 +1029,7 @@
+@@ -757,6 +1044,7 @@
this.debugCommandProfiler = new MinecraftServer.TimeProfiler(SystemUtils.getNanos(), this.tickCount);
}
+ MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
this.nextTickTimeNanos += i;
- this.startMetricsRecordingTick();
- this.profiler.push("tick");
-@@ -789,6 +1077,12 @@
+
+ try {
+@@ -830,6 +1118,12 @@
this.services.profileCache().clearExecutor();
}
@@ -591,7 +591,7 @@
this.onServerExit();
}
-@@ -848,7 +1142,14 @@
+@@ -889,7 +1183,14 @@
}
private boolean haveTime() {
@@ -607,7 +607,7 @@
}
public static boolean throwIfFatalException() {
-@@ -862,7 +1163,7 @@
+@@ -903,7 +1204,7 @@
}
public static void setFatalException(RuntimeException runtimeexception) {
@@ -616,36 +616,49 @@
}
@Override
-@@ -928,7 +1229,7 @@
+@@ -977,7 +1278,7 @@
}
}
- protected void doRunTask(TickTask ticktask) {
+ public void doRunTask(TickTask ticktask) { // CraftBukkit - decompile error
- this.getProfiler().incrementCounter("runTask");
+ Profiler.get().incrementCounter("runTask");
super.doRunTask(ticktask);
}
-@@ -987,8 +1288,10 @@
+@@ -1041,6 +1342,7 @@
+ this.autoSave();
+ }
+
++ this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
+ this.tickConnection();
+ return;
+ }
+@@ -1055,7 +1357,7 @@
}
--this.ticksUntilAutosave;
- if (this.ticksUntilAutosave <= 0) {
-- this.ticksUntilAutosave = this.computeNextAutosaveInterval();
-+ // CraftBukkit start
-+ if (this.autosavePeriod > 0 && this.ticksUntilAutosave <= 0) {
-+ this.ticksUntilAutosave = this.autosavePeriod;
-+ // CraftBukkit end
- MinecraftServer.LOGGER.debug("Autosave started");
- this.profiler.push("save");
- this.saveEverything(true, false, false);
-@@ -1076,11 +1379,26 @@
++ if (this.autosavePeriod > 0 && this.ticksUntilAutosave <= 0) { // CraftBukkit
+ this.autoSave();
+ }
+
+@@ -1074,7 +1376,7 @@
+ }
+
+ private void autoSave() {
+- this.ticksUntilAutosave = this.computeNextAutosaveInterval();
++ this.ticksUntilAutosave = this.autosavePeriod; // CraftBukkit
+ MinecraftServer.LOGGER.debug("Autosave started");
+ GameProfilerFiller gameprofilerfiller = Profiler.get();
+
+@@ -1154,11 +1456,26 @@
this.getPlayerList().getPlayers().forEach((entityplayer) -> {
entityplayer.connection.suspendFlushing();
});
-+ this.server.getScheduler().mainThreadHeartbeat(this.tickCount); // CraftBukkit
- this.profiler.push("commandFunctions");
++ this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
+ gameprofilerfiller.push("commandFunctions");
this.getFunctions().tick();
- this.profiler.popPush("levels");
+ gameprofilerfiller.popPush("levels");
Iterator iterator = this.getAllLevels().iterator();
+ // CraftBukkit start
@@ -658,28 +671,28 @@
+ if (this.tickCount % 20 == 0) {
+ for (int i = 0; i < this.getPlayerList().players.size(); ++i) {
+ EntityPlayer entityplayer = (EntityPlayer) this.getPlayerList().players.get(i);
-+ entityplayer.connection.send(new PacketPlayOutUpdateTime(entityplayer.level().getGameTime(), entityplayer.getPlayerTime(), entityplayer.level().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); // Add support for per player time
++ entityplayer.connection.send(new PacketPlayOutUpdateTime(entityplayer.level().getGameTime(), entityplayer.getPlayerTime(), entityplayer.serverLevel().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); // Add support for per player time
+ }
+ }
+
while (iterator.hasNext()) {
WorldServer worldserver = (WorldServer) iterator.next();
-@@ -1089,11 +1407,13 @@
+@@ -1167,11 +1484,13 @@
return s + " " + String.valueOf(worldserver.dimension().location());
});
+ /* Drop global time updates
if (this.tickCount % 20 == 0) {
- this.profiler.push("timeSync");
+ gameprofilerfiller.push("timeSync");
this.synchronizeTime(worldserver);
- this.profiler.pop();
+ gameprofilerfiller.pop();
}
+ // CraftBukkit end */
- this.profiler.push("tick");
+ gameprofilerfiller.push("tick");
-@@ -1183,6 +1503,22 @@
+@@ -1267,6 +1586,22 @@
return (WorldServer) this.levels.get(resourcekey);
}
@@ -702,7 +715,7 @@
public Set> levelKeys() {
return this.levels.keySet();
}
-@@ -1212,7 +1548,7 @@
+@@ -1296,7 +1631,7 @@
@DontObfuscate
public String getServerModName() {
@@ -711,7 +724,7 @@
}
public SystemReport fillSystemReport(SystemReport systemreport) {
-@@ -1554,11 +1890,11 @@
+@@ -1634,11 +1969,11 @@
public CompletableFuture reloadResources(Collection collection) {
CompletableFuture completablefuture = CompletableFuture.supplyAsync(() -> {
@@ -724,8 +737,8 @@
+ return stream.map(resourcepackrepository::getPack).filter(Objects::nonNull).map(ResourcePackLoader::open).collect(ImmutableList.toImmutableList()); // CraftBukkit - decompile error
}, this).thenCompose((immutablelist) -> {
ResourceManager resourcemanager = new ResourceManager(EnumResourcePackType.SERVER_DATA, immutablelist);
-
-@@ -1573,6 +1909,7 @@
+ List> list = TagDataPack.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess());
+@@ -1654,6 +1989,7 @@
}).thenAcceptAsync((minecraftserver_reloadableresources) -> {
this.resources.close();
this.resources = minecraftserver_reloadableresources;
@@ -733,16 +746,16 @@
this.packRepository.setSelected(collection);
WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures());
-@@ -1873,7 +2210,7 @@
+@@ -1952,7 +2288,7 @@
final List list = Lists.newArrayList();
final GameRules gamerules = this.getGameRules();
-- GameRules.visitGameRuleTypes(new GameRules.GameRuleVisitor(this) {
-+ GameRules.visitGameRuleTypes(new GameRules.GameRuleVisitor() { // CraftBukkit - decompile error
+- gamerules.visitGameRuleTypes(new GameRules.GameRuleVisitor(this) {
++ gamerules.visitGameRuleTypes(new GameRules.GameRuleVisitor() { // CraftBukkit - decompile error
@Override
public > void visit(GameRules.GameRuleKey gamerules_gamerulekey, GameRules.GameRuleDefinition gamerules_gameruledefinition) {
list.add(String.format(Locale.ROOT, "%s=%s\n", gamerules_gamerulekey.getId(), gamerules.getRule(gamerules_gamerulekey)));
-@@ -1979,7 +2316,7 @@
+@@ -2058,7 +2394,7 @@
try {
label51:
{
@@ -751,7 +764,7 @@
try {
arraylist = Lists.newArrayList(NativeModuleLister.listModules());
-@@ -2029,6 +2366,22 @@
+@@ -2108,6 +2444,22 @@
}
@@ -771,10 +784,10 @@
+ }
+ // CraftBukkit end
+
- private void startMetricsRecordingTick() {
+ private GameProfilerFiller createProfiler() {
if (this.willStartRecordingMetrics) {
this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(SystemUtils.timeSource, this.isDedicatedServer()), SystemUtils.timeSource, SystemUtils.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> {
-@@ -2159,6 +2512,11 @@
+@@ -2235,6 +2587,11 @@
}
diff --git a/nms-patches/net/minecraft/server/bossevents/BossBattleCustom.patch b/nms-patches/net/minecraft/server/bossevents/BossBattleCustom.patch
new file mode 100644
index 00000000..3dacf956
--- /dev/null
+++ b/nms-patches/net/minecraft/server/bossevents/BossBattleCustom.patch
@@ -0,0 +1,30 @@
+--- a/net/minecraft/server/bossevents/BossBattleCustom.java
++++ b/net/minecraft/server/bossevents/BossBattleCustom.java
+@@ -19,12 +19,27 @@
+ import net.minecraft.util.MathHelper;
+ import net.minecraft.world.BossBattle;
+
++// CraftBukkit start
++import org.bukkit.boss.KeyedBossBar;
++import org.bukkit.craftbukkit.boss.CraftKeyedBossbar;
++// CraftBukkit end
++
+ public class BossBattleCustom extends BossBattleServer {
+
+ private final MinecraftKey id;
+ private final Set players = Sets.newHashSet();
+ private int value;
+ private int max = 100;
++ // CraftBukkit start
++ private KeyedBossBar bossBar;
++
++ public KeyedBossBar getBukkitEntity() {
++ if (bossBar == null) {
++ bossBar = new CraftKeyedBossbar(this);
++ }
++ return bossBar;
++ }
++ // CraftBukkit end
+
+ public BossBattleCustom(MinecraftKey minecraftkey, IChatBaseComponent ichatbasecomponent) {
+ super(ichatbasecomponent, BossBattle.BarColor.WHITE, BossBattle.BarStyle.PROGRESS);
diff --git a/nms-patches/net/minecraft/server/commands/CommandGamerule.patch b/nms-patches/net/minecraft/server/commands/CommandGamerule.patch
index e9c56cdd..f3107570 100644
--- a/nms-patches/net/minecraft/server/commands/CommandGamerule.patch
+++ b/nms-patches/net/minecraft/server/commands/CommandGamerule.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/commands/CommandGamerule.java
+++ b/net/minecraft/server/commands/CommandGamerule.java
-@@ -31,7 +31,7 @@
+@@ -34,7 +34,7 @@
static > int setRule(CommandContext commandcontext, GameRules.GameRuleKey gamerules_gamerulekey) {
CommandListenerWrapper commandlistenerwrapper = (CommandListenerWrapper) commandcontext.getSource();
@@ -9,7 +9,7 @@
t0.setFromArgument(commandcontext, "value");
commandlistenerwrapper.sendSuccess(() -> {
-@@ -41,7 +41,7 @@
+@@ -44,7 +44,7 @@
}
static > int queryRule(CommandListenerWrapper commandlistenerwrapper, GameRules.GameRuleKey gamerules_gamerulekey) {
diff --git a/nms-patches/net/minecraft/server/commands/CommandLoot.patch b/nms-patches/net/minecraft/server/commands/CommandLoot.patch
index 8c242917..d68afd40 100644
--- a/nms-patches/net/minecraft/server/commands/CommandLoot.patch
+++ b/nms-patches/net/minecraft/server/commands/CommandLoot.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/commands/CommandLoot.java
+++ b/net/minecraft/server/commands/CommandLoot.java
-@@ -91,7 +91,7 @@
+@@ -95,7 +95,7 @@
}
private static > T addTargets(T t0, CommandLoot.c commandloot_c) {
@@ -9,7 +9,7 @@
return entityReplace(ArgumentEntity.getEntities(commandcontext, "entities"), ArgumentInventorySlot.getSlot(commandcontext, "slot"), list.size(), list, commandloot_a);
}).then(commandloot_c.construct(net.minecraft.commands.CommandDispatcher.argument("count", IntegerArgumentType.integer(0)), (commandcontext, list, commandloot_a) -> {
return entityReplace(ArgumentEntity.getEntities(commandcontext, "entities"), ArgumentInventorySlot.getSlot(commandcontext, "slot"), IntegerArgumentType.getInteger(commandcontext, "count"), list, commandloot_a);
-@@ -246,6 +246,7 @@
+@@ -250,6 +250,7 @@
private static int dropInWorld(CommandListenerWrapper commandlistenerwrapper, Vec3D vec3d, List list, CommandLoot.a commandloot_a) throws CommandSyntaxException {
WorldServer worldserver = commandlistenerwrapper.getLevel();
diff --git a/nms-patches/net/minecraft/server/commands/CommandSchedule.patch b/nms-patches/net/minecraft/server/commands/CommandSchedule.patch
index 00b20307..96177b3a 100644
--- a/nms-patches/net/minecraft/server/commands/CommandSchedule.patch
+++ b/nms-patches/net/minecraft/server/commands/CommandSchedule.patch
@@ -1,11 +1,11 @@
--- a/net/minecraft/server/commands/CommandSchedule.java
+++ b/net/minecraft/server/commands/CommandSchedule.java
-@@ -55,7 +55,7 @@
+@@ -58,7 +58,7 @@
} else {
long j = commandlistenerwrapper.getLevel().getGameTime() + (long) i;
MinecraftKey minecraftkey = (MinecraftKey) pair.getFirst();
- CustomFunctionCallbackTimerQueue customfunctioncallbacktimerqueue = commandlistenerwrapper.getServer().getWorldData().overworldData().getScheduledEvents();
+ CustomFunctionCallbackTimerQueue customfunctioncallbacktimerqueue = commandlistenerwrapper.getLevel().serverLevelData.overworldData().getScheduledEvents(); // CraftBukkit - SPIGOT-6667: Use world specific function timer
+ Optional> optional = ((Either) pair.getSecond()).left();
+ String s;
- ((Either) pair.getSecond()).ifLeft((net_minecraft_commands_functions_commandfunction) -> {
- String s = minecraftkey.toString();
diff --git a/nms-patches/net/minecraft/server/commands/CommandSpreadPlayers.patch b/nms-patches/net/minecraft/server/commands/CommandSpreadPlayers.patch
index b637188c..67d39d33 100644
--- a/nms-patches/net/minecraft/server/commands/CommandSpreadPlayers.patch
+++ b/nms-patches/net/minecraft/server/commands/CommandSpreadPlayers.patch
@@ -13,8 +13,8 @@
commandspreadplayers_a = acommandspreadplayers_a[j++];
}
-- entity.teleportTo(worldserver, (double) MathHelper.floor(commandspreadplayers_a.x) + 0.5D, (double) commandspreadplayers_a.getSpawnY(worldserver, i), (double) MathHelper.floor(commandspreadplayers_a.z) + 0.5D, Set.of(), entity.getYRot(), entity.getXRot());
-+ entity.teleportTo(worldserver, (double) MathHelper.floor(commandspreadplayers_a.x) + 0.5D, (double) commandspreadplayers_a.getSpawnY(worldserver, i), (double) MathHelper.floor(commandspreadplayers_a.z) + 0.5D, Set.of(), entity.getYRot(), entity.getXRot(), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.COMMAND); // CraftBukkit - handle teleport reason
+- entity.teleportTo(worldserver, (double) MathHelper.floor(commandspreadplayers_a.x) + 0.5D, (double) commandspreadplayers_a.getSpawnY(worldserver, i), (double) MathHelper.floor(commandspreadplayers_a.z) + 0.5D, Set.of(), entity.getYRot(), entity.getXRot(), true);
++ entity.teleportTo(worldserver, (double) MathHelper.floor(commandspreadplayers_a.x) + 0.5D, (double) commandspreadplayers_a.getSpawnY(worldserver, i), (double) MathHelper.floor(commandspreadplayers_a.z) + 0.5D, Set.of(), entity.getYRot(), entity.getXRot(), true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.COMMAND); // CraftBukkit - handle teleport reason
d1 = Double.MAX_VALUE;
CommandSpreadPlayers.a[] acommandspreadplayers_a1 = acommandspreadplayers_a;
int k = acommandspreadplayers_a.length;
diff --git a/nms-patches/net/minecraft/server/commands/CommandSummon.patch b/nms-patches/net/minecraft/server/commands/CommandSummon.patch
index 7cff016f..8e53d336 100644
--- a/nms-patches/net/minecraft/server/commands/CommandSummon.patch
+++ b/nms-patches/net/minecraft/server/commands/CommandSummon.patch
@@ -1,7 +1,7 @@
--- a/net/minecraft/server/commands/CommandSummon.java
+++ b/net/minecraft/server/commands/CommandSummon.java
@@ -67,7 +67,7 @@
- ((EntityInsentient) entity).finalizeSpawn(commandlistenerwrapper.getLevel(), commandlistenerwrapper.getLevel().getCurrentDifficultyAt(entity.blockPosition()), EnumMobSpawn.COMMAND, (GroupDataEntity) null);
+ ((EntityInsentient) entity).finalizeSpawn(commandlistenerwrapper.getLevel(), commandlistenerwrapper.getLevel().getCurrentDifficultyAt(entity.blockPosition()), EntitySpawnReason.COMMAND, (GroupDataEntity) null);
}
- if (!worldserver.tryAddFreshEntityWithPassengers(entity)) {
diff --git a/nms-patches/net/minecraft/server/commands/CommandTeleport.patch b/nms-patches/net/minecraft/server/commands/CommandTeleport.patch
index c96cfba8..01612c03 100644
--- a/nms-patches/net/minecraft/server/commands/CommandTeleport.patch
+++ b/nms-patches/net/minecraft/server/commands/CommandTeleport.patch
@@ -1,10 +1,11 @@
--- a/net/minecraft/server/commands/CommandTeleport.java
+++ b/net/minecraft/server/commands/CommandTeleport.java
-@@ -33,6 +33,13 @@
+@@ -31,6 +31,14 @@
import net.minecraft.world.phys.Vec2F;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
++import net.minecraft.server.level.EntityPlayer;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.event.entity.EntityTeleportEvent;
@@ -14,35 +15,35 @@
public class CommandTeleport {
private static final SimpleCommandExceptionType INVALID_POSITION = new SimpleCommandExceptionType(IChatBaseComponent.translatable("commands.teleport.invalidPosition"));
-@@ -155,7 +162,30 @@
- float f2 = MathHelper.wrapDegrees(f);
- float f3 = MathHelper.wrapDegrees(f1);
+@@ -167,7 +175,30 @@
+ float f4 = MathHelper.wrapDegrees(f2);
+ float f5 = MathHelper.wrapDegrees(f3);
-- if (entity.teleportTo(worldserver, d0, d1, d2, set, f2, f3)) {
+- if (entity.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true)) {
+ // CraftBukkit start - Teleport event
+ boolean result;
+ if (entity instanceof EntityPlayer player) {
-+ result = player.teleportTo(worldserver, d0, d1, d2, set, f2, f3, PlayerTeleportEvent.TeleportCause.COMMAND);
++ result = player.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true, PlayerTeleportEvent.TeleportCause.COMMAND);
+ } else {
-+ Location to = new Location(worldserver.getWorld(), d0, d1, d2, f2, f3);
++ Location to = new Location(worldserver.getWorld(), d3, d4, d5, f4, f5);
+ EntityTeleportEvent event = new EntityTeleportEvent(entity.getBukkitEntity(), entity.getBukkitEntity().getLocation(), to);
+ worldserver.getCraftServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+
-+ d0 = to.getX();
-+ d1 = to.getY();
-+ d2 = to.getZ();
-+ f2 = to.getYaw();
-+ f3 = to.getPitch();
++ d3 = to.getX();
++ d4 = to.getY();
++ d5 = to.getZ();
++ f4 = to.getYaw();
++ f5 = to.getPitch();
+ worldserver = ((CraftWorld) to.getWorld()).getHandle();
+
-+ result = entity.teleportTo(worldserver, d0, d1, d2, set, f2, f3);
++ result = entity.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true);
+ }
+
+ if (result) {
+ // CraftBukkit end
- if (commandteleport_a != null) {
- commandteleport_a.perform(commandlistenerwrapper, entity);
+ if (lookat != null) {
+ lookat.perform(commandlistenerwrapper, entity);
}
diff --git a/nms-patches/net/minecraft/server/dedicated/DedicatedServer.patch b/nms-patches/net/minecraft/server/dedicated/DedicatedServer.patch
index 2113fa76..2b0e2397 100644
--- a/nms-patches/net/minecraft/server/dedicated/DedicatedServer.patch
+++ b/nms-patches/net/minecraft/server/dedicated/DedicatedServer.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
-@@ -60,6 +60,18 @@
+@@ -59,6 +59,18 @@
import net.minecraft.world.level.storage.Convertable;
import org.slf4j.Logger;
@@ -19,7 +19,7 @@
public class DedicatedServer extends MinecraftServer implements IMinecraftServer {
static final Logger LOGGER = LogUtils.getLogger();
-@@ -68,7 +80,7 @@
+@@ -67,7 +79,7 @@
private final List consoleInput = Collections.synchronizedList(Lists.newArrayList());
@Nullable
private RemoteStatusListener queryThreadGs4;
@@ -28,7 +28,7 @@
@Nullable
private RemoteControlListener rconThread;
public DedicatedServerSettings settings;
-@@ -82,10 +94,12 @@
+@@ -81,10 +93,12 @@
private DebugSampleSubscriptionTracker debugSampleSubscriptionTracker;
public ServerLinks serverLinks;
@@ -41,10 +41,10 @@
this.settings = dedicatedserversettings;
- this.rconConsoleSource = new RemoteControlCommandListener(this);
+ // this.rconConsoleSource = new RemoteControlCommandListener(this); // CraftBukkit - remove field
- this.textFilterClient = TextFilter.createFromConfig(dedicatedserversettings.getProperties().textFilteringConfig);
+ this.serverTextFilter = ServerTextFilter.createFromConfig(dedicatedserversettings.getProperties());
this.serverLinks = createServerLinks(dedicatedserversettings);
}
-@@ -94,13 +108,44 @@
+@@ -93,13 +107,44 @@
public boolean initServer() throws IOException {
Thread thread = new Thread("Server console handler") {
public void run() {
@@ -92,7 +92,7 @@
}
} catch (IOException ioexception) {
DedicatedServer.LOGGER.error("Exception handling console input", ioexception);
-@@ -109,6 +154,29 @@
+@@ -108,6 +153,29 @@
}
};
@@ -122,7 +122,7 @@
thread.setDaemon(true);
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(DedicatedServer.LOGGER));
thread.start();
-@@ -133,7 +201,7 @@
+@@ -132,7 +200,7 @@
this.setMotd(dedicatedserverproperties.motd);
super.setPlayerIdleTimeout((Integer) dedicatedserverproperties.playerIdleTimeout.get());
this.setEnforceWhitelist(dedicatedserverproperties.enforceWhitelist);
@@ -131,7 +131,7 @@
DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode);
InetAddress inetaddress = null;
-@@ -157,6 +225,12 @@
+@@ -156,6 +224,12 @@
return false;
}
@@ -144,7 +144,7 @@
if (!this.usesAuthentication()) {
DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware.");
-@@ -171,7 +245,7 @@
+@@ -170,7 +244,7 @@
if (!NameReferencingFileConverter.serverReadyAfterUserconversion(this)) {
return false;
} else {
@@ -153,7 +153,7 @@
this.debugSampleSubscriptionTracker = new DebugSampleSubscriptionTracker(this.getPlayerList());
this.tickTimeLogger = new RemoteSampleLogger(TpsDebugDimensions.values().length, this.debugSampleSubscriptionTracker, RemoteDebugSampleType.TICK_TIME);
long i = SystemUtils.getNanos();
-@@ -179,13 +253,13 @@
+@@ -178,13 +252,13 @@
TileEntitySkull.setup(this.services, this);
UserCache.setUsesAuthentication(this.usesAuthentication());
DedicatedServer.LOGGER.info("Preparing level \"{}\"", this.getLevelIdName());
@@ -169,7 +169,7 @@
}
if (dedicatedserverproperties.enableQuery) {
-@@ -311,6 +385,7 @@
+@@ -293,6 +367,7 @@
this.queryThreadGs4.stop();
}
@@ -177,7 +177,7 @@
}
@Override
-@@ -332,7 +407,15 @@
+@@ -314,7 +389,15 @@
while (!this.consoleInput.isEmpty()) {
ServerCommand servercommand = (ServerCommand) this.consoleInput.remove(0);
@@ -194,7 +194,7 @@
}
}
-@@ -559,16 +642,52 @@
+@@ -541,16 +624,52 @@
@Override
public String getPluginNames() {
@@ -251,7 +251,7 @@
}
public void storeUsingWhiteList(boolean flag) {
-@@ -673,4 +792,15 @@
+@@ -660,4 +779,15 @@
}
}
}
diff --git a/nms-patches/net/minecraft/server/dedicated/DedicatedServerProperties.patch b/nms-patches/net/minecraft/server/dedicated/DedicatedServerProperties.patch
index b14bb65a..f46a8a10 100644
--- a/nms-patches/net/minecraft/server/dedicated/DedicatedServerProperties.patch
+++ b/nms-patches/net/minecraft/server/dedicated/DedicatedServerProperties.patch
@@ -30,7 +30,7 @@
this.difficulty = (EnumDifficulty) this.get("difficulty", dispatchNumberOrString(EnumDifficulty::byId, EnumDifficulty::byName), EnumDifficulty::getKey, EnumDifficulty.EASY);
this.gamemode = (EnumGamemode) this.get("gamemode", dispatchNumberOrString(EnumGamemode::byId, EnumGamemode::byName), EnumGamemode::getName, EnumGamemode.SURVIVAL);
this.levelName = this.get("level-name", "world");
-@@ -165,13 +172,15 @@
+@@ -167,13 +174,15 @@
this.initialDataPackConfiguration = getDatapackConfig(this.get("initial-enabled-packs", String.join(",", WorldDataConfiguration.DEFAULT.dataPacks().getEnabled())), this.get("initial-disabled-packs", String.join(",", WorldDataConfiguration.DEFAULT.dataPacks().getDisabled())));
}
@@ -50,7 +50,7 @@
}
@Nullable
-@@ -252,10 +261,10 @@
+@@ -254,10 +263,10 @@
}).orElseThrow(() -> {
return new IllegalStateException("Invalid datapack contents: can't find default preset");
});
@@ -62,11 +62,11 @@
+ return Optional.ofNullable(DedicatedServerProperties.WorldDimensionData.LEGACY_PRESET_NAMES.get(this.levelType)); // CraftBukkit - decompile error
});
- Objects.requireNonNull(iregistry);
-@@ -267,7 +276,7 @@
+ Objects.requireNonNull(holderlookup);
+@@ -269,7 +278,7 @@
if (holder.is(WorldPresets.FLAT)) {
- RegistryOps registryops = iregistrycustom.createSerializationContext(JsonOps.INSTANCE);
+ RegistryOps registryops = holderlookup_a.createSerializationContext(JsonOps.INSTANCE);
- DataResult dataresult = GeneratorSettingsFlat.CODEC.parse(new Dynamic(registryops, this.generatorSettings()));
+ DataResult dataresult = GeneratorSettingsFlat.CODEC.parse(new Dynamic(registryops, this.generatorSettings())); // CraftBukkit - decompile error
Logger logger = DedicatedServerProperties.LOGGER;
diff --git a/nms-patches/net/minecraft/server/gui/ServerGUI.patch b/nms-patches/net/minecraft/server/gui/ServerGUI.patch
new file mode 100644
index 00000000..e99114a8
--- /dev/null
+++ b/nms-patches/net/minecraft/server/gui/ServerGUI.patch
@@ -0,0 +1,37 @@
+--- a/net/minecraft/server/gui/ServerGUI.java
++++ b/net/minecraft/server/gui/ServerGUI.java
+@@ -96,7 +96,7 @@
+ private JComponent buildInfoPanel() {
+ JPanel jpanel = new JPanel(new BorderLayout());
+ GuiStatsComponent guistatscomponent = new GuiStatsComponent(this.server);
+- Collection collection = this.finalizers;
++ Collection collection = this.finalizers; // CraftBukkit - decompile error
+
+ Objects.requireNonNull(guistatscomponent);
+ collection.add(guistatscomponent::close);
+@@ -132,7 +132,7 @@
+
+ jtextfield.setText("");
+ });
+- jtextarea.addFocusListener(new FocusAdapter(this) {
++ jtextarea.addFocusListener(new FocusAdapter() { // CraftBukkit - decompile error
+ public void focusGained(FocusEvent focusevent) {}
+ });
+ jpanel.add(jscrollpane, "Center");
+@@ -166,6 +166,7 @@
+ this.finalizers.forEach(Runnable::run);
+ }
+
++ private static final java.util.regex.Pattern ANSI = java.util.regex.Pattern.compile("\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})*)?[m|K]"); // CraftBukkit
+ public void print(JTextArea jtextarea, JScrollPane jscrollpane, String s) {
+ if (!SwingUtilities.isEventDispatchThread()) {
+ SwingUtilities.invokeLater(() -> {
+@@ -181,7 +182,7 @@
+ }
+
+ try {
+- document.insertString(document.getLength(), s, (AttributeSet) null);
++ document.insertString(document.getLength(), ANSI.matcher(s).replaceAll(""), (AttributeSet) null); // CraftBukkit
+ } catch (BadLocationException badlocationexception) {
+ ;
+ }
diff --git a/nms-patches/net/minecraft/server/level/ChunkMapDistance.patch b/nms-patches/net/minecraft/server/level/ChunkMapDistance.patch
index b88b2aeb..8a42bd4d 100644
--- a/nms-patches/net/minecraft/server/level/ChunkMapDistance.patch
+++ b/nms-patches/net/minecraft/server/level/ChunkMapDistance.patch
@@ -1,6 +1,22 @@
--- a/net/minecraft/server/level/ChunkMapDistance.java
+++ b/net/minecraft/server/level/ChunkMapDistance.java
-@@ -163,7 +163,7 @@
+@@ -117,6 +117,15 @@
+
+ PlayerChunk playerchunk;
+
++ // CraftBukkit start - SPIGOT-7780: Call chunk unload events before updateHighestAllowedStatus
++ while (iterator.hasNext()) {
++ playerchunk = (PlayerChunk) iterator.next();
++ playerchunk.callEventIfUnloading(playerchunkmap);
++ }
++
++ iterator = this.chunksToUpdateFutures.iterator();
++ // CraftBukkit end
++
+ while (iterator.hasNext()) {
+ playerchunk = (PlayerChunk) iterator.next();
+ playerchunk.updateHighestAllowedStatus(playerchunkmap);
+@@ -165,7 +174,7 @@
}
}
@@ -9,7 +25,7 @@
ArraySetSorted> arraysetsorted = this.getTickets(i);
int j = getTicketLevelAt(arraysetsorted);
Ticket> ticket1 = (Ticket) arraysetsorted.addOrGet(ticket);
-@@ -173,13 +173,15 @@
+@@ -175,13 +184,15 @@
this.ticketTracker.update(i, ticket.getTicketLevel(), true);
}
@@ -27,7 +43,7 @@
}
if (arraysetsorted.isEmpty()) {
-@@ -187,6 +189,7 @@
+@@ -189,6 +200,7 @@
}
this.ticketTracker.update(i, getTicketLevelAt(arraysetsorted), false);
@@ -35,7 +51,7 @@
}
public void addTicket(TicketType tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
-@@ -200,19 +203,33 @@
+@@ -202,19 +214,33 @@
}
public void addRegionTicket(TicketType tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) {
@@ -71,7 +87,7 @@
}
private ArraySetSorted> getTickets(long i) {
-@@ -251,6 +268,7 @@
+@@ -253,6 +279,7 @@
ChunkCoordIntPair chunkcoordintpair = sectionposition.chunk();
long i = chunkcoordintpair.toLong();
ObjectSet objectset = (ObjectSet) this.playersPerChunk.get(i);
@@ -79,7 +95,7 @@
objectset.remove(entityplayer);
if (objectset.isEmpty()) {
-@@ -380,6 +398,26 @@
+@@ -391,6 +418,26 @@
return !this.tickets.isEmpty();
}
diff --git a/nms-patches/net/minecraft/server/level/ChunkProviderServer.patch b/nms-patches/net/minecraft/server/level/ChunkProviderServer.patch
index 18aed6e8..6d00dd68 100644
--- a/nms-patches/net/minecraft/server/level/ChunkProviderServer.patch
+++ b/nms-patches/net/minecraft/server/level/ChunkProviderServer.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/ChunkProviderServer.java
+++ b/net/minecraft/server/level/ChunkProviderServer.java
-@@ -82,6 +82,16 @@
+@@ -96,6 +96,16 @@
this.clearCache();
}
@@ -17,7 +17,7 @@
@Override
public LightEngineThreaded getLightEngine() {
return this.lightEngine;
-@@ -125,7 +135,7 @@
+@@ -139,7 +149,7 @@
if (k == this.lastChunkPos[l] && chunkstatus == this.lastChunkStatus[l]) {
IChunkAccess ichunkaccess = this.lastChunk[l];
@@ -26,7 +26,7 @@
return ichunkaccess;
}
}
-@@ -138,7 +148,7 @@
+@@ -152,7 +162,7 @@
Objects.requireNonNull(completablefuture);
chunkproviderserver_b.managedBlock(completablefuture::isDone);
ChunkResult chunkresult = (ChunkResult) completablefuture.join();
@@ -35,7 +35,7 @@
if (ichunkaccess1 == null && flag) {
throw (IllegalStateException) SystemUtils.pauseInIde(new IllegalStateException("Chunk not there when requested: " + chunkresult.getError()));
-@@ -218,7 +228,15 @@
+@@ -232,7 +242,15 @@
int l = ChunkLevel.byStatus(chunkstatus);
PlayerChunk playerchunk = this.getVisibleChunkIfPresent(k);
@@ -51,8 +51,8 @@
+ // CraftBukkit end
this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
if (this.chunkAbsent(playerchunk, l)) {
- GameProfilerFiller gameprofilerfiller = this.level.getProfiler();
-@@ -237,7 +255,7 @@
+ GameProfilerFiller gameprofilerfiller = Profiler.get();
+@@ -251,7 +269,7 @@
}
private boolean chunkAbsent(@Nullable PlayerChunk playerchunk, int i) {
@@ -61,7 +61,7 @@
}
@Override
-@@ -292,11 +310,31 @@
+@@ -310,12 +328,34 @@
@Override
public void close() throws IOException {
@@ -75,40 +75,63 @@
+ this.save(true);
+ }
+ // CraftBukkit end
+ this.dataStorage.close();
this.lightEngine.close();
this.chunkMap.close();
}
+ // CraftBukkit start - modelled on below
+ public void purgeUnload() {
-+ this.level.getProfiler().push("purge");
++ GameProfilerFiller gameprofilerfiller = Profiler.get();
++
++ gameprofilerfiller.push("purge");
+ this.distanceManager.purgeStaleTickets();
+ this.runDistanceManagerUpdates();
-+ this.level.getProfiler().popPush("unload");
++ gameprofilerfiller.popPush("unload");
+ this.chunkMap.tick(() -> true);
-+ this.level.getProfiler().pop();
++ gameprofilerfiller.pop();
+ this.clearCache();
+ }
+ // CraftBukkit end
+
@Override
public void tick(BooleanSupplier booleansupplier, boolean flag) {
- this.level.getProfiler().push("purge");
-@@ -346,11 +384,11 @@
+ GameProfilerFiller gameprofilerfiller = Profiler.get();
+@@ -402,14 +442,14 @@
+
+ this.lastSpawnState = spawnercreature_d;
+ gameprofilerfiller.popPush("spawnAndTick");
+- boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING);
++ boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
+ int k = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
+ List list1;
- this.lastSpawnState = spawnercreature_d;
- gameprofilerfiller.popPush("spawnAndTick");
-- boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING);
-+ boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
+ if (flag && (this.spawnEnemies || this.spawnFriendlies)) {
+- boolean flag1 = this.level.getLevelData().getGameTime() % 400L == 0L;
++ boolean flag1 = this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && this.level.getLevelData().getGameTime() % this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit
- SystemUtils.shuffle(list, this.level.random);
- int l = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
-- boolean flag1 = this.level.getLevelData().getGameTime() % 400L == 0L;
-+ boolean flag1 = this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && this.level.getLevelData().getGameTime() % this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit
- Iterator iterator1 = list.iterator();
+- list1 = SpawnerCreature.getFilteredSpawningCategories(spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1);
++ list1 = SpawnerCreature.getFilteredSpawningCategories(spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1, this.level); // CraftBukkit
+ } else {
+ list1 = List.of();
+ }
+@@ -542,8 +582,14 @@
+
+ @Override
+ public void setSpawnSettings(boolean flag) {
++ // CraftBukkit start
++ this.setSpawnSettings(flag, this.spawnFriendlies);
++ }
++
++ public void setSpawnSettings(boolean flag, boolean spawnFriendlies) {
+ this.spawnEnemies = flag;
+- this.spawnFriendlies = this.spawnFriendlies;
++ this.spawnFriendlies = spawnFriendlies;
++ // CraftBukkit end
+ }
- while (iterator1.hasNext()) {
-@@ -560,13 +598,19 @@
+ public String getChunkDebugData(ChunkCoordIntPair chunkcoordintpair) {
+@@ -619,13 +665,19 @@
}
@Override
diff --git a/nms-patches/net/minecraft/server/level/EntityPlayer.patch b/nms-patches/net/minecraft/server/level/EntityPlayer.patch
index f14d7ace..d2126ebd 100644
--- a/nms-patches/net/minecraft/server/level/EntityPlayer.patch
+++ b/nms-patches/net/minecraft/server/level/EntityPlayer.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/EntityPlayer.java
+++ b/net/minecraft/server/level/EntityPlayer.java
-@@ -166,6 +166,40 @@
+@@ -184,6 +184,41 @@
import net.minecraft.world.scores.criteria.IScoreboardCriteria;
import org.slf4j.Logger;
@@ -15,6 +15,7 @@
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.WeatherType;
++import org.bukkit.command.CommandSender;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.CraftWorldBorder;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
@@ -28,20 +29,20 @@
+import org.bukkit.event.player.PlayerBedLeaveEvent;
+import org.bukkit.event.player.PlayerChangedMainHandEvent;
+import org.bukkit.event.player.PlayerChangedWorldEvent;
++import org.bukkit.event.player.PlayerDropItemEvent;
+import org.bukkit.event.player.PlayerLocaleChangeEvent;
+import org.bukkit.event.player.PlayerPortalEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
+import org.bukkit.event.player.PlayerSpawnChangeEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
-+import org.bukkit.event.player.PlayerToggleSneakEvent;
+import org.bukkit.inventory.MainHand;
+// CraftBukkit end
+
public class EntityPlayer extends EntityHuman {
private static final Logger LOGGER = LogUtils.getLogger();
-@@ -204,7 +238,7 @@
+@@ -227,7 +262,7 @@
private int levitationStartTime;
private boolean disconnected;
private int requestedViewDistance;
@@ -50,7 +51,7 @@
@Nullable
private Vec3D startingToFallPosition;
@Nullable
-@@ -235,6 +269,21 @@
+@@ -261,6 +296,22 @@
private int containerCounter;
public boolean wonGame;
@@ -58,6 +59,7 @@
+ public CraftPlayer.TransferCookieConnection transferCookieConnection;
+ public String displayName;
+ public IChatBaseComponent listName;
++ public int listOrder = 0;
+ public org.bukkit.Location compassTarget;
+ public int newExp = 0;
+ public int newLevel = 0;
@@ -72,7 +74,21 @@
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, ClientInformation clientinformation) {
super(worldserver, worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle(), gameprofile);
this.chatVisibility = EnumChatVisibility.FULL;
-@@ -302,14 +351,67 @@
+@@ -342,6 +393,13 @@
+ public void sendSystemMessage(IChatBaseComponent ichatbasecomponent) {
+ EntityPlayer.this.sendSystemMessage(ichatbasecomponent);
+ }
++
++ // CraftBukkit start
++ @Override
++ public CommandSender getBukkitSender(CommandListenerWrapper wrapper) {
++ return getBukkitEntity();
++ }
++ // CraftBukkit end
+ };
+ this.textFilter = minecraftserver.createTextFilterForPlayer(this);
+ this.gameMode = minecraftserver.createGameModeForPlayer(this);
+@@ -354,14 +412,67 @@
this.moveTo(this.adjustSpawnLocation(worldserver, worldserver.getSharedSpawnPos()).getBottomCenter(), 0.0F, 0.0F);
this.updateOptions(clientinformation);
this.object = null;
@@ -81,8 +97,8 @@
+ this.displayName = this.getScoreboardName();
+ this.bukkitPickUpLoot = true;
+ this.maxHealthCache = this.getMaxHealth();
- }
-
++ }
++
+ // Use method to resend items in hands in case of client desync, because the item use got cancelled.
+ // For example, when cancelling the leash event
+ public void resendItemInHands() {
@@ -128,9 +144,9 @@
+ }
+
+ return blockposition;
-+ }
+ }
+ // CraftBukkit end
-+
+
@Override
public BlockPosition adjustSpawnLocation(WorldServer worldserver, BlockPosition blockposition) {
AxisAlignedBB axisalignedbb = this.getDimensions(EntityPose.STANDING).makeBoundingBox(Vec3D.ZERO);
@@ -141,7 +157,30 @@
int i = Math.max(0, this.server.getSpawnRadius(worldserver));
int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ()));
-@@ -366,7 +468,7 @@
+@@ -397,14 +508,20 @@
+
+ Objects.requireNonNull(blockposition);
+ crashreportsystemdetails.setDetail("Origin", blockposition::toString);
++ // CraftBukkit start - decompile error
++ int finalI = i;
+ crashreportsystemdetails.setDetail("Radius", () -> {
+- return Integer.toString(i);
++ return Integer.toString(finalI);
++ // CraftBukkit end
+ });
+ crashreportsystemdetails.setDetail("Candidate", () -> {
+ return "[" + l2 + "," + i3 + "]";
+ });
++ // CraftBukkit start - decompile error
++ int finalL1 = l1;
+ crashreportsystemdetails.setDetail("Progress", () -> {
+- return "" + l1 + " out of " + i1;
++ return "" + finalL1 + " out of " + i1;
++ // CraftBukkit end
+ });
+ throw new ReportedException(crashreport);
+ }
+@@ -442,7 +559,7 @@
dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("warden_spawn_tracker")));
logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -150,9 +189,9 @@
this.wardenSpawnTracker = wardenspawntracker;
});
}
-@@ -381,17 +483,26 @@
- if (nbttagcompound.contains("recipeBook", 10)) {
- this.recipeBook.fromNbt(nbttagcompound.getCompound("recipeBook"), this.server.getRecipeManager());
+@@ -459,17 +576,26 @@
+ return this.server.getRecipeManager().byKey(resourcekey).isPresent();
+ });
}
+ this.getBukkitEntity().readExtraData(nbttagcompound); // CraftBukkit
@@ -178,7 +217,7 @@
Logger logger1 = EntityPlayer.LOGGER;
Objects.requireNonNull(logger1);
-@@ -406,7 +517,7 @@
+@@ -484,7 +610,7 @@
dataresult = BlockPosition.CODEC.parse(DynamicOpsNBT.INSTANCE, nbtbase);
logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -187,7 +226,7 @@
this.raidOmenPosition = blockposition;
});
}
-@@ -416,7 +527,7 @@
+@@ -494,7 +620,7 @@
@Override
public void addAdditionalSaveData(NBTTagCompound nbttagcompound) {
super.addAdditionalSaveData(nbttagcompound);
@@ -196,7 +235,15 @@
Logger logger = EntityPlayer.LOGGER;
Objects.requireNonNull(logger);
-@@ -437,7 +548,20 @@
+@@ -528,6 +654,7 @@
+ nbttagcompound.put("SpawnDimension", nbtbase);
+ });
+ }
++ this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit
+
+ nbttagcompound.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall);
+ if (this.raidOmenPosition != null) {
+@@ -546,7 +673,20 @@
Entity entity = this.getRootVehicle();
Entity entity1 = this.getVehicle();
@@ -215,18 +262,43 @@
+
+ if (persistVehicle && entity1 != null && entity != this && entity.hasExactlyOnePlayerPassenger()) {
+ // CraftBukkit end
+ NBTTagCompound nbttagcompound1 = new NBTTagCompound();
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
- NBTTagCompound nbttagcompound3 = new NBTTagCompound();
-@@ -462,6 +586,7 @@
- nbttagcompound.put("SpawnDimension", nbtbase);
- });
- }
-+ this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit
+@@ -600,12 +740,12 @@
- nbttagcompound.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall);
- if (this.raidOmenPosition != null) {
-@@ -475,6 +600,29 @@
+ if (!this.isPassenger()) {
+ EntityPlayer.LOGGER.warn("Couldn't reattach entity to player");
+- entity.discard();
++ entity.discard(null); // CraftBukkit - add Bukkit remove cause
+ iterator = entity.getIndirectPassengers().iterator();
+
+ while (iterator.hasNext()) {
+ entity1 = (Entity) iterator.next();
+- entity1.discard();
++ entity1.discard(null); // CraftBukkit - add Bukkit remove cause
+ }
+ }
+ }
+@@ -627,7 +767,7 @@
+ NBTTagCompound nbttagcompound1 = new NBTTagCompound();
+
+ entityenderpearl.save(nbttagcompound1);
+- DataResult dataresult = MinecraftKey.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, entityenderpearl.level().dimension().location());
++ DataResult dataresult = MinecraftKey.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, entityenderpearl.level().dimension().location()); // CraftBukkit - decompile error
+ Logger logger = EntityPlayer.LOGGER;
+
+ Objects.requireNonNull(logger);
+@@ -653,7 +793,7 @@
+ nbttaglist.forEach((nbtbase1) -> {
+ if (nbtbase1 instanceof NBTTagCompound nbttagcompound) {
+ if (nbttagcompound.contains("ender_pearl_dimension")) {
+- DataResult dataresult = World.RESOURCE_KEY_CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("ender_pearl_dimension"));
++ DataResult> dataresult = World.RESOURCE_KEY_CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("ender_pearl_dimension")); // CraftBukkit - decompile error
+ Logger logger = EntityPlayer.LOGGER;
+
+ Objects.requireNonNull(logger);
+@@ -688,6 +828,29 @@
}
@@ -256,7 +328,7 @@
public void setExperiencePoints(int i) {
float f = (float) this.getXpNeededForNextLevel();
float f1 = (f - 1.0F) / f;
-@@ -533,6 +681,11 @@
+@@ -746,6 +909,11 @@
@Override
public void tick() {
@@ -268,7 +340,7 @@
this.gameMode.tick();
this.wardenSpawnTracker.tick();
--this.spawnInvulnerableTime;
-@@ -613,7 +766,7 @@
+@@ -822,7 +990,7 @@
}
if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) {
@@ -277,7 +349,7 @@
this.lastSentHealth = this.getHealth();
this.lastSentFood = this.foodData.getFoodLevel();
this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F;
-@@ -644,6 +797,12 @@
+@@ -853,6 +1021,12 @@
this.updateScoreForCriteria(IScoreboardCriteria.EXPERIENCE, MathHelper.ceil((float) this.lastRecordedExperience));
}
@@ -290,7 +362,7 @@
if (this.experienceLevel != this.lastRecordedLevel) {
this.lastRecordedLevel = this.experienceLevel;
this.updateScoreForCriteria(IScoreboardCriteria.LEVEL, MathHelper.ceil((float) this.lastRecordedLevel));
-@@ -658,6 +817,20 @@
+@@ -867,6 +1041,20 @@
CriterionTriggers.LOCATION.trigger(this);
}
@@ -311,7 +383,16 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Player being ticked");
-@@ -703,7 +876,8 @@
+@@ -895,7 +1083,7 @@
+ if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL && this.serverLevel().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION)) {
+ if (this.tickCount % 20 == 0) {
+ if (this.getHealth() < this.getMaxHealth()) {
+- this.heal(1.0F);
++ this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN); // CraftBukkit - added regain reason of "REGEN" for filtering purposes.
+ }
+
+ float f = this.foodData.getSaturationLevel();
+@@ -948,7 +1136,8 @@
}
private void updateScoreForCriteria(IScoreboardCriteria iscoreboardcriteria, int i) {
@@ -321,16 +402,16 @@
scoreaccess.set(i);
});
}
-@@ -712,9 +886,47 @@
+@@ -957,9 +1146,47 @@
public void die(DamageSource damagesource) {
this.gameEvent(GameEvent.ENTITY_DIE);
- boolean flag = this.level().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
+ boolean flag = this.serverLevel().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
+ // CraftBukkit start - fire PlayerDeathEvent
+ if (this.isRemoved()) {
+ return;
+ }
+ java.util.List loot = new java.util.ArrayList<>(this.getInventory().getContainerSize());
-+ boolean keepInventory = this.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || this.isSpectator();
++ boolean keepInventory = this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || this.isSpectator();
- if (flag) {
- IChatBaseComponent ichatbasecomponent = this.getCombatTracker().getDeathMessage();
@@ -342,7 +423,7 @@
+ }
+ }
+ // SPIGOT-5071: manually add player loot tables (SPIGOT-5195 - ignores keepInventory rule)
-+ this.dropFromLootTable(damagesource, this.lastHurtByPlayerTime > 0);
++ this.dropFromLootTable(this.serverLevel(), damagesource, this.lastHurtByPlayerTime > 0);
+ this.dropCustomDeathLoot(this.serverLevel(), damagesource, flag);
+
+ loot.addAll(this.drops);
@@ -371,15 +452,15 @@
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> {
boolean flag1 = true;
-@@ -745,12 +957,18 @@
- if (this.level().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
+@@ -990,12 +1217,18 @@
+ if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
this.tellNeutralMobsThatIDied();
}
-
- if (!this.isSpectator()) {
- this.dropAllDeathLoot(this.serverLevel(), damagesource);
+ // SPIGOT-5478 must be called manually now
-+ this.dropExperience(damagesource.getEntity());
++ this.dropExperience(this.serverLevel(), damagesource.getEntity());
+ // we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory.
+ if (!event.getKeepInventory()) {
+ this.getInventory().clearContent();
@@ -394,7 +475,7 @@
EntityLiving entityliving = this.getKillCredit();
if (entityliving != null) {
-@@ -785,10 +1003,12 @@
+@@ -1030,10 +1263,12 @@
if (entity != this) {
super.awardKillScore(entity, i, damagesource);
this.increaseScore(i);
@@ -409,7 +490,7 @@
} else {
this.awardStat(StatisticList.MOB_KILLS);
}
-@@ -806,7 +1026,8 @@
+@@ -1051,7 +1286,8 @@
int i = scoreboardteam.getColor().getId();
if (i >= 0 && i < aiscoreboardcriteria.length) {
@@ -419,7 +500,7 @@
}
}
-@@ -856,10 +1077,16 @@
+@@ -1101,10 +1337,16 @@
}
private boolean isPvpAllowed() {
@@ -428,53 +509,53 @@
+ return this.level().pvpMode;
}
-- public DimensionTransition findRespawnPositionAndUseSpawnBlock(boolean flag, DimensionTransition.a dimensiontransition_a) {
+- public TeleportTransition findRespawnPositionAndUseSpawnBlock(boolean flag, TeleportTransition.a teleporttransition_a) {
+ // CraftBukkit start
-+ public DimensionTransition findRespawnPositionAndUseSpawnBlock(boolean flag, DimensionTransition.a dimensiontransition_a, PlayerRespawnEvent.RespawnReason reason) {
-+ DimensionTransition dimensionTransition;
++ public TeleportTransition findRespawnPositionAndUseSpawnBlock(boolean flag, TeleportTransition.a teleporttransition_a, PlayerRespawnEvent.RespawnReason reason) {
++ TeleportTransition teleportTransition;
+ boolean isBedSpawn = false;
+ boolean isAnchorSpawn = false;
+ // CraftBukkit end
BlockPosition blockposition = this.getRespawnPosition();
float f = this.getRespawnAngle();
boolean flag1 = this.isRespawnForced();
-@@ -871,13 +1098,32 @@
+@@ -1116,13 +1358,32 @@
if (optional.isPresent()) {
EntityPlayer.RespawnPosAngle entityplayer_respawnposangle = (EntityPlayer.RespawnPosAngle) optional.get();
-- return new DimensionTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, dimensiontransition_a);
+- return new TeleportTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, teleporttransition_a);
+ // CraftBukkit start
+ isBedSpawn = entityplayer_respawnposangle.isBedSpawn();
+ isAnchorSpawn = entityplayer_respawnposangle.isAnchorSpawn();
-+ dimensionTransition = new DimensionTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, dimensiontransition_a);
++ teleportTransition = new TeleportTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, teleporttransition_a);
+ // CraftBukkit end
} else {
-- return DimensionTransition.missingRespawnBlock(this.server.overworld(), this, dimensiontransition_a);
-+ dimensionTransition = DimensionTransition.missingRespawnBlock(this.server.overworld(), this, dimensiontransition_a); // CraftBukkit
+- return TeleportTransition.missingRespawnBlock(this.server.overworld(), this, teleporttransition_a);
++ teleportTransition = TeleportTransition.missingRespawnBlock(this.server.overworld(), this, teleporttransition_a); // CraftBukkit
}
} else {
-- return new DimensionTransition(this.server.overworld(), this, dimensiontransition_a);
-+ dimensionTransition = new DimensionTransition(this.server.overworld(), this, dimensiontransition_a); // CraftBukkit
+- return new TeleportTransition(this.server.overworld(), this, teleporttransition_a);
++ teleportTransition = new TeleportTransition(this.server.overworld(), this, teleporttransition_a); // CraftBukkit
}
+ // CraftBukkit start
+ if (reason == null) {
-+ return dimensionTransition;
++ return teleportTransition;
+ }
+
+ Player respawnPlayer = this.getBukkitEntity();
-+ Location location = CraftLocation.toBukkit(dimensionTransition.pos(), dimensionTransition.newLevel().getWorld(), dimensionTransition.yRot(), dimensionTransition.xRot());
++ Location location = CraftLocation.toBukkit(teleportTransition.position(), teleportTransition.newLevel().getWorld(), teleportTransition.yRot(), teleportTransition.xRot());
+
+ PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn, isAnchorSpawn, reason);
+ this.level().getCraftServer().getPluginManager().callEvent(respawnEvent);
+
+ location = respawnEvent.getRespawnLocation();
+
-+ return new DimensionTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), dimensionTransition.speed(), location.getYaw(), location.getPitch(), dimensionTransition.missingRespawnBlock(), dimensionTransition.postDimensionTransition(), dimensionTransition.cause());
++ return new TeleportTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), teleportTransition.deltaMovement(), location.getYaw(), location.getPitch(), teleportTransition.missingRespawnBlock(), teleportTransition.asPassenger(), teleportTransition.relatives(), teleportTransition.postTeleportTransition(), teleportTransition.cause());
+ // CraftBukkit end
}
public static Optional findRespawnAndUseSpawnBlock(WorldServer worldserver, BlockPosition blockposition, float f, boolean flag, boolean flag1) {
-@@ -892,11 +1138,11 @@
+@@ -1137,11 +1398,11 @@
}
return optional.map((vec3d) -> {
@@ -488,7 +569,7 @@
});
} else if (!flag) {
return Optional.empty();
-@@ -905,7 +1151,7 @@
+@@ -1150,7 +1411,7 @@
IBlockData iblockdata1 = worldserver.getBlockState(blockposition.above());
boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1);
@@ -497,32 +578,49 @@
}
}
-@@ -923,6 +1169,7 @@
+@@ -1168,6 +1429,7 @@
@Nullable
@Override
- public Entity changeDimension(DimensionTransition dimensiontransition) {
+ public EntityPlayer teleport(TeleportTransition teleporttransition) {
+ if (this.isSleeping()) return null; // CraftBukkit - SPIGOT-3154
if (this.isRemoved()) {
return null;
} else {
-@@ -932,14 +1179,21 @@
+@@ -1177,18 +1439,38 @@
- WorldServer worldserver = dimensiontransition.newLevel();
+ WorldServer worldserver = teleporttransition.newLevel();
WorldServer worldserver1 = this.serverLevel();
- ResourceKey resourcekey = worldserver1.dimension();
+ // CraftBukkit start
+ ResourceKey resourcekey = worldserver1.getTypeKey();
++
++ Location enter = this.getBukkitEntity().getLocation();
++ PositionMoveRotation absolutePosition = PositionMoveRotation.calculateAbsolute(PositionMoveRotation.of(this), PositionMoveRotation.of(teleporttransition), teleporttransition.relatives());
++ Location exit = (worldserver == null) ? null : CraftLocation.toBukkit(absolutePosition.position(), worldserver.getWorld(), absolutePosition.yRot(), absolutePosition.xRot());
++ PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, teleporttransition.cause());
++ Bukkit.getServer().getPluginManager().callEvent(tpEvent);
++ Location newExit = tpEvent.getTo();
++ if (tpEvent.isCancelled() || newExit == null) {
++ return null;
++ }
++ if (!newExit.equals(exit)) {
++ worldserver = ((CraftWorld) newExit.getWorld()).getHandle();
++ teleporttransition = new TeleportTransition(worldserver, CraftLocation.toVec3D(newExit), Vec3D.ZERO, newExit.getYaw(), newExit.getPitch(), teleporttransition.missingRespawnBlock(), teleporttransition.asPassenger(), Set.of(), teleporttransition.postTeleportTransition(), teleporttransition.cause());
++ }
++ // CraftBukkit end
+
+ if (!teleporttransition.asPassenger()) {
+ this.stopRiding();
+ }
- if (worldserver.dimension() == resourcekey) {
-- this.connection.teleport(dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), dimensiontransition.xRot());
-+ if (worldserver != null && worldserver.dimension() == worldserver1.dimension()) { // CraftBukkit
-+ boolean result = this.connection.teleport(dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), dimensiontransition.xRot(), dimensiontransition.cause());
-+ if (!result) {
-+ return null;
-+ }
+- this.connection.teleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives());
++ // CraftBukkit start
++ if (worldserver != null && worldserver.dimension() == worldserver1.dimension()) {
++ this.connection.internalTeleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives());
+ // CraftBukkit end
this.connection.resetPosition();
- dimensiontransition.postDimensionTransition().onTransition(this);
+ teleporttransition.postTeleportTransition().onTransition(this);
return this;
} else {
+ // CraftBukkit start
@@ -530,31 +628,22 @@
this.isChangingDimension = true;
WorldData worlddata = worldserver.getLevelData();
-@@ -950,15 +1204,40 @@
+@@ -1199,17 +1481,31 @@
playerlist.sendPlayerPermissionLevel(this);
worldserver1.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION);
this.unsetRemoved();
+ */
+ // CraftBukkit end
- worldserver1.getProfiler().push("moving");
+ GameProfilerFiller gameprofilerfiller = Profiler.get();
+
+ gameprofilerfiller.push("moving");
- if (resourcekey == World.OVERWORLD && worldserver.dimension() == World.NETHER) {
+ if (worldserver != null && resourcekey == WorldDimension.OVERWORLD && worldserver.getTypeKey() == WorldDimension.NETHER) { // CraftBukkit - empty to fall through to null to event
this.enteredNetherPosition = this.position();
}
-+ // CraftBukkit start
-+ Location enter = this.getBukkitEntity().getLocation();
-+ Location exit = (worldserver == null) ? null : CraftLocation.toBukkit(dimensiontransition.pos(), worldserver.getWorld(), dimensiontransition.yRot(), dimensiontransition.xRot());
-+ PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, dimensiontransition.cause());
-+ Bukkit.getServer().getPluginManager().callEvent(tpEvent);
-+ if (tpEvent.isCancelled() || tpEvent.getTo() == null) {
-+ return null;
-+ }
-+ exit = tpEvent.getTo();
-+ worldserver = ((CraftWorld) exit.getWorld()).getHandle();
-+ // CraftBukkit end
- worldserver1.getProfiler().pop();
- worldserver1.getProfiler().push("placing");
+ gameprofilerfiller.pop();
+ gameprofilerfiller.push("placing");
+ // CraftBukkit start
+ this.isChangingDimension = true; // CraftBukkit - Set teleport invulnerability only if player changing worlds
+ WorldData worlddata = worldserver.getLevelData();
@@ -568,12 +657,12 @@
+ this.unsetRemoved();
+ // CraftBukkit end
this.setServerLevel(worldserver);
-- this.connection.teleport(dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), dimensiontransition.xRot());
-+ this.connection.teleport(exit); // CraftBukkit - use internal teleport without event
+- this.connection.teleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives());
++ this.connection.internalTeleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives()); // CraftBukkit - use internal teleport without event
this.connection.resetPosition();
worldserver.addDuringTeleport(this);
- worldserver1.getProfiler().pop();
-@@ -971,21 +1250,47 @@
+ gameprofilerfiller.pop();
+@@ -1223,11 +1519,29 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@@ -600,6 +689,10 @@
+ }
+ // CraftBukkit end
+
+ @Override
+ public void forceSetRotation(float f, float f1) {
+ this.connection.send(new ClientboundPlayerRotationPacket(f, f1));
+@@ -1236,13 +1550,21 @@
public void triggerDimensionChangeTriggers(WorldServer worldserver) {
ResourceKey resourcekey = worldserver.dimension();
ResourceKey resourcekey1 = this.level().dimension();
@@ -624,7 +717,7 @@
this.enteredNetherPosition = null;
}
-@@ -1002,19 +1307,17 @@
+@@ -1259,19 +1581,17 @@
this.containerMenu.broadcastChanges();
}
@@ -648,7 +741,7 @@
if (this.level().isDay()) {
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_NOW);
} else {
-@@ -1031,7 +1334,36 @@
+@@ -1288,7 +1608,36 @@
}
}
@@ -686,7 +779,7 @@
this.awardStat(StatisticList.SLEEP_IN_BED);
CriterionTriggers.SLEPT_IN_BED.trigger(this);
});
-@@ -1044,9 +1376,8 @@
+@@ -1301,9 +1650,8 @@
return either;
}
}
@@ -697,7 +790,7 @@
}
@Override
-@@ -1073,13 +1404,31 @@
+@@ -1330,13 +1678,31 @@
@Override
public void stopSleepInBed(boolean flag, boolean flag1) {
@@ -730,7 +823,7 @@
}
}
-@@ -1146,8 +1495,9 @@
+@@ -1403,8 +1769,9 @@
this.connection.send(new PacketPlayOutOpenSignEditor(tileentitysign.getBlockPos(), flag));
}
@@ -741,7 +834,7 @@
}
@Override
-@@ -1155,13 +1505,35 @@
+@@ -1412,13 +1779,35 @@
if (itileinventory == null) {
return OptionalInt.empty();
} else {
@@ -777,7 +870,7 @@
if (container == null) {
if (this.isSpectator()) {
this.displayClientMessage(IChatBaseComponent.translatable("container.spectatorCantOpen").withStyle(EnumChatFormat.RED), true);
-@@ -1169,9 +1541,11 @@
+@@ -1426,9 +1815,11 @@
return OptionalInt.empty();
} else {
@@ -791,7 +884,7 @@
return OptionalInt.of(this.containerCounter);
}
}
-@@ -1184,15 +1558,26 @@
+@@ -1441,15 +1832,26 @@
@Override
public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) {
@@ -820,7 +913,7 @@
this.initMenu(this.containerMenu);
}
-@@ -1215,6 +1600,7 @@
+@@ -1472,6 +1874,7 @@
@Override
public void closeContainer() {
@@ -828,24 +921,7 @@
this.connection.send(new PacketPlayOutCloseWindow(this.containerMenu.containerId));
this.doCloseContainer();
}
-@@ -1237,6 +1623,16 @@
- }
-
- this.jumping = flag;
-+ // CraftBukkit start
-+ if (flag1 != this.isShiftKeyDown()) {
-+ PlayerToggleSneakEvent event = new PlayerToggleSneakEvent(this.getBukkitEntity(), flag1);
-+ this.server.server.getPluginManager().callEvent(event);
-+
-+ if (event.isCancelled()) {
-+ return;
-+ }
-+ }
-+ // CraftBukkit end
- this.setShiftKeyDown(flag1);
- }
-
-@@ -1270,19 +1666,19 @@
+@@ -1501,19 +1904,19 @@
i = Math.round((float) Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F);
if (i > 0) {
this.awardStat(StatisticList.SWIM_ONE_CM, i);
@@ -868,7 +944,7 @@
}
} else if (this.onClimbable()) {
if (d1 > 0.0D) {
-@@ -1293,13 +1689,13 @@
+@@ -1524,13 +1927,13 @@
if (i > 0) {
if (this.isSprinting()) {
this.awardStat(StatisticList.SPRINT_ONE_CM, i);
@@ -885,7 +961,7 @@
}
}
} else if (this.isFallFlying()) {
-@@ -1342,7 +1738,7 @@
+@@ -1573,7 +1976,7 @@
@Override
public void awardStat(Statistic> statistic, int i) {
this.stats.increment(this, statistic, i);
@@ -894,7 +970,7 @@
scoreaccess.add(i);
});
}
-@@ -1350,7 +1746,7 @@
+@@ -1581,7 +1984,7 @@
@Override
public void resetStat(Statistic> statistic) {
this.stats.setValue(this, statistic, 0);
@@ -903,7 +979,19 @@
}
@Override
-@@ -1398,6 +1794,7 @@
+@@ -1613,9 +2016,9 @@
+ super.jumpFromGround();
+ this.awardStat(StatisticList.JUMP);
+ if (this.isSprinting()) {
+- this.causeFoodExhaustion(0.2F);
++ this.causeFoodExhaustion(0.2F, EntityExhaustionEvent.ExhaustionReason.JUMP_SPRINT); // CraftBukkit - EntityExhaustionEvent
+ } else {
+- this.causeFoodExhaustion(0.05F);
++ this.causeFoodExhaustion(0.05F, EntityExhaustionEvent.ExhaustionReason.JUMP); // CraftBukkit - EntityExhaustionEvent
+ }
+
+ }
+@@ -1641,6 +2044,7 @@
public void resetSentInfo() {
this.lastSentHealth = -1.0E8F;
@@ -911,16 +999,7 @@
}
@Override
-@@ -1433,7 +1830,7 @@
- this.gameMode.setGameModeForPlayer(entityplayer.gameMode.getGameModeForPlayer(), entityplayer.gameMode.getPreviousGameModeForPlayer());
- this.onUpdateAbilities();
- this.getAttributes().assignBaseValues(entityplayer.getAttributes());
-- this.setHealth(this.getMaxHealth());
-+ // this.setHealth(this.getMaxHealth()); // CraftBukkit
- if (flag) {
- this.getInventory().replaceWith(entityplayer.getInventory());
- this.setHealth(entityplayer.getHealth());
-@@ -1443,7 +1840,7 @@
+@@ -1685,7 +2089,7 @@
while (iterator.hasNext()) {
MobEffect mobeffect = (MobEffect) iterator.next();
@@ -928,8 +1007,17 @@
+ // this.addEffect(new MobEffect(mobeffect)); // CraftBukkit
}
- this.experienceLevel = entityplayer.experienceLevel;
-@@ -1465,7 +1862,7 @@
+ this.getInventory().replaceWith(entityplayer.getInventory());
+@@ -1696,7 +2100,7 @@
+ this.portalProcess = entityplayer.portalProcess;
+ } else {
+ this.getAttributes().assignBaseValues(entityplayer.getAttributes());
+- this.setHealth(this.getMaxHealth());
++ // this.setHealth(this.getMaxHealth()); // CraftBukkit
+ if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || entityplayer.isSpectator()) {
+ this.getInventory().replaceWith(entityplayer.getInventory());
+ this.experienceLevel = entityplayer.experienceLevel;
+@@ -1712,7 +2116,7 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@@ -938,32 +1026,25 @@
this.seenCredits = entityplayer.seenCredits;
this.enteredNetherPosition = entityplayer.enteredNetherPosition;
this.chunkTrackingView = entityplayer.chunkTrackingView;
-@@ -1516,6 +1913,12 @@
+@@ -1768,7 +2172,7 @@
+ }
@Override
- public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1) {
-+ // CraftBukkit start
-+ return teleportTo(worldserver, d0, d1, d2, set, f, f1, TeleportCause.UNKNOWN);
-+ }
-+
-+ public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1, TeleportCause cause) {
-+ // CraftBukkit end
+- public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1, boolean flag) {
++ public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1, boolean flag, TeleportCause cause) { // CraftBukkit
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(BlockPosition.containing(d0, d1, d2));
worldserver.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkcoordintpair, 1, this.getId());
-@@ -1525,9 +1928,9 @@
+@@ -1780,7 +2184,7 @@
+ this.setCamera(this);
}
- if (worldserver == this.level()) {
-- this.connection.teleport(d0, d1, d2, f, f1, set);
-+ this.connection.teleport(d0, d1, d2, f, f1, set, cause); // CraftBukkit
- } else {
-- this.teleportTo(worldserver, d0, d1, d2, f, f1);
-+ this.teleportTo(worldserver, d0, d1, d2, f, f1, cause); // CraftBukkit
- }
+- boolean flag1 = super.teleportTo(worldserver, d0, d1, d2, set, f, f1, flag);
++ boolean flag1 = super.teleportTo(worldserver, d0, d1, d2, set, f, f1, flag, cause); // CraftBukkit
- this.setYHeadRot(f);
-@@ -1635,6 +2038,16 @@
+ if (flag1) {
+ this.setYHeadRot(set.contains(Relative.Y_ROT) ? this.getYHeadRot() + f : f);
+@@ -1897,6 +2301,16 @@
}
public void updateOptions(ClientInformation clientinformation) {
@@ -980,16 +1061,16 @@
this.language = clientinformation.language();
this.requestedViewDistance = clientinformation.viewDistance();
this.chatVisibility = clientinformation.chatVisibility();
-@@ -1718,7 +2131,7 @@
+@@ -1981,7 +2395,7 @@
if (world instanceof WorldServer) {
WorldServer worldserver = (WorldServer) world;
-- this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot());
-+ this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), TeleportCause.SPECTATE); // CraftBukkit
+- this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), false);
++ this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), false, TeleportCause.SPECTATE); // CraftBukkit
}
if (entity != null) {
-@@ -1755,7 +2168,7 @@
+@@ -2018,11 +2432,11 @@
@Nullable
public IChatBaseComponent getTabListDisplayName() {
@@ -997,33 +1078,13 @@
+ return listName; // CraftBukkit
}
- @Override
-@@ -1776,14 +2189,24 @@
- return this.advancements;
- }
-
-+ // CraftBukkit start
- public void teleportTo(WorldServer worldserver, double d0, double d1, double d2, float f, float f1) {
-+ this.teleportTo(worldserver, d0, d1, d2, f, f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.UNKNOWN);
-+ }
-+
-+ public void teleportTo(WorldServer worldserver, double d0, double d1, double d2, float f, float f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
-+ // CraftBukkit end
- this.setCamera(this);
- this.stopRiding();
-+ /* CraftBukkit start - replace with bukkit handling for multi-world
- if (worldserver == this.level()) {
- this.connection.teleport(d0, d1, d2, f, f1);
- } else {
- this.changeDimension(new DimensionTransition(worldserver, new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f1, DimensionTransition.DO_NOTHING));
- }
-+ */
-+ this.getBukkitEntity().teleport(new Location(worldserver.getWorld(), d0, d1, d2, f, f1), cause);
-+ // CraftBukkit end
-
+ public int getTabListOrder() {
+- return 0;
++ return listOrder; // CraftBukkit
}
-@@ -1809,6 +2232,32 @@
+ @Override
+@@ -2065,6 +2479,32 @@
}
public void setRespawnPosition(ResourceKey resourcekey, @Nullable BlockPosition blockposition, float f, boolean flag, boolean flag1) {
@@ -1056,24 +1117,48 @@
if (blockposition != null) {
boolean flag2 = blockposition.equals(this.respawnPosition) && resourcekey.equals(this.respawnDimension);
-@@ -1852,7 +2301,14 @@
+@@ -2107,12 +2547,38 @@
+ }
@Override
- public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) {
-- EntityItem entityitem = super.drop(itemstack, flag, flag1);
-+ // CraftBukkit start - SPIGOT-2942: Add boolean to call event
-+ return drop(itemstack, flag, flag1, true);
-+ }
-+
-+ @Override
-+ public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1, boolean callEvent) {
-+ EntityItem entityitem = super.drop(itemstack, flag, flag1, callEvent);
-+ // CraftBukkit end
+- public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) {
++ public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1, boolean callEvent) { // CraftBukkit - SPIGOT-2942: Add boolean to call event
+ EntityItem entityitem = this.createItemStackToDrop(itemstack, flag, flag1);
if (entityitem == null) {
return null;
-@@ -2049,10 +2505,12 @@
- this.awardStat(StatisticList.ITEM_BROKEN.get(item));
+ } else {
++ // CraftBukkit start - fire PlayerDropItemEvent
++ if (callEvent) {
++ Player player = (Player) this.getBukkitEntity();
++ org.bukkit.entity.Item drop = (org.bukkit.entity.Item) entityitem.getBukkitEntity();
++
++ PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop);
++ this.level().getCraftServer().getPluginManager().callEvent(event);
++
++ if (event.isCancelled()) {
++ org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand();
++ if (flag1 && (cur == null || cur.getAmount() == 0)) {
++ // The complete stack was dropped
++ player.getInventory().setItemInHand(drop.getItemStack());
++ } else if (flag1 && cur.isSimilar(drop.getItemStack()) && cur.getAmount() < cur.getMaxStackSize() && drop.getItemStack().getAmount() == 1) {
++ // Only one item is dropped
++ cur.setAmount(cur.getAmount() + 1);
++ player.getInventory().setItemInHand(cur);
++ } else {
++ // Fallback
++ player.getInventory().addItem(drop.getItemStack());
++ }
++ return null;
++ }
++ }
++ // CraftBukkit end
++
+ this.level().addFreshEntity(entityitem);
+ ItemStack itemstack1 = entityitem.getItem();
+
+@@ -2394,10 +2860,12 @@
+ return TicketType.ENDER_PEARL.timeout();
}
- public static record RespawnPosAngle(Vec3D position, float yaw) {
@@ -1088,7 +1173,7 @@
}
private static float calculateLookAtYaw(Vec3D vec3d, BlockPosition blockposition) {
-@@ -2061,4 +2519,147 @@
+@@ -2406,4 +2874,146 @@
return (float) MathHelper.wrapDegrees(MathHelper.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
}
}
@@ -1195,7 +1280,6 @@
+
+ public void reset() {
+ float exp = 0;
-+ boolean keepInventory = this.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY);
+
+ if (this.keepLevel) { // CraftBukkit - SPIGOT-6687: Only use keepLevel (was pre-set with RULE_KEEPINVENTORY value in PlayerDeathEvent)
+ exp = this.experienceProgress;
@@ -1207,7 +1291,7 @@
+ this.stopUsingItem(); // CraftBukkit - SPIGOT-6682: Clear active item on reset
+ this.setRemainingFireTicks(0);
+ this.fallDistance = 0;
-+ this.foodData = new FoodMetaData(this);
++ this.foodData = new FoodMetaData();
+ this.experienceLevel = this.newLevel;
+ this.totalExperience = this.newTotalExp;
+ this.experienceProgress = 0;
diff --git a/nms-patches/net/minecraft/server/level/EntityTrackerEntry.patch b/nms-patches/net/minecraft/server/level/EntityTrackerEntry.patch
index f8ac888b..1e4584f0 100644
--- a/nms-patches/net/minecraft/server/level/EntityTrackerEntry.patch
+++ b/nms-patches/net/minecraft/server/level/EntityTrackerEntry.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/EntityTrackerEntry.java
+++ b/net/minecraft/server/level/EntityTrackerEntry.java
-@@ -46,6 +46,12 @@
+@@ -50,6 +50,12 @@
import net.minecraft.world.phys.Vec3D;
import org.slf4j.Logger;
@@ -13,7 +13,7 @@
public class EntityTrackerEntry {
private static final Logger LOGGER = LogUtils.getLogger();
-@@ -70,8 +76,12 @@
+@@ -74,8 +80,12 @@
private boolean wasOnGround;
@Nullable
private List> trackedDataValues;
@@ -27,7 +27,7 @@
this.level = worldserver;
this.broadcast = consumer;
this.entity = entity;
-@@ -90,7 +100,7 @@
+@@ -94,7 +104,7 @@
List list = this.entity.getPassengers();
if (!list.equals(this.lastPassengers)) {
@@ -36,7 +36,7 @@
removedPassengers(list, this.lastPassengers).forEach((entity) -> {
if (entity instanceof EntityPlayer entityplayer) {
entityplayer.connection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot());
-@@ -103,18 +113,18 @@
+@@ -107,18 +117,18 @@
Entity entity = this.entity;
if (entity instanceof EntityItemFrame entityitemframe) {
@@ -59,7 +59,7 @@
worldmap.tickCarriedBy(entityplayer, itemstack);
Packet> packet = worldmap.getUpdatePacket(mapid, entityplayer);
-@@ -232,6 +242,27 @@
+@@ -248,6 +258,27 @@
++this.tickCount;
if (this.entity.hurtMarked) {
@@ -87,7 +87,7 @@
this.entity.hurtMarked = false;
this.broadcastAndSend(new PacketPlayOutEntityVelocity(this.entity));
}
-@@ -260,7 +291,10 @@
+@@ -298,7 +329,10 @@
public void sendPairingData(EntityPlayer entityplayer, Consumer> consumer) {
if (this.entity.isRemoved()) {
@@ -99,7 +99,7 @@
}
Packet packet = this.entity.getAddEntityPacket(this);
-@@ -275,6 +309,12 @@
+@@ -313,6 +347,12 @@
if (this.entity instanceof EntityLiving) {
Collection collection = ((EntityLiving) this.entity).getAttributes().getSyncableAttributes();
@@ -112,7 +112,7 @@
if (!collection.isEmpty()) {
consumer.accept(new PacketPlayOutUpdateAttributes(this.entity.getId(), collection));
}
-@@ -305,6 +345,7 @@
+@@ -344,6 +384,7 @@
if (!list.isEmpty()) {
consumer.accept(new PacketPlayOutEntityEquipment(this.entity.getId(), list));
}
@@ -120,7 +120,7 @@
}
if (!this.entity.getPassengers().isEmpty()) {
-@@ -358,6 +399,11 @@
+@@ -396,6 +437,11 @@
Set set = ((EntityLiving) this.entity).getAttributes().getAttributesToSync();
if (!set.isEmpty()) {
diff --git a/nms-patches/net/minecraft/server/level/PlayerChunk.patch b/nms-patches/net/minecraft/server/level/PlayerChunk.patch
index 085ee7e4..8cdc5508 100644
--- a/nms-patches/net/minecraft/server/level/PlayerChunk.patch
+++ b/nms-patches/net/minecraft/server/level/PlayerChunk.patch
@@ -52,15 +52,15 @@
}
@Nullable
-@@ -134,6 +150,7 @@
- if (chunk != null) {
+@@ -138,6 +154,7 @@
+ boolean flag = this.hasChangedSections;
int i = this.levelHeightAccessor.getSectionIndex(blockposition.getY());
-+ if (i < 0 || i >= this.changedBlocksPerSection.length) return; // CraftBukkit - SPIGOT-6086, SPIGOT-6296
++ if (i < 0 || i >= this.changedBlocksPerSection.length) return false; // CraftBukkit - SPIGOT-6086, SPIGOT-6296
if (this.changedBlocksPerSection[i] == null) {
this.hasChangedSections = true;
this.changedBlocksPerSection[i] = new ShortOpenHashSet();
-@@ -208,8 +225,11 @@
+@@ -224,8 +241,11 @@
PacketPlayOutMultiBlockChange packetplayoutmultiblockchange = new PacketPlayOutMultiBlockChange(sectionposition, shortset, chunksection);
this.broadcast(list, packetplayoutmultiblockchange);
@@ -73,7 +73,7 @@
});
}
}
-@@ -275,7 +295,7 @@
+@@ -291,7 +311,7 @@
this.pendingFullStateConfirmation = completablefuture1;
completablefuture.thenAccept((chunkresult) -> {
chunkresult.ifSuccess((chunk) -> {
@@ -82,13 +82,19 @@
});
});
}
-@@ -290,6 +310,30 @@
- FullChunkStatus fullchunkstatus1 = ChunkLevel.fullStatus(this.ticketLevel);
- boolean flag = fullchunkstatus.isOrAfter(FullChunkStatus.FULL);
- boolean flag1 = fullchunkstatus1.isOrAfter(FullChunkStatus.FULL);
-+ // CraftBukkit start
-+ // ChunkUnloadEvent: Called before the chunk is unloaded: isChunkLoaded is still true and chunk can still be modified by plugins.
-+ if (flag && !flag1) {
+@@ -301,6 +321,38 @@
+ playerchunkmap.onFullChunkStatusChange(this.pos, fullchunkstatus);
+ }
+
++ // CraftBukkit start
++ // ChunkUnloadEvent: Called before the chunk is unloaded: isChunkLoaded is still true and chunk can still be modified by plugins.
++ // SPIGOT-7780: Moved out of updateFutures to call all chunk unload events before calling updateHighestAllowedStatus for all chunks
++ protected void callEventIfUnloading(PlayerChunkMap playerchunkmap) {
++ FullChunkStatus oldFullChunkStatus = ChunkLevel.fullStatus(this.oldTicketLevel);
++ FullChunkStatus newFullChunkStatus = ChunkLevel.fullStatus(this.ticketLevel);
++ boolean oldIsFull = oldFullChunkStatus.isOrAfter(FullChunkStatus.FULL);
++ boolean newIsFull = newFullChunkStatus.isOrAfter(FullChunkStatus.FULL);
++ if (oldIsFull && !newIsFull) {
+ this.getFullChunkFuture().thenAccept((either) -> {
+ Chunk chunk = (Chunk) either.orElse(null);
+ if (chunk != null) {
@@ -96,7 +102,7 @@
+ // Minecraft will apply the chunks tick lists to the world once the chunk got loaded, and then store the tick
+ // lists again inside the chunk once the chunk becomes inaccessible and set the chunk's needsSaving flag.
+ // These actions may however happen deferred, so we manually set the needsSaving flag already here.
-+ chunk.setUnsaved(true);
++ chunk.markUnsaved();
+ chunk.unloadCallback();
+ });
+ }
@@ -109,11 +115,13 @@
+ // Run callback right away if the future was already done
+ playerchunkmap.callbackExecutor.run();
+ }
-+ // CraftBukkit end
-
- this.wasAccessibleSinceLastSave |= flag1;
- if (!flag && flag1) {
-@@ -341,6 +385,26 @@
++ }
++ // CraftBukkit end
++
+ protected void updateFutures(PlayerChunkMap playerchunkmap, Executor executor) {
+ FullChunkStatus fullchunkstatus = ChunkLevel.fullStatus(this.oldTicketLevel);
+ FullChunkStatus fullchunkstatus1 = ChunkLevel.fullStatus(this.ticketLevel);
+@@ -357,6 +409,26 @@
this.onLevelChange.onLevelChange(this.pos, this::getQueueLevel, this.ticketLevel, this::setQueueLevel);
this.oldTicketLevel = this.ticketLevel;
diff --git a/nms-patches/net/minecraft/server/level/PlayerChunkMap.patch b/nms-patches/net/minecraft/server/level/PlayerChunkMap.patch
index f6390c0e..91440ae9 100644
--- a/nms-patches/net/minecraft/server/level/PlayerChunkMap.patch
+++ b/nms-patches/net/minecraft/server/level/PlayerChunkMap.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/PlayerChunkMap.java
+++ b/net/minecraft/server/level/PlayerChunkMap.java
-@@ -102,6 +102,10 @@
+@@ -104,6 +104,10 @@
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.slf4j.Logger;
@@ -11,7 +11,7 @@
public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.b, GeneratingChunkMap {
private static final ChunkResult> UNLOADED_CHUNK_LIST_RESULT = ChunkResult.error("Unloaded chunks found in range");
-@@ -145,6 +149,27 @@
+@@ -149,6 +153,27 @@
public int serverViewDistance;
private final WorldGenContext worldGenContext;
@@ -39,7 +39,7 @@
public PlayerChunkMap(WorldServer worldserver, Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, StructureTemplateManager structuretemplatemanager, Executor executor, IAsyncTaskHandler iasynctaskhandler, ILightAccess ilightaccess, ChunkGenerator chunkgenerator, WorldLoadListener worldloadlistener, ChunkStatusUpdateListener chunkstatusupdatelistener, Supplier supplier, int i, boolean flag) {
super(new RegionStorageInfo(convertable_conversionsession.getLevelId(), worldserver.dimension(), "chunk"), convertable_conversionsession.getDimensionPath(worldserver.dimension()).resolve("region"), datafixer, flag);
this.visibleChunkMap = this.updatingChunkMap.clone();
-@@ -164,7 +189,13 @@
+@@ -170,7 +195,13 @@
IRegistryCustom iregistrycustom = worldserver.registryAccess();
long j = worldserver.getSeed();
@@ -54,7 +54,7 @@
this.randomState = RandomState.create((GeneratorSettingBase) chunkgeneratorabstract.generatorSettings().value(), (HolderGetter) iregistrycustom.lookupOrThrow(Registries.NOISE), j);
} else {
this.randomState = RandomState.create(GeneratorSettingBase.dummy(), (HolderGetter) iregistrycustom.lookupOrThrow(Registries.NOISE), j);
-@@ -318,7 +349,7 @@
+@@ -325,7 +356,7 @@
throw this.debugFuturesAndCreateReportedException(new IllegalStateException("At least one of the chunk futures were null"), "n/a");
}
@@ -63,7 +63,7 @@
if (ichunkaccess == null) {
return PlayerChunkMap.UNLOADED_CHUNK_LIST_RESULT;
-@@ -937,7 +968,8 @@
+@@ -977,7 +1008,8 @@
return ichunkaccess instanceof Chunk ? Optional.of((Chunk) ichunkaccess) : Optional.empty();
});
@@ -73,7 +73,7 @@
return chunk.getBlockEntities().size();
}).orElse(0), tickingtracker.getTicketDebugString(i), tickingtracker.getLevel(i), optional1.map((chunk) -> {
return chunk.getBlockTicks().count();
-@@ -950,7 +982,7 @@
+@@ -990,7 +1022,7 @@
private static String printFuture(CompletableFuture> completablefuture) {
try {
@@ -82,13 +82,13 @@
return chunkresult != null ? (chunkresult.isSuccess() ? "done" : "unloaded") : "not completed";
} catch (CompletionException completionexception) {
-@@ -962,12 +994,14 @@
+@@ -1002,12 +1034,14 @@
private CompletableFuture> readChunk(ChunkCoordIntPair chunkcoordintpair) {
return this.read(chunkcoordintpair).thenApplyAsync((optional) -> {
- return optional.map(this::upgradeChunkTag);
+ return optional.map((nbttagcompound) -> upgradeChunkTag(nbttagcompound, chunkcoordintpair)); // CraftBukkit
- }, SystemUtils.backgroundExecutor());
+ }, SystemUtils.backgroundExecutor().forName("upgradeChunk"));
}
- private NBTTagCompound upgradeChunkTag(NBTTagCompound nbttagcompound) {
@@ -99,8 +99,8 @@
+ // CraftBukkit end
}
- boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair) {
-@@ -1370,7 +1404,7 @@
+ void forEachSpawnCandidateChunk(Consumer consumer) {
+@@ -1424,7 +1458,7 @@
public final Set seenBy = Sets.newIdentityHashSet();
public EntityTracker(final Entity entity, final int i, final int j, final boolean flag) {
@@ -109,7 +109,7 @@
this.entity = entity;
this.range = i;
this.lastSectionPos = SectionPosition.of((EntityAccess) entity);
-@@ -1430,6 +1464,11 @@
+@@ -1484,6 +1518,11 @@
double d2 = d0 * d0;
boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(entityplayer) && PlayerChunkMap.this.isChunkTracked(entityplayer, this.entity.chunkPosition().x, this.entity.chunkPosition().z);
diff --git a/nms-patches/net/minecraft/server/level/PlayerInteractManager.patch b/nms-patches/net/minecraft/server/level/PlayerInteractManager.patch
index a82ef80b..5826f84b 100644
--- a/nms-patches/net/minecraft/server/level/PlayerInteractManager.patch
+++ b/nms-patches/net/minecraft/server/level/PlayerInteractManager.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/PlayerInteractManager.java
+++ b/net/minecraft/server/level/PlayerInteractManager.java
-@@ -28,6 +28,27 @@
+@@ -26,6 +26,27 @@
import net.minecraft.world.phys.Vec3D;
import org.slf4j.Logger;
@@ -28,7 +28,7 @@
public class PlayerInteractManager {
private static final Logger LOGGER = LogUtils.getLogger();
-@@ -58,9 +79,16 @@
+@@ -56,9 +77,16 @@
if (enumgamemode == this.gameModeForPlayer) {
return false;
} else {
@@ -46,7 +46,7 @@
this.level.updateSleepingPlayerList();
if (enumgamemode == EnumGamemode.CREATIVE) {
this.player.resetCurrentImpulseContext();
-@@ -94,7 +122,7 @@
+@@ -92,7 +120,7 @@
}
public void tick() {
@@ -55,7 +55,7 @@
IBlockData iblockdata;
if (this.hasDelayedDestroy) {
-@@ -148,11 +176,33 @@
+@@ -146,11 +174,33 @@
if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.START_DESTROY_BLOCK) {
if (!this.level.mayInteract(this.player, blockposition)) {
@@ -89,7 +89,7 @@
if (this.isCreative()) {
this.destroyAndAck(blockposition, j, "creative destroy");
return;
-@@ -168,7 +218,19 @@
+@@ -166,7 +216,19 @@
float f = 1.0F;
iblockdata = this.level.getBlockState(blockposition);
@@ -110,7 +110,7 @@
EnchantmentManager.onHitBlock(this.level, this.player.getMainHandItem(), this.player, this.player, EnumItemSlot.MAINHAND, Vec3D.atCenterOf(blockposition), iblockdata, (item) -> {
this.player.onEquippedItemBroken(item, EnumItemSlot.MAINHAND);
});
-@@ -176,6 +238,26 @@
+@@ -174,6 +236,26 @@
f = iblockdata.getDestroyProgress(this.player, this.player.level(), blockposition);
}
@@ -137,7 +137,7 @@
if (!iblockdata.isAir() && f >= 1.0F) {
this.destroyAndAck(blockposition, j, "insta mine");
} else {
-@@ -220,13 +302,15 @@
+@@ -218,13 +300,15 @@
} else if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.ABORT_DESTROY_BLOCK) {
this.isDestroyingBlock = false;
if (!Objects.equals(this.destroyPos, blockposition)) {
@@ -154,7 +154,7 @@
}
}
-@@ -244,10 +328,65 @@
+@@ -242,10 +326,65 @@
public boolean destroyBlock(BlockPosition blockposition) {
IBlockData iblockdata = this.level.getBlockState(blockposition);
@@ -221,7 +221,7 @@
TileEntity tileentity = this.level.getBlockEntity(blockposition);
Block block = iblockdata.getBlock();
-@@ -257,6 +396,10 @@
+@@ -255,6 +394,10 @@
} else if (this.player.blockActionRestricted(this.level, blockposition, this.gameModeForPlayer)) {
return false;
} else {
@@ -232,7 +232,7 @@
IBlockData iblockdata1 = block.playerWillDestroy(this.level, blockposition, iblockdata, this.player);
boolean flag = this.level.removeBlock(blockposition, false);
-@@ -265,19 +408,32 @@
+@@ -263,19 +406,32 @@
}
if (this.isCreative()) {
@@ -268,7 +268,7 @@
}
}
}
-@@ -315,14 +471,53 @@
+@@ -321,14 +477,53 @@
}
}
@@ -290,7 +290,7 @@
+ cancelledBlock = !(itileinventory instanceof ITileInventory);
+ }
+
-+ if (entityplayer.getCooldowns().isOnCooldown(itemstack.getItem())) {
++ if (entityplayer.getCooldowns().isOnCooldown(itemstack)) {
+ cancelledBlock = true;
+ }
+
@@ -322,11 +322,11 @@
if (itileinventory != null) {
entityplayer.openMenu(itileinventory);
-@@ -353,7 +548,7 @@
+@@ -359,7 +554,7 @@
}
}
-- if (!itemstack.isEmpty() && !entityplayer.getCooldowns().isOnCooldown(itemstack.getItem())) {
+- if (!itemstack.isEmpty() && !entityplayer.getCooldowns().isOnCooldown(itemstack)) {
+ if (!itemstack.isEmpty() && !interactResult) { // add !interactResult SPIGOT-764
ItemActionContext itemactioncontext = new ItemActionContext(entityplayer, enumhand, movingobjectpositionblock);
diff --git a/nms-patches/net/minecraft/server/level/TicketType.patch b/nms-patches/net/minecraft/server/level/TicketType.patch
index a83c57b3..64176430 100644
--- a/nms-patches/net/minecraft/server/level/TicketType.patch
+++ b/nms-patches/net/minecraft/server/level/TicketType.patch
@@ -1,7 +1,7 @@
--- a/net/minecraft/server/level/TicketType.java
+++ b/net/minecraft/server/level/TicketType.java
-@@ -22,6 +22,8 @@
- public static final TicketType PORTAL = create("portal", BaseBlockPosition::compareTo, 300);
+@@ -23,6 +23,8 @@
+ public static final TicketType ENDER_PEARL = create("ender_pearl", Comparator.comparingLong(ChunkCoordIntPair::toLong), 40);
public static final TicketType POST_TELEPORT = create("post_teleport", Integer::compareTo, 5);
public static final TicketType UNKNOWN = create("unknown", Comparator.comparingLong(ChunkCoordIntPair::toLong), 1);
+ public static final TicketType PLUGIN = create("plugin", (a, b) -> 0); // CraftBukkit
diff --git a/nms-patches/net/minecraft/server/level/WorldServer.patch b/nms-patches/net/minecraft/server/level/WorldServer.patch
index 2327d7de..170108a5 100644
--- a/nms-patches/net/minecraft/server/level/WorldServer.patch
+++ b/nms-patches/net/minecraft/server/level/WorldServer.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/WorldServer.java
+++ b/net/minecraft/server/level/WorldServer.java
-@@ -171,6 +171,23 @@
+@@ -173,6 +173,23 @@
import net.minecraft.world.ticks.TickListServer;
import org.slf4j.Logger;
@@ -21,31 +21,28 @@
+import org.bukkit.event.world.TimeSkipEvent;
+// CraftBukkit end
+
- public class WorldServer extends World implements GeneratorAccessSeed {
+ public class WorldServer extends World implements ServerEntityGetter, GeneratorAccessSeed {
public static final BlockPosition END_SPAWN_POINT = new BlockPosition(100, 50, 0);
-@@ -184,7 +201,7 @@
- final List players;
+@@ -186,7 +203,7 @@
+ final List players = Lists.newArrayList();
private final ChunkProviderServer chunkSource;
private final MinecraftServer server;
- public final IWorldDataServer serverLevelData;
+ public final WorldDataServer serverLevelData; // CraftBukkit - type
private int lastSpawnChunkRadius;
- final EntityTickList entityTickList;
+ final EntityTickList entityTickList = new EntityTickList();
public final PersistentEntitySectionManager entityManager;
-@@ -211,12 +228,30 @@
+@@ -213,13 +230,47 @@
private final boolean tickTime;
private final RandomSequences randomSequences;
- public WorldServer(MinecraftServer minecraftserver, Executor executor, Convertable.ConversionSession convertable_conversionsession, IWorldDataServer iworlddataserver, ResourceKey resourcekey, WorldDimension worlddimension, WorldLoadListener worldloadlistener, boolean flag, long i, List list, boolean flag1, @Nullable RandomSequences randomsequences) {
-- IRegistryCustom.Dimension iregistrycustom_dimension = minecraftserver.registryAccess();
-- Holder holder = worlddimension.type();
+- super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), false, flag, i, minecraftserver.getMaxChainedNeighborUpdates());
+ // CraftBukkit start
+ public final Convertable.ConversionSession convertable;
+ public final UUID uuid;
-
-- Objects.requireNonNull(minecraftserver);
-- super(iworlddataserver, resourcekey, iregistrycustom_dimension, holder, minecraftserver::getProfiler, false, flag, i, minecraftserver.getMaxChainedNeighborUpdates());
++
+ public Chunk getChunkIfLoaded(int x, int z) {
+ return this.chunkSource.getChunk(x, z, false);
+ }
@@ -57,19 +54,13 @@
+
+ // Add env and gen to constructor, IWorldDataServer -> WorldDataServer
+ public WorldServer(MinecraftServer minecraftserver, Executor executor, Convertable.ConversionSession convertable_conversionsession, WorldDataServer iworlddataserver, ResourceKey resourcekey, WorldDimension worlddimension, WorldLoadListener worldloadlistener, boolean flag, long i, List list, boolean flag1, @Nullable RandomSequences randomsequences, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider) {
-+ // IRegistryCustom.Dimension iregistrycustom_dimension = minecraftserver.registryAccess(); // CraftBukkit - decompile error
-+ // Holder holder = worlddimension.type(); // CraftBukkit - decompile error
-+
-+ // Objects.requireNonNull(minecraftserver); // CraftBukkit - decompile error
-+ super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), minecraftserver::getProfiler, false, flag, i, minecraftserver.getMaxChainedNeighborUpdates(), gen, biomeProvider, env);
++ super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), false, flag, i, minecraftserver.getMaxChainedNeighborUpdates(), gen, biomeProvider, env);
+ this.pvpMode = minecraftserver.isPvpAllowed();
+ convertable = convertable_conversionsession;
+ uuid = WorldUUID.getUUID(convertable_conversionsession.levelDirectory.path().toFile());
+ // CraftBukkit end
- this.players = Lists.newArrayList();
- this.entityTickList = new EntityTickList();
- this.blockTicks = new TickListServer<>(this::isPositionTickingWithEntitiesLoaded, this.getProfilerSupplier());
-@@ -231,6 +266,22 @@
+ this.tickTime = flag1;
+ this.server = minecraftserver;
this.customSpawners = list;
this.serverLevelData = iworlddataserver;
ChunkGenerator chunkgenerator = worlddimension.generator();
@@ -77,7 +68,7 @@
+ serverLevelData.setWorld(this);
+
+ if (biomeProvider != null) {
-+ WorldChunkManager worldChunkManager = new CustomWorldChunkManager(getWorld(), biomeProvider, server.registryAccess().registryOrThrow(Registries.BIOME));
++ WorldChunkManager worldChunkManager = new CustomWorldChunkManager(getWorld(), biomeProvider, server.registryAccess().lookupOrThrow(Registries.BIOME));
+ if (chunkgenerator instanceof ChunkGeneratorAbstract cga) {
+ chunkgenerator = new ChunkGeneratorAbstract(worldChunkManager, cga.settings);
+ } else if (chunkgenerator instanceof ChunkProviderFlat cpf) {
@@ -92,7 +83,7 @@
boolean flag2 = minecraftserver.forceSynchronousWrites();
DataFixer datafixer = minecraftserver.getFixerUpper();
EntityPersistentStorage entitypersistentstorage = new EntityStorage(new SimpleRegionStorage(new RegionStorageInfo(convertable_conversionsession.getLevelId(), resourcekey, "entities"), convertable_conversionsession.getDimensionPath(resourcekey).resolve("entities"), datafixer, flag2, DataFixTypes.ENTITY_CHUNK), this, minecraftserver);
-@@ -258,9 +309,9 @@
+@@ -247,9 +298,9 @@
long l = minecraftserver.getWorldData().worldGenOptions().seed();
this.structureCheck = new StructureCheck(this.chunkSource.chunkScanner(), this.registryAccess(), minecraftserver.getStructureManager(), resourcekey, chunkgenerator, this.chunkSource.randomState(), this, chunkgenerator.getBiomeSource(), l, datafixer);
@@ -105,7 +96,7 @@
} else {
this.dragonFight = null;
}
-@@ -270,6 +321,7 @@
+@@ -259,6 +310,7 @@
this.randomSequences = (RandomSequences) Objects.requireNonNullElseGet(randomsequences, () -> {
return (RandomSequences) this.getDataStorage().computeIfAbsent(RandomSequences.factory(l), "random_sequences");
});
@@ -113,7 +104,7 @@
}
/** @deprecated */
-@@ -314,12 +366,20 @@
+@@ -304,12 +356,20 @@
long j;
if (this.sleepStatus.areEnoughSleeping(i) && this.sleepStatus.areEnoughDeepSleeping(i, this.players)) {
@@ -137,7 +128,7 @@
if (this.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE) && this.isRaining()) {
this.resetWeatherCycle();
}
-@@ -354,7 +414,7 @@
+@@ -344,7 +404,7 @@
this.handlingTick = false;
gameprofilerfiller.pop();
@@ -146,16 +137,7 @@
if (flag1) {
this.resetEmptyTime();
-@@ -370,7 +430,7 @@
-
- this.entityTickList.forEach((entity) -> {
- if (!entity.isRemoved()) {
-- if (this.shouldDiscardEntity(entity)) {
-+ if (false && this.shouldDiscardEntity(entity)) { // CraftBukkit - We prevent spawning in general, so this butchering is not needed
- entity.discard();
- } else if (!tickratemanager.isEntityFrozen(entity)) {
- gameprofilerfiller.push("checkDespawn");
-@@ -442,7 +502,7 @@
+@@ -428,7 +488,7 @@
private void wakeUpAllPlayers() {
this.sleepStatus.removeAllSleepers();
@@ -164,7 +146,7 @@
entityplayer.stopSleepInBed(false, false);
});
}
-@@ -469,7 +529,7 @@
+@@ -455,7 +515,7 @@
entityhorseskeleton.setTrap(true);
entityhorseskeleton.setAge(0);
entityhorseskeleton.setPos((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
@@ -173,7 +155,7 @@
}
}
-@@ -478,7 +538,7 @@
+@@ -464,7 +524,7 @@
if (entitylightning != null) {
entitylightning.moveTo(Vec3D.atBottomCenterOf(blockposition));
entitylightning.setVisualOnly(flag1);
@@ -182,7 +164,7 @@
}
}
}
-@@ -534,7 +594,7 @@
+@@ -520,7 +580,7 @@
BiomeBase biomebase = (BiomeBase) this.getBiome(blockposition1).value();
if (biomebase.shouldFreeze(this, blockposition2)) {
@@ -191,7 +173,7 @@
}
if (this.isRaining()) {
-@@ -550,10 +610,10 @@
+@@ -536,10 +596,10 @@
IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockSnow.LAYERS, j + 1);
Block.pushEntitiesUp(iblockdata, iblockdata1, this, blockposition1);
@@ -204,7 +186,7 @@
}
}
-@@ -714,6 +774,7 @@
+@@ -700,6 +760,7 @@
this.rainLevel = MathHelper.clamp(this.rainLevel, 0.0F, 1.0F);
}
@@ -212,7 +194,7 @@
if (this.oRainLevel != this.rainLevel) {
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel), this.dimension());
}
-@@ -732,15 +793,48 @@
+@@ -718,15 +779,48 @@
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel));
this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.THUNDER_LEVEL_CHANGE, this.thunderLevel));
}
@@ -263,15 +245,15 @@
}
public void resetEmptyTime() {
-@@ -775,6 +869,7 @@
+@@ -762,6 +856,7 @@
});
gameprofilerfiller.incrementCounter("tickNonPassenger");
entity.tick();
+ entity.postTick(); // CraftBukkit
- this.getProfiler().pop();
+ gameprofilerfiller.pop();
Iterator iterator = entity.getPassengers().iterator();
-@@ -798,6 +893,7 @@
+@@ -785,6 +880,7 @@
});
gameprofilerfiller.incrementCounter("tickPassenger");
entity1.rideTick();
@@ -279,7 +261,7 @@
gameprofilerfiller.pop();
Iterator iterator = entity1.getPassengers().iterator();
-@@ -822,6 +918,7 @@
+@@ -809,6 +905,7 @@
ChunkProviderServer chunkproviderserver = this.getChunkSource();
if (!flag1) {
@@ -287,7 +269,7 @@
if (iprogressupdate != null) {
iprogressupdate.progressStartNoAbort(IChatBaseComponent.translatable("menu.savingLevel"));
}
-@@ -839,11 +936,19 @@
+@@ -826,11 +923,19 @@
}
}
@@ -301,14 +283,14 @@
+ // CraftBukkit end
}
- private void saveLevelData() {
+ private void saveLevelData(boolean flag) {
if (this.dragonFight != null) {
- this.server.getWorldData().setEndDragonFightData(this.dragonFight.saveData());
+ this.serverLevelData.setEndDragonFightData(this.dragonFight.saveData()); // CraftBukkit
}
- this.getChunkSource().getDataStorage().save();
-@@ -908,18 +1013,40 @@
+ WorldPersistentData worldpersistentdata = this.getChunkSource().getDataStorage();
+@@ -902,18 +1007,40 @@
@Override
public boolean addFreshEntity(Entity entity) {
@@ -352,7 +334,7 @@
}
}
-@@ -944,24 +1071,37 @@
+@@ -938,24 +1065,37 @@
this.entityManager.addNewEntity(entityplayer);
}
@@ -394,19 +376,19 @@
return true;
}
}
-@@ -972,13 +1112,35 @@
+@@ -966,13 +1106,35 @@
}
public void removePlayerImmediately(EntityPlayer entityplayer, Entity.RemovalReason entity_removalreason) {
- entityplayer.remove(entity_removalreason);
+ entityplayer.remove(entity_removalreason, null); // CraftBukkit - add Bukkit remove cause
- }
-
++ }
++
+ // CraftBukkit start
+ public boolean strikeLightning(Entity entitylightning) {
+ return this.strikeLightning(entitylightning, LightningStrikeEvent.Cause.UNKNOWN);
-+ }
-+
+ }
+
+ public boolean strikeLightning(Entity entitylightning, LightningStrikeEvent.Cause cause) {
+ LightningStrikeEvent lightning = CraftEventFactory.callLightningStrikeEvent((org.bukkit.entity.LightningStrike) entitylightning.getBukkitEntity(), cause);
+
@@ -431,7 +413,7 @@
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
-@@ -987,6 +1149,12 @@
+@@ -981,6 +1143,12 @@
double d1 = (double) blockposition.getY() - entityplayer.getY();
double d2 = (double) blockposition.getZ() - entityplayer.getZ();
@@ -444,7 +426,7 @@
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
entityplayer.connection.send(new PacketPlayOutBlockBreakAnimation(i, blockposition, j));
}
-@@ -1047,7 +1215,18 @@
+@@ -1059,7 +1227,18 @@
Iterator iterator = this.navigatingMobs.iterator();
while (iterator.hasNext()) {
@@ -464,19 +446,52 @@
NavigationAbstract navigationabstract = entityinsentient.getNavigation();
if (navigationabstract.shouldRecomputePath(blockposition)) {
-@@ -1109,6 +1288,11 @@
+@@ -1125,6 +1304,12 @@
+
@Override
- public Explosion explode(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, World.a world_a, ParticleParam particleparam, ParticleParam particleparam1, Holder holder) {
- Explosion explosion = this.explode(entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, world_a, false, particleparam, particleparam1, holder);
+ public void explode(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, World.a world_a, ParticleParam particleparam, ParticleParam particleparam1, Holder holder) {
+ // CraftBukkit start
-+ if (explosion.wasCanceled) {
-+ return explosion;
++ this.explode0(entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, world_a, particleparam, particleparam1, holder);
++ }
++
++ public ServerExplosion explode0(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, World.a world_a, ParticleParam particleparam, ParticleParam particleparam1, Holder holder) {
++ // CraftBukkit end
+ Explosion.Effect explosion_effect;
+
+ switch (world_a) {
+@@ -1143,6 +1328,11 @@
+ case TRIGGER:
+ explosion_effect = Explosion.Effect.TRIGGER_BLOCK;
+ break;
++ // CraftBukkit start - handle custom explosion type
++ case STANDARD:
++ explosion_effect = Explosion.Effect.DESTROY;
++ break;
++ // CraftBukkit end
+ default:
+ throw new MatchException((String) null, (Throwable) null);
+ }
+@@ -1152,6 +1342,11 @@
+ ServerExplosion serverexplosion = new ServerExplosion(this, entity, damagesource, explosiondamagecalculator, vec3d, f, flag, explosion_effect1);
+
+ serverexplosion.explode();
++ // CraftBukkit start
++ if (serverexplosion.wasCanceled) {
++ return serverexplosion;
+ }
+ // CraftBukkit end
+ ParticleParam particleparam2 = serverexplosion.isSmall() ? particleparam : particleparam1;
+ Iterator iterator = this.players.iterator();
+
+@@ -1165,6 +1360,7 @@
+ }
+ }
+
++ return serverexplosion; // CraftBukkit
+ }
- if (!explosion.interactsWithBlocks()) {
- explosion.clearToBlow();
-@@ -1181,13 +1365,20 @@
+ private Explosion.Effect getDestroyType(GameRules.GameRuleKey gamerules_gamerulekey) {
+@@ -1225,13 +1421,20 @@
}
public int sendParticles(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
@@ -499,7 +514,7 @@
++j;
}
}
-@@ -1238,7 +1429,7 @@
+@@ -1282,7 +1485,7 @@
@Nullable
public BlockPosition findNearestMapStructure(TagKey tagkey, BlockPosition blockposition, int i, boolean flag) {
@@ -507,8 +522,8 @@
+ if (!this.serverLevelData.worldGenOptions().generateStructures()) { // CraftBukkit
return null;
} else {
- Optional> optional = this.registryAccess().registryOrThrow(Registries.STRUCTURE).getTag(tagkey);
-@@ -1280,11 +1471,22 @@
+ Optional> optional = this.registryAccess().lookupOrThrow(Registries.STRUCTURE).get(tagkey);
+@@ -1324,11 +1527,22 @@
@Nullable
@Override
public WorldMap getMapData(MapId mapid) {
@@ -532,7 +547,7 @@
this.getServer().overworld().getDataStorage().set(mapid.key(), worldmap);
}
-@@ -1595,6 +1797,11 @@
+@@ -1639,6 +1853,11 @@
@Override
public void blockUpdated(BlockPosition blockposition, Block block) {
if (!this.isDebug()) {
@@ -544,7 +559,7 @@
this.updateNeighborsAt(blockposition, block);
}
-@@ -1614,12 +1821,12 @@
+@@ -1658,12 +1877,12 @@
}
public boolean isFlat() {
@@ -559,7 +574,7 @@
}
@Nullable
-@@ -1642,7 +1849,7 @@
+@@ -1686,7 +1905,7 @@
private static String getTypeCount(Iterable iterable, Function function) {
try {
Object2IntOpenHashMap object2intopenhashmap = new Object2IntOpenHashMap();
@@ -568,7 +583,7 @@
while (iterator.hasNext()) {
T t0 = iterator.next();
-@@ -1651,7 +1858,7 @@
+@@ -1695,7 +1914,7 @@
object2intopenhashmap.addTo(s, 1);
}
@@ -577,7 +592,7 @@
String s1 = (String) entry.getKey();
return s1 + ":" + entry.getIntValue();
-@@ -1796,6 +2003,8 @@
+@@ -1854,6 +2073,8 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
@@ -586,7 +601,7 @@
}
public void onTrackingEnd(Entity entity) {
-@@ -1827,6 +2036,14 @@
+@@ -1885,6 +2106,14 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);
diff --git a/nms-patches/net/minecraft/server/network/PlayerConnection.patch b/nms-patches/net/minecraft/server/network/PlayerConnection.patch
index ef370f58..b11116f7 100644
--- a/nms-patches/net/minecraft/server/network/PlayerConnection.patch
+++ b/nms-patches/net/minecraft/server/network/PlayerConnection.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/network/PlayerConnection.java
+++ b/net/minecraft/server/network/PlayerConnection.java
-@@ -191,6 +191,67 @@
+@@ -196,6 +196,69 @@
import net.minecraft.world.phys.shapes.VoxelShapes;
import org.slf4j.Logger;
@@ -13,7 +13,7 @@
+import net.minecraft.network.chat.OutgoingChatMessage;
+import net.minecraft.network.protocol.game.PacketPlayOutAttachEntity;
+import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment;
-+import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity;
++import net.minecraft.network.protocol.game.PacketPlayOutSetSlot;
+import net.minecraft.world.entity.EntityInsentient;
+import net.minecraft.world.entity.animal.Bucketable;
+import net.minecraft.world.entity.EntityLiving;
@@ -30,7 +30,9 @@
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftItemType;
++import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.craftbukkit.util.CraftChatMessage;
++import org.bukkit.craftbukkit.util.CraftLocation;
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
+import org.bukkit.craftbukkit.util.LazyPlayerSet;
+import org.bukkit.craftbukkit.util.Waitable;
@@ -68,18 +70,7 @@
public class PlayerConnection extends ServerCommonPacketListenerImpl implements PacketListenerPlayIn, ServerPlayerConnection, TickablePacketListener {
static final Logger LOGGER = LogUtils.getLogger();
-@@ -204,7 +265,9 @@
- public final PlayerChunkSender chunkSender;
- private int tickCount;
- private int ackBlockChangesUpTo = -1;
-- private int chatSpamTickCount;
-+ // CraftBukkit start - multithreaded fields
-+ private final AtomicInteger chatSpamTickCount = new AtomicInteger();
-+ // CraftBukkit end
- private int dropSpamTickCount;
- private double firstGoodX;
- private double firstGoodY;
-@@ -239,7 +302,7 @@
+@@ -245,7 +308,7 @@
private boolean waitingForSwitchToConfig;
public PlayerConnection(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer, CommonListenerCookie commonlistenercookie) {
@@ -88,7 +79,7 @@
this.chunkSender = new PlayerChunkSender(networkmanager.isMemoryConnection());
this.player = entityplayer;
entityplayer.connection = this;
-@@ -248,9 +311,25 @@
+@@ -254,9 +317,25 @@
Objects.requireNonNull(minecraftserver);
this.signedMessageDecoder = SignedMessageChain.b.unsigned(uuid, minecraftserver::enforceSecureProfile);
@@ -115,29 +106,15 @@
@Override
public void tick() {
if (this.ackBlockChangesUpTo > -1) {
-@@ -302,15 +381,21 @@
- }
-
- this.keepConnectionAlive();
-+ // CraftBukkit start
-+ for (int spam; (spam = this.chatSpamTickCount.get()) > 0 && !chatSpamTickCount.compareAndSet(spam, spam - 1); ) ;
-+ /* Use thread-safe field access instead
- if (this.chatSpamTickCount > 0) {
- --this.chatSpamTickCount;
- }
-+ */
-+ // CraftBukkit end
-
- if (this.dropSpamTickCount > 0) {
- --this.dropSpamTickCount;
- }
-
+@@ -311,6 +390,7 @@
+ this.chatSpamThrottler.tick();
+ this.dropSpamThrottler.tick();
if (this.player.getLastActionTime() > 0L && this.server.getPlayerIdleTimeout() > 0 && SystemUtils.getMillis() - this.player.getLastActionTime() > (long) this.server.getPlayerIdleTimeout() * 1000L * 60L) {
+ this.player.resetLastActionTime(); // CraftBukkit - SPIGOT-854
this.disconnect((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.idling"));
}
-@@ -399,6 +484,13 @@
+@@ -399,6 +479,13 @@
if (entity != this.player && entity.getControllingPassenger() == this.player && entity == this.lastVehicle) {
WorldServer worldserver = this.player.serverLevel();
@@ -151,7 +128,7 @@
double d0 = entity.getX();
double d1 = entity.getY();
double d2 = entity.getZ();
-@@ -413,7 +505,33 @@
+@@ -413,7 +500,33 @@
double d9 = entity.getDeltaMovement().lengthSqr();
double d10 = d6 * d6 + d7 * d7 + d8 * d8;
@@ -186,7 +163,7 @@
PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", new Object[]{entity.getName().getString(), this.player.getName().getString(), d6, d7, d8});
this.send(new PacketPlayOutVehicleMove(entity));
return;
-@@ -453,14 +571,76 @@
+@@ -453,14 +566,76 @@
}
entity.absMoveTo(d3, d4, d5, f, f1);
@@ -261,9 +238,9 @@
+ // CraftBukkit end
+
this.player.serverLevel().getChunkSource().move(this.player);
+ entity.recordMovementThroughBlocks(new Vec3D(d0, d1, d2), entity.position());
Vec3D vec3d = new Vec3D(entity.getX() - d0, entity.getY() - d1, entity.getZ() - d2);
-
-@@ -497,6 +677,7 @@
+@@ -498,6 +673,7 @@
}
this.awaitingPositionFromClient = null;
@@ -271,16 +248,7 @@
}
}
-@@ -504,7 +685,7 @@
- @Override
- public void handleRecipeBookSeenRecipePacket(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) {
- PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipedisplayed, this, this.player.serverLevel());
-- Optional optional = this.server.getRecipeManager().byKey(packetplayinrecipedisplayed.getRecipe());
-+ Optional extends RecipeHolder>> optional = this.server.getRecipeManager().byKey(packetplayinrecipedisplayed.getRecipe()); // CraftBukkit - decompile error
- RecipeBookServer recipebookserver = this.player.getRecipeBook();
-
- Objects.requireNonNull(recipebookserver);
-@@ -514,6 +695,7 @@
+@@ -521,6 +697,7 @@
@Override
public void handleRecipeBookChangeSettingsPacket(PacketPlayInRecipeSettings packetplayinrecipesettings) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipesettings, this, this.player.serverLevel());
@@ -288,12 +256,12 @@
this.player.getRecipeBook().setBookSetting(packetplayinrecipesettings.getBookType(), packetplayinrecipesettings.isOpen(), packetplayinrecipesettings.isFiltering());
}
-@@ -534,6 +716,12 @@
+@@ -541,6 +718,12 @@
@Override
public void handleCustomCommandSuggestions(PacketPlayInTabComplete packetplayintabcomplete) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayintabcomplete, this, this.player.serverLevel());
+ // CraftBukkit start
-+ if (chatSpamTickCount.addAndGet(1) > 500 && !this.server.getPlayerList().isOp(this.player.getGameProfile())) {
++ if (!this.chatSpamThrottler.isIncrementAndUnderThreshold(1, 500) && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
+ this.disconnect(IChatBaseComponent.translatable("disconnect.spam"));
+ return;
+ }
@@ -301,7 +269,7 @@
StringReader stringreader = new StringReader(packetplayintabcomplete.getCommand());
if (stringreader.canRead() && stringreader.peek() == '/') {
-@@ -543,6 +731,7 @@
+@@ -550,6 +733,7 @@
ParseResults parseresults = this.server.getCommands().getDispatcher().parse(stringreader, this.player.createCommandSourceStack());
this.server.getCommands().getDispatcher().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> {
@@ -309,7 +277,7 @@
Suggestions suggestions1 = suggestions.getList().size() <= 1000 ? suggestions : new Suggestions(suggestions.getRange(), suggestions.getList().subList(0, 1000));
this.send(new PacketPlayOutTabComplete(packetplayintabcomplete.getId(), suggestions1));
-@@ -787,6 +976,13 @@
+@@ -796,6 +980,13 @@
Container container = this.player.containerMenu;
if (container instanceof ContainerMerchant containermerchant) {
@@ -323,7 +291,7 @@
if (!containermerchant.stillValid(this.player)) {
PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, containermerchant);
return;
-@@ -800,6 +996,13 @@
+@@ -809,6 +1000,13 @@
@Override
public void handleEditBook(PacketPlayInBEdit packetplayinbedit) {
@@ -337,16 +305,7 @@
int i = packetplayinbedit.slot();
if (PlayerInventory.isHotbarSlot(i) || i == 40) {
-@@ -808,7 +1011,7 @@
-
- Objects.requireNonNull(list);
- optional.ifPresent(list::add);
-- Stream stream = packetplayinbedit.pages().stream().limit(100L);
-+ Stream stream = packetplayinbedit.pages().stream().limit(100L); // CraftBukkit - decompile error
-
- Objects.requireNonNull(list);
- stream.forEach(list::add);
-@@ -823,12 +1026,16 @@
+@@ -829,12 +1027,16 @@
}
private void updateBookContents(List list, int i) {
@@ -356,7 +315,7 @@
+ ItemStack itemstack = handItem.copy();
+ // CraftBukkit end
- if (itemstack.is(Items.WRITABLE_BOOK)) {
+ if (itemstack.has(DataComponents.WRITABLE_BOOK_CONTENT)) {
List> list1 = list.stream().map(this::filterableFromOutgoing).toList();
itemstack.set(DataComponents.WRITABLE_BOOK_CONTENT, new WritableBookContent(list1));
@@ -364,7 +323,7 @@
}
}
-@@ -839,12 +1046,13 @@
+@@ -845,12 +1047,13 @@
ItemStack itemstack1 = itemstack.transmuteCopy(Items.WRITTEN_BOOK);
itemstack1.remove(DataComponents.WRITABLE_BOOK_CONTENT);
@@ -380,7 +339,7 @@
}
}
-@@ -906,7 +1114,7 @@
+@@ -912,7 +1115,7 @@
} else {
WorldServer worldserver = this.player.serverLevel();
@@ -389,7 +348,7 @@
if (this.tickCount == 0) {
this.resetPosition();
}
-@@ -921,7 +1129,15 @@
+@@ -927,7 +1130,15 @@
if (this.player.isPassenger()) {
this.player.absMoveTo(this.player.getX(), this.player.getY(), this.player.getZ(), f, f1);
this.player.serverLevel().getChunkSource().move(this.player);
@@ -405,7 +364,7 @@
double d3 = this.player.getX();
double d4 = this.player.getY();
double d5 = this.player.getZ();
-@@ -943,15 +1159,33 @@
+@@ -949,15 +1160,33 @@
++this.receivedMovePacketCount;
int i = this.receivedMovePacketCount - this.knownMovePacketCount;
@@ -432,16 +391,16 @@
+ speed = player.getAbilities().walkingSpeed * 10f;
+ }
+
- if (!this.player.isChangingDimension() && (!this.player.level().getGameRules().getBoolean(GameRules.RULE_DISABLE_ELYTRA_MOVEMENT_CHECK) || !flag)) {
+ if (this.shouldCheckPlayerMovement(flag)) {
float f2 = flag ? 300.0F : 100.0F;
-- if (d10 - d9 > (double) (f2 * (float) i) && !this.isSingleplayerOwner()) {
-+ if (d10 - d9 > Math.max(f2, Math.pow((double) (10.0F * (float) i * speed), 2)) && !this.isSingleplayerOwner()) {
+- if (d10 - d9 > (double) (f2 * (float) i)) {
++ if (d10 - d9 > Math.max(f2, Math.pow((double) (10.0F * (float) i * speed), 2))) {
+ // CraftBukkit end
PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", new Object[]{this.player.getName().getString(), d6, d7, d8});
this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot());
return;
-@@ -973,6 +1207,7 @@
+@@ -979,6 +1208,7 @@
boolean flag2 = this.player.verticalCollisionBelow;
this.player.move(EnumMoveType.PLAYER, new Vec3D(d6, d7, d8));
@@ -449,12 +408,12 @@
double d11 = d7;
d6 = d0 - this.player.getX();
-@@ -991,9 +1226,75 @@
+@@ -997,9 +1227,75 @@
}
if (!this.player.noPhysics && !this.player.isSleeping() && (flag3 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb, d0, d1, d2))) {
- this.teleport(d3, d4, d5, f, f1);
-+ this.internalTeleport(d3, d4, d5, f, f1, Collections.emptySet()); // CraftBukkit - SPIGOT-1807: Don't call teleport event, when the client thinks the player is falling, because the chunks are not loaded on the client yet.
++ this.internalTeleport(d3, d4, d5, f, f1); // CraftBukkit - SPIGOT-1807: Don't call teleport event, when the client thinks the player is falling, because the chunks are not loaded on the client yet.
this.player.doCheckFallDamage(this.player.getX() - d3, this.player.getY() - d4, this.player.getZ() - d5, packetplayinflying.isOnGround());
} else {
+ // CraftBukkit start - fire PlayerMoveEvent
@@ -526,7 +485,7 @@
this.player.absMoveTo(d0, d1, d2, f, f1);
boolean flag4 = this.player.isAutoSpinAttack();
-@@ -1030,6 +1331,7 @@
+@@ -1049,6 +1345,7 @@
this.awaitingTeleportTime = this.tickCount;
this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
}
@@ -534,38 +493,33 @@
return true;
} else {
-@@ -1057,11 +1359,68 @@
- return true;
+@@ -1077,10 +1374,62 @@
}
-+ // CraftBukkit start - Delegate to teleport(Location)
public void teleport(double d0, double d1, double d2, float f, float f1) {
-- this.teleport(d0, d1, d2, f, f1, Collections.emptySet());
+- this.teleport(new PositionMoveRotation(new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f1), Collections.emptySet());
++ // CraftBukkit start - Delegate to teleport(Location)
+ this.teleport(d0, d1, d2, f, f1, PlayerTeleportEvent.TeleportCause.UNKNOWN);
+ }
+
+ public boolean teleport(double d0, double d1, double d2, float f, float f1, PlayerTeleportEvent.TeleportCause cause) {
-+ return this.teleport(d0, d1, d2, f, f1, Collections.emptySet(), cause);
++ return this.teleport(new PositionMoveRotation(new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f1), Collections.emptySet(), cause);
++ // CraftBukkit end
}
- public void teleport(double d0, double d1, double d2, float f, float f1, Set set) {
-+ this.teleport(d0, d1, d2, f, f1, set, PlayerTeleportEvent.TeleportCause.UNKNOWN);
+ public void teleport(PositionMoveRotation positionmoverotation, Set set) {
++ // CraftBukkit start
++ this.teleport(positionmoverotation, set, PlayerTeleportEvent.TeleportCause.UNKNOWN);
+ }
+
-+ public boolean teleport(double d0, double d1, double d2, float f, float f1, Set set, PlayerTeleportEvent.TeleportCause cause) { // CraftBukkit - Return event status
++ public boolean teleport(PositionMoveRotation positionmoverotation, Set set, PlayerTeleportEvent.TeleportCause cause) { // CraftBukkit - Return event status
+ Player player = this.getCraftPlayer();
+ Location from = player.getLocation();
-+
-+ double x = d0;
-+ double y = d1;
-+ double z = d2;
-+ float yaw = f;
-+ float pitch = f1;
-+
-+ Location to = new Location(this.getCraftPlayer().getWorld(), x, y, z, yaw, pitch);
++ PositionMoveRotation absolutePosition = PositionMoveRotation.calculateAbsolute(PositionMoveRotation.of(this.player), positionmoverotation, set);
++ Location to = CraftLocation.toBukkit(absolutePosition.position(), this.getCraftPlayer().getWorld(), absolutePosition.yRot(), absolutePosition.xRot());
+ // SPIGOT-5171: Triggered on join
+ if (from.equals(to)) {
-+ this.internalTeleport(d0, d1, d2, f, f1, set);
++ this.internalTeleport(positionmoverotation, set);
+ return true; // CraftBukkit - Return event status
+ }
+
@@ -575,51 +529,48 @@
+ if (event.isCancelled() || !to.equals(event.getTo())) {
+ set = Collections.emptySet(); // Can't relative teleport
+ to = event.isCancelled() ? event.getFrom() : event.getTo();
-+ d0 = to.getX();
-+ d1 = to.getY();
-+ d2 = to.getZ();
-+ f = to.getYaw();
-+ f1 = to.getPitch();
++ positionmoverotation = new PositionMoveRotation(CraftLocation.toVec3D(to), Vec3D.ZERO, to.getYaw(), to.getPitch());
+ }
+
-+ this.internalTeleport(d0, d1, d2, f, f1, set);
++ this.internalTeleport(positionmoverotation, set);
+ return !event.isCancelled(); // CraftBukkit - Return event status
+ }
+
+ public void teleport(Location dest) {
-+ internalTeleport(dest.getX(), dest.getY(), dest.getZ(), dest.getYaw(), dest.getPitch(), Collections.emptySet());
++ this.internalTeleport(dest.getX(), dest.getY(), dest.getZ(), dest.getYaw(), dest.getPitch());
+ }
+
-+ private void internalTeleport(double d0, double d1, double d2, float f, float f1, Set set) {
-+ // CraftBukkit start
-+ if (Float.isNaN(f)) {
-+ f = 0;
++ private void internalTeleport(double d0, double d1, double d2, float f, float f1) {
++ this.internalTeleport(new PositionMoveRotation(new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f1), Collections.emptySet());
++ }
++
++ public void internalTeleport(PositionMoveRotation positionmoverotation, Set set) {
++ if (Float.isNaN(positionmoverotation.yRot())) {
++ positionmoverotation = new PositionMoveRotation(positionmoverotation.position(), positionmoverotation.deltaMovement(), 0, positionmoverotation.xRot());
+ }
-+ if (Float.isNaN(f1)) {
-+ f1 = 0;
++ if (Float.isNaN(positionmoverotation.xRot())) {
++ positionmoverotation = new PositionMoveRotation(positionmoverotation.position(), positionmoverotation.deltaMovement(), positionmoverotation.yRot(), 0);
+ }
+
+ this.justTeleported = true;
+ // CraftBukkit end
- double d3 = set.contains(RelativeMovement.X) ? this.player.getX() : 0.0D;
- double d4 = set.contains(RelativeMovement.Y) ? this.player.getY() : 0.0D;
- double d5 = set.contains(RelativeMovement.Z) ? this.player.getZ() : 0.0D;
-@@ -1073,6 +1432,14 @@
+ this.awaitingTeleportTime = this.tickCount;
+ if (++this.awaitingTeleport == Integer.MAX_VALUE) {
this.awaitingTeleport = 0;
- }
+@@ -1088,12 +1437,20 @@
+ this.player.teleportSetPosition(positionmoverotation, set);
+ this.awaitingPositionFromClient = this.player.position();
+ // CraftBukkit start - update last location
+ this.lastPosX = this.awaitingPositionFromClient.x;
+ this.lastPosY = this.awaitingPositionFromClient.y;
+ this.lastPosZ = this.awaitingPositionFromClient.z;
-+ this.lastYaw = f;
-+ this.lastPitch = f1;
++ this.lastYaw = this.player.getYRot();
++ this.lastPitch = this.player.getXRot();
+ // CraftBukkit end
-+
- this.awaitingTeleportTime = this.tickCount;
- this.player.absMoveTo(d0, d1, d2, f, f1);
- this.player.connection.send(new PacketPlayOutPosition(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.awaitingTeleport));
-@@ -1081,6 +1448,7 @@
+ this.player.connection.send(PacketPlayOutPosition.of(this.awaitingTeleport, positionmoverotation, set));
+ }
+
@Override
public void handlePlayerAction(PacketPlayInBlockDig packetplayinblockdig) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockdig, this, this.player.serverLevel());
@@ -627,7 +578,7 @@
BlockPosition blockposition = packetplayinblockdig.getPos();
this.player.resetLastActionTime();
-@@ -1091,14 +1459,46 @@
+@@ -1104,14 +1461,46 @@
if (!this.player.isSpectator()) {
ItemStack itemstack = this.player.getItemInHand(EnumHand.OFF_HAND);
@@ -676,7 +627,7 @@
this.player.drop(false);
}
-@@ -1136,6 +1536,7 @@
+@@ -1149,6 +1538,7 @@
@Override
public void handleUseItemOn(PacketPlayInUseItem packetplayinuseitem) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseitem, this, this.player.serverLevel());
@@ -684,15 +635,15 @@
this.player.connection.ackBlockChangesUpTo(packetplayinuseitem.getSequence());
WorldServer worldserver = this.player.serverLevel();
EnumHand enumhand = packetplayinuseitem.getHand();
-@@ -1158,6 +1559,7 @@
+@@ -1171,6 +1561,7 @@
- if (blockposition.getY() < i) {
+ if (blockposition.getY() <= i) {
if (this.awaitingPositionFromClient == null && worldserver.mayInteract(this.player, blockposition)) {
+ this.player.stopUsingItem(); // CraftBukkit - SPIGOT-4706
EnumInteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock);
if (enuminteractionresult.consumesAction()) {
-@@ -1190,6 +1592,7 @@
+@@ -1207,6 +1598,7 @@
@Override
public void handleUseItem(PacketPlayInBlockPlace packetplayinblockplace) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockplace, this, this.player.serverLevel());
@@ -700,7 +651,7 @@
this.ackBlockChangesUpTo(packetplayinblockplace.getSequence());
WorldServer worldserver = this.player.serverLevel();
EnumHand enumhand = packetplayinblockplace.getHand();
-@@ -1204,6 +1607,47 @@
+@@ -1221,6 +1613,47 @@
this.player.absRotateTo(f, f1);
}
@@ -747,17 +698,17 @@
+ // CraftBukkit end
EnumInteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand);
- if (enuminteractionresult.shouldSwing()) {
-@@ -1224,7 +1668,7 @@
+ if (enuminteractionresult instanceof EnumInteractionResult.d) {
+@@ -1245,7 +1678,7 @@
Entity entity = packetplayinspectate.getEntity(worldserver);
if (entity != null) {
-- this.player.teleportTo(worldserver, entity.getX(), entity.getY(), entity.getZ(), entity.getYRot(), entity.getXRot());
-+ this.player.teleportTo(worldserver, entity.getX(), entity.getY(), entity.getZ(), entity.getYRot(), entity.getXRot(), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.SPECTATE); // CraftBukkit
+- this.player.teleportTo(worldserver, entity.getX(), entity.getY(), entity.getZ(), Set.of(), entity.getYRot(), entity.getXRot(), true);
++ this.player.teleportTo(worldserver, entity.getX(), entity.getY(), entity.getZ(), Set.of(), entity.getYRot(), entity.getXRot(), true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.SPECTATE); // CraftBukkit
return;
}
}
-@@ -1245,6 +1689,13 @@
+@@ -1266,6 +1699,13 @@
@Override
public void onDisconnect(DisconnectionDetails disconnectiondetails) {
@@ -771,7 +722,7 @@
PlayerConnection.LOGGER.info("{} lost connection: {}", this.player.getName().getString(), disconnectiondetails.reason().getString());
this.removePlayerFromWorld();
super.onDisconnect(disconnectiondetails);
-@@ -1252,10 +1703,18 @@
+@@ -1273,10 +1713,18 @@
private void removePlayerFromWorld() {
this.chatMessageChain.close();
@@ -791,7 +742,7 @@
this.player.getTextFilter().leave();
}
-@@ -1270,7 +1729,16 @@
+@@ -1291,7 +1739,16 @@
@Override
public void handleSetCarriedItem(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinhelditemslot, this, this.player.serverLevel());
@@ -808,7 +759,7 @@
if (this.player.getInventory().selected != packetplayinhelditemslot.getSlot() && this.player.getUsedItemHand() == EnumHand.MAIN_HAND) {
this.player.stopUsingItem();
}
-@@ -1279,11 +1747,18 @@
+@@ -1300,11 +1757,18 @@
this.player.resetLastActionTime();
} else {
PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString());
@@ -827,7 +778,7 @@
Optional optional = this.unpackAndApplyLastSeen(packetplayinchat.lastSeenMessages());
if (!optional.isEmpty()) {
-@@ -1297,7 +1772,7 @@
+@@ -1318,7 +1782,7 @@
return;
}
@@ -836,7 +787,7 @@
IChatBaseComponent ichatbasecomponent = this.server.getChatDecorator().decorate(this.player, playerchatmessage.decoratedContent());
this.chatMessageChain.append(completablefuture, (filteredtext) -> {
-@@ -1305,19 +1780,36 @@
+@@ -1326,19 +1790,36 @@
this.broadcastChatMessage(playerchatmessage1);
});
@@ -875,7 +826,7 @@
ParseResults parseresults = this.parseCommand(s);
if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) {
-@@ -1334,19 +1826,37 @@
+@@ -1355,19 +1836,37 @@
if (!optional.isEmpty()) {
this.tryHandleChat(serverboundchatcommandsignedpacket.command(), () -> {
@@ -916,7 +867,7 @@
} catch (SignedMessageChain.a signedmessagechain_a) {
this.handleMessageDecodeFailure(signedmessagechain_a);
return;
-@@ -1354,10 +1864,10 @@
+@@ -1375,10 +1874,10 @@
CommandSigningContext.a commandsigningcontext_a = new CommandSigningContext.a(map);
@@ -929,7 +880,7 @@
}
private void handleMessageDecodeFailure(SignedMessageChain.a signedmessagechain_a) {
-@@ -1433,14 +1943,20 @@
+@@ -1454,14 +1953,20 @@
return com_mojang_brigadier_commanddispatcher.parse(s, this.player.createCommandSourceStack());
}
@@ -953,7 +904,7 @@
}
}
-@@ -1469,6 +1985,116 @@
+@@ -1490,6 +1995,116 @@
return false;
}
@@ -1070,7 +1021,7 @@
private PlayerChatMessage getSignedMessage(PacketPlayInChat packetplayinchat, LastSeenMessages lastseenmessages) throws SignedMessageChain.a {
SignedMessageBody signedmessagebody = new SignedMessageBody(packetplayinchat.message(), packetplayinchat.timeStamp(), packetplayinchat.salt(), lastseenmessages);
-@@ -1476,13 +2102,33 @@
+@@ -1497,13 +2112,33 @@
}
private void broadcastChatMessage(PlayerChatMessage playerchatmessage) {
@@ -1098,16 +1049,16 @@
}
private void detectRateSpam() {
-- this.chatSpamTickCount += 20;
-- if (this.chatSpamTickCount > 200 && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
+- this.chatSpamThrottler.increment();
+- if (!this.chatSpamThrottler.isUnderThreshold() && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
+ // CraftBukkit start - replaced with thread safe throttle
-+ // this.chatSpamTickCount += 20;
-+ if (this.chatSpamTickCount.addAndGet(20) > 200 && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
++ // this.chatSpamThrottler.increment();
++ if (!this.chatSpamThrottler.isIncrementAndUnderThreshold() && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) {
+ // CraftBukkit end
this.disconnect((IChatBaseComponent) IChatBaseComponent.translatable("disconnect.spam"));
}
-@@ -1504,13 +2150,62 @@
+@@ -1525,13 +2160,62 @@
@Override
public void handleAnimate(PacketPlayInArmAnimation packetplayinarmanimation) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinarmanimation, this, this.player.serverLevel());
@@ -1170,7 +1121,7 @@
this.player.resetLastActionTime();
Entity entity;
-@@ -1587,6 +2282,12 @@
+@@ -1608,6 +2292,12 @@
}
public void sendPlayerChatMessage(PlayerChatMessage playerchatmessage, ChatMessageType.a chatmessagetype_a) {
@@ -1183,7 +1134,7 @@
this.send(new ClientboundPlayerChatPacket(playerchatmessage.link().sender(), playerchatmessage.link().index(), playerchatmessage.signature(), playerchatmessage.signedBody().pack(this.messageSignatureCache), playerchatmessage.unsignedContent(), playerchatmessage.filterMask(), chatmessagetype_a));
this.addPendingMessage(playerchatmessage);
}
-@@ -1614,6 +2315,7 @@
+@@ -1635,6 +2325,7 @@
@Override
public void handleInteract(PacketPlayInUseEntity packetplayinuseentity) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseentity, this, this.player.serverLevel());
@@ -1191,9 +1142,9 @@
final WorldServer worldserver = this.player.serverLevel();
final Entity entity = packetplayinuseentity.getTarget(worldserver);
-@@ -1628,13 +2330,51 @@
+@@ -1649,13 +2340,51 @@
- if (this.player.canInteractWithEntity(axisalignedbb, 1.0D)) {
+ if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) {
packetplayinuseentity.dispatch(new PacketPlayInUseEntity.c() {
- private void performInteraction(EnumHand enumhand, PlayerConnection.a playerconnection_a) {
+ private void performInteraction(EnumHand enumhand, PlayerConnection.a playerconnection_a, PlayerInteractEntityEvent event) { // CraftBukkit
@@ -1241,10 +1192,10 @@
+ }
+ // CraftBukkit end
+
- if (enuminteractionresult.consumesAction()) {
- CriterionTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(PlayerConnection.this.player, enuminteractionresult.indicateItemUse() ? itemstack1 : ItemStack.EMPTY, entity);
- if (enuminteractionresult.shouldSwing()) {
-@@ -1647,19 +2387,20 @@
+ if (enuminteractionresult instanceof EnumInteractionResult.d) {
+ EnumInteractionResult.d enuminteractionresult_d = (EnumInteractionResult.d) enuminteractionresult;
+ ItemStack itemstack2 = enuminteractionresult_d.wasItemInteraction() ? itemstack1 : ItemStack.EMPTY;
+@@ -1671,19 +2400,20 @@
@Override
public void onInteraction(EnumHand enumhand) {
@@ -1268,7 +1219,7 @@
label23:
{
if (entity instanceof EntityArrow) {
-@@ -1677,6 +2418,11 @@
+@@ -1701,6 +2431,11 @@
}
PlayerConnection.this.player.attack(entity);
@@ -1280,28 +1231,30 @@
return;
}
}
-@@ -1700,17 +2446,17 @@
+@@ -1724,7 +2459,7 @@
case PERFORM_RESPAWN:
if (this.player.wonGame) {
this.player.wonGame = false;
- this.player = this.server.getPlayerList().respawn(this.player, true, Entity.RemovalReason.CHANGED_DIMENSION);
+ this.player = this.server.getPlayerList().respawn(this.player, true, Entity.RemovalReason.CHANGED_DIMENSION, RespawnReason.END_PORTAL); // CraftBukkit
+ this.resetPosition();
CriterionTriggers.CHANGED_DIMENSION.trigger(this.player, World.END, World.OVERWORLD);
} else {
- if (this.player.getHealth() > 0.0F) {
+@@ -1732,11 +2467,11 @@
return;
}
- this.player = this.server.getPlayerList().respawn(this.player, false, Entity.RemovalReason.KILLED);
+ this.player = this.server.getPlayerList().respawn(this.player, false, Entity.RemovalReason.KILLED, RespawnReason.DEATH); // CraftBukkit
+ this.resetPosition();
if (this.server.isHardcore()) {
this.player.setGameMode(EnumGamemode.SPECTATOR);
-- ((GameRules.GameRuleBoolean) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.server);
-+ ((GameRules.GameRuleBoolean) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.player.serverLevel()); // CraftBukkit - per-world
+- ((GameRules.GameRuleBoolean) this.player.serverLevel().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.server);
++ ((GameRules.GameRuleBoolean) this.player.serverLevel().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.player.serverLevel()); // CraftBukkit - per-world
}
}
break;
-@@ -1723,15 +2469,21 @@
+@@ -1749,15 +2484,21 @@
@Override
public void handleContainerClose(PacketPlayInCloseWindow packetplayinclosewindow) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinclosewindow, this, this.player.serverLevel());
@@ -1325,7 +1278,7 @@
this.player.containerMenu.sendAllDataToRemote();
} else if (!this.player.containerMenu.stillValid(this.player)) {
PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
-@@ -1744,7 +2496,284 @@
+@@ -1770,7 +2511,284 @@
boolean flag = packetplayinwindowclick.getStateId() != this.player.containerMenu.getStateId();
this.player.containerMenu.suppressRemoteUpdates();
@@ -1611,28 +1564,30 @@
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.getChangedSlots()).iterator();
while (objectiterator.hasNext()) {
-@@ -1774,9 +2803,18 @@
- if (!this.player.containerMenu.stillValid(this.player)) {
- PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
- } else {
-- this.server.getRecipeManager().byKey(packetplayinautorecipe.getRecipe()).ifPresent((recipeholder) -> {
-- ((ContainerRecipeBook) this.player.containerMenu).handlePlacement(packetplayinautorecipe.isShiftDown(), recipeholder, this.player);
-+ // CraftBukkit start - implement PlayerRecipeBookClickEvent
-+ org.bukkit.inventory.Recipe recipe = this.cserver.getRecipe(CraftNamespacedKey.fromMinecraft(packetplayinautorecipe.getRecipe()));
-+ if (recipe == null) {
-+ return;
-+ }
-+ org.bukkit.event.player.PlayerRecipeBookClickEvent event = CraftEventFactory.callRecipeBookClickEvent(this.player, recipe, packetplayinautorecipe.isShiftDown());
+@@ -1816,7 +2834,21 @@
+ return;
+ }
+
+- ContainerRecipeBook.a containerrecipebook_a = containerrecipebook.handlePlacement(packetplayinautorecipe.useMaxItems(), this.player.isCreative(), recipeholder, this.player.serverLevel(), this.player.getInventory());
++ // CraftBukkit start - implement PlayerRecipeBookClickEvent
++ org.bukkit.inventory.Recipe recipe = recipeholder.toBukkitRecipe();
++ if (recipe == null) {
++ return;
++ }
++ org.bukkit.event.player.PlayerRecipeBookClickEvent event = CraftEventFactory.callRecipeBookClickEvent(this.player, recipe, packetplayinautorecipe.useMaxItems());
+
-+ // Cast to keyed should be safe as the recipe will never be a MerchantRecipe.
-+ this.server.getRecipeManager().byKey(CraftNamespacedKey.toMinecraft(((org.bukkit.Keyed) event.getRecipe()).getKey())).ifPresent((recipeholder) -> {
-+ ((ContainerRecipeBook) this.player.containerMenu).handlePlacement(event.isShiftClick(), recipeholder, this.player);
- });
-+ // CraftBukkit end
- }
- }
- }
-@@ -1784,6 +2822,7 @@
++ // Cast to keyed should be safe as the recipe will never be a MerchantRecipe.
++ recipeholder = this.server.getRecipeManager().byKey(CraftRecipe.toMinecraft(((org.bukkit.Keyed) event.getRecipe()).getKey())).orElse(null);
++ if (recipeholder == null) {
++ return;
++ }
++
++ ContainerRecipeBook.a containerrecipebook_a = containerrecipebook.handlePlacement(event.isShiftClick(), this.player.isCreative(), recipeholder, this.player.serverLevel(), this.player.getInventory());
++ // CraftBukkit end
+
+ if (containerrecipebook_a == ContainerRecipeBook.a.PLACE_GHOST_RECIPE) {
+ this.player.connection.send(new PacketPlayOutAutoRecipe(this.player.containerMenu.containerId, craftingmanager_d.display().display()));
+@@ -1832,6 +2864,7 @@
@Override
public void handleContainerButtonClick(PacketPlayInEnchantItem packetplayinenchantitem) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinenchantitem, this, this.player.serverLevel());
@@ -1640,7 +1595,7 @@
this.player.resetLastActionTime();
if (this.player.containerMenu.containerId == packetplayinenchantitem.containerId() && !this.player.isSpectator()) {
if (!this.player.containerMenu.stillValid(this.player)) {
-@@ -1826,6 +2865,43 @@
+@@ -1875,6 +2908,43 @@
boolean flag1 = packetplayinsetcreativeslot.slotNum() >= 1 && packetplayinsetcreativeslot.slotNum() <= 45;
boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize();
@@ -1684,7 +1639,7 @@
if (flag1 && flag2) {
this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.slotNum()).setByPlayer(itemstack);
-@@ -1848,6 +2924,7 @@
+@@ -1902,6 +2972,7 @@
}
private void updateSignText(PacketPlayInUpdateSign packetplayinupdatesign, List list) {
@@ -1692,7 +1647,7 @@
this.player.resetLastActionTime();
WorldServer worldserver = this.player.serverLevel();
BlockPosition blockposition = packetplayinupdatesign.getPos();
-@@ -1869,7 +2946,17 @@
+@@ -1923,7 +2994,17 @@
@Override
public void handlePlayerAbilities(PacketPlayInAbilities packetplayinabilities) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinabilities, this, this.player.serverLevel());
@@ -1711,7 +1666,7 @@
}
@Override
-@@ -1928,7 +3015,7 @@
+@@ -1982,7 +3063,7 @@
if (!this.waitingForSwitchToConfig) {
throw new IllegalStateException("Client acknowledged config, but none was requested");
} else {
@@ -1720,7 +1675,7 @@
}
}
-@@ -1953,8 +3040,10 @@
+@@ -2007,8 +3088,10 @@
});
}
@@ -1732,4 +1687,4 @@
+ // CraftBukkit end
@Override
- public EntityPlayer getPlayer() {
+ public void handleClientTickEnd(ServerboundClientTickEndPacket serverboundclienttickendpacket) {
diff --git a/nms-patches/net/minecraft/server/network/ServerCommonPacketListenerImpl.patch b/nms-patches/net/minecraft/server/network/ServerCommonPacketListenerImpl.patch
index a158caaa..53e150b2 100644
--- a/nms-patches/net/minecraft/server/network/ServerCommonPacketListenerImpl.patch
+++ b/nms-patches/net/minecraft/server/network/ServerCommonPacketListenerImpl.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
-@@ -28,8 +28,44 @@
+@@ -29,8 +29,44 @@
import net.minecraft.util.thread.IAsyncTaskHandler;
import org.slf4j.Logger;
@@ -46,7 +46,7 @@
private static final Logger LOGGER = LogUtils.getLogger();
public static final int LATENCY_CHECK_INTERVAL = 15000;
private static final int CLOSED_LISTENER_TIMEOUT = 15000;
-@@ -46,12 +82,24 @@
+@@ -47,12 +83,24 @@
private int latency;
private volatile boolean suspendFlushingOnServerThread = false;
@@ -72,7 +72,7 @@
}
private void close() {
-@@ -73,6 +121,7 @@
+@@ -80,6 +128,7 @@
@Override
public void handleKeepAlive(ServerboundKeepAlivePacket serverboundkeepalivepacket) {
@@ -80,7 +80,7 @@
if (this.keepAlivePending && serverboundkeepalivepacket.getId() == this.keepAliveChallenge) {
int i = (int) (SystemUtils.getMillis() - this.keepAliveTime);
-@@ -87,8 +136,56 @@
+@@ -94,8 +143,56 @@
@Override
public void handlePong(ServerboundPongPacket serverboundpongpacket) {}
@@ -138,7 +138,7 @@
@Override
public void handleResourcePackResponse(ServerboundResourcePackPacket serverboundresourcepackpacket) {
-@@ -97,11 +194,18 @@
+@@ -104,11 +201,18 @@
ServerCommonPacketListenerImpl.LOGGER.info("Disconnecting {} due to resource pack {} rejection", this.playerProfile().getName(), serverboundresourcepackpacket.id());
this.disconnect((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.requiredTexturePrompt.disconnect"));
}
@@ -157,8 +157,8 @@
this.disconnect(ServerCommonPacketListenerImpl.DISCONNECT_UNEXPECTED_QUERY);
}
-@@ -109,7 +213,7 @@
- this.server.getProfiler().push("keepAlive");
+@@ -116,7 +220,7 @@
+ Profiler.get().push("keepAlive");
long i = SystemUtils.getMillis();
- if (!this.isSingleplayerOwner() && i - this.keepAliveTime >= 15000L) {
@@ -166,7 +166,7 @@
if (this.keepAlivePending) {
this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE);
} else if (this.checkIfClosed(i)) {
-@@ -149,6 +253,14 @@
+@@ -156,6 +260,14 @@
}
public void send(Packet> packet, @Nullable PacketSendListener packetsendlistener) {
@@ -181,7 +181,7 @@
if (packet.isTerminal()) {
this.close();
}
-@@ -173,15 +285,61 @@
+@@ -180,15 +292,61 @@
}
public void disconnect(DisconnectionDetails disconnectiondetails) {
diff --git a/nms-patches/net/minecraft/server/players/PlayerList.patch b/nms-patches/net/minecraft/server/players/PlayerList.patch
index da2910eb..f4b02439 100644
--- a/nms-patches/net/minecraft/server/players/PlayerList.patch
+++ b/nms-patches/net/minecraft/server/players/PlayerList.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
-@@ -103,6 +103,27 @@
+@@ -104,6 +104,27 @@
import net.minecraft.world.scores.ScoreboardTeam;
import org.slf4j.Logger;
@@ -28,7 +28,7 @@
public abstract class PlayerList {
public static final File USERBANLIST_FILE = new File("banned-players.json");
-@@ -115,14 +136,16 @@
+@@ -116,14 +137,16 @@
private static final int SEND_PLAYER_INFO_INTERVAL = 600;
private static final SimpleDateFormat BAN_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
private final MinecraftServer server;
@@ -48,7 +48,7 @@
public final WorldNBTStorage playerIo;
private boolean doWhiteList;
private final LayeredRegistryAccess registries;
-@@ -133,13 +156,23 @@
+@@ -134,13 +157,23 @@
private static final boolean ALLOW_LOGOUTIVATOR = false;
private int sendAllPlayerInfoIn;
@@ -74,7 +74,7 @@
this.server = minecraftserver;
this.registries = layeredregistryaccess;
this.maxPlayers = i;
-@@ -149,25 +182,34 @@
+@@ -150,25 +183,34 @@
public void placeNewPlayer(NetworkManager networkmanager, EntityPlayer entityplayer, CommonListenerCookie commonlistenercookie) {
GameProfile gameprofile = entityplayer.getGameProfile();
UserCache usercache = this.server.getProfileCache();
@@ -114,7 +114,7 @@
WorldServer worldserver = this.server.getLevel(resourcekey);
WorldServer worldserver1;
-@@ -181,10 +223,11 @@
+@@ -182,10 +224,11 @@
entityplayer.setServerLevel(worldserver1);
String s1 = networkmanager.getLoggableAddress(this.server.logIPs());
@@ -128,7 +128,7 @@
PlayerConnection playerconnection = new PlayerConnection(this.server, networkmanager, entityplayer, commonlistenercookie);
networkmanager.setupInboundProtocol(GameProtocols.SERVERBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(this.server.registryAccess())), playerconnection);
-@@ -194,6 +237,7 @@
+@@ -195,6 +238,7 @@
boolean flag2 = gamerules.getBoolean(GameRules.RULE_LIMITED_CRAFTING);
playerconnection.send(new PacketPlayOutLogin(entityplayer.getId(), worlddata.isHardcore(), this.server.levelKeys(), this.getMaxPlayers(), this.viewDistance, this.simulationDistance, flag1, !flag, flag2, entityplayer.createCommonSpawnInfo(worldserver1), this.server.enforceSecureProfile()));
@@ -136,7 +136,7 @@
playerconnection.send(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
playerconnection.send(new PacketPlayOutAbilities(entityplayer.getAbilities()));
playerconnection.send(new PacketPlayOutHeldItemSlot(entityplayer.getInventory().selected));
-@@ -210,8 +254,10 @@
+@@ -213,8 +257,10 @@
} else {
ichatmutablecomponent = IChatBaseComponent.translatable("multiplayer.player.joined.renamed", entityplayer.getDisplayName(), s);
}
@@ -148,7 +148,7 @@
playerconnection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot());
ServerPing serverping = this.server.getStatus();
-@@ -219,18 +265,70 @@
+@@ -222,17 +268,70 @@
entityplayer.sendServerStatus(serverping);
}
@@ -215,39 +215,15 @@
+ worldserver1 = entityplayer.serverLevel(); // CraftBukkit - Update in case join event changed it
+ // CraftBukkit end
this.sendActivePlayerEffects(entityplayer);
- if (optional.isPresent() && ((NBTTagCompound) optional.get()).contains("RootVehicle", 10)) {
- NBTTagCompound nbttagcompound = ((NBTTagCompound) optional.get()).getCompound("RootVehicle");
-+ WorldServer finalWorldServer = worldserver1; // CraftBukkit - decompile error
- Entity entity = EntityTypes.loadEntityRecursive(nbttagcompound.getCompound("Entity"), worldserver1, (entity1) -> {
-- return !worldserver1.addWithUUID(entity1) ? null : entity1;
-+ return !finalWorldServer.addWithUUID(entity1) ? null : entity1; // CraftBukkit - decompile error
- });
-
- if (entity != null) {
-@@ -261,18 +359,20 @@
-
- if (!entityplayer.isPassenger()) {
- PlayerList.LOGGER.warn("Couldn't reattach entity to player");
-- entity.discard();
-+ entity.discard(null); // CraftBukkit - add Bukkit remove cause
- iterator = entity.getIndirectPassengers().iterator();
-
- while (iterator.hasNext()) {
- entity1 = (Entity) iterator.next();
-- entity1.discard();
-+ entity1.discard(null); // CraftBukkit - add Bukkit remove cause
- }
- }
- }
- }
-
+ entityplayer.loadAndSpawnEnderpearls(optional);
+ entityplayer.loadAndSpawnParentVehicle(optional);
entityplayer.initInventoryMenu();
+ // CraftBukkit - Moved from above, added world
+ PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", entityplayer.getName().getString(), s1, entityplayer.getId(), worldserver1.serverLevelData.getLevelName(), entityplayer.getX(), entityplayer.getY(), entityplayer.getZ());
}
public void updateEntireScoreboard(ScoreboardServer scoreboardserver, EntityPlayer entityplayer) {
-@@ -309,30 +409,31 @@
+@@ -269,30 +368,31 @@
}
public void addWorldborderListener(WorldServer worldserver) {
@@ -284,7 +260,7 @@
}
@Override
-@@ -359,14 +460,15 @@
+@@ -319,14 +419,15 @@
}
protected void save(EntityPlayer entityplayer) {
@@ -302,7 +278,7 @@
if (advancementdataplayer != null) {
advancementdataplayer.save();
-@@ -374,10 +476,24 @@
+@@ -334,10 +435,24 @@
}
@@ -328,7 +304,7 @@
this.save(entityplayer);
if (entityplayer.isPassenger()) {
Entity entity = entityplayer.getRootVehicle();
-@@ -386,7 +502,7 @@
+@@ -346,7 +461,7 @@
PlayerList.LOGGER.debug("Removing player mount");
entityplayer.stopRiding();
entity.getPassengersAndSelf().forEach((entity1) -> {
@@ -337,7 +313,16 @@
});
}
}
-@@ -401,17 +517,66 @@
+@@ -357,7 +472,7 @@
+ while (iterator.hasNext()) {
+ EntityEnderPearl entityenderpearl = (EntityEnderPearl) iterator.next();
+
+- entityenderpearl.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER);
++ entityenderpearl.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER, EntityRemoveEvent.Cause.PLAYER_QUIT); // CraftBukkit - add Bukkit remove cause
+ }
+
+ worldserver.removePlayerImmediately(entityplayer, Entity.RemovalReason.UNLOADED_WITH_PLAYER);
+@@ -369,17 +484,66 @@
if (entityplayer1 == entityplayer) {
this.playersByUUID.remove(uuid);
@@ -409,7 +394,7 @@
if (this.bans.isBanned(gameprofile)) {
GameProfileBanEntry gameprofilebanentry = (GameProfileBanEntry) this.bans.get(gameprofile);
-@@ -420,9 +585,11 @@
+@@ -388,9 +552,11 @@
ichatmutablecomponent.append((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.banned.expiration", PlayerList.BAN_DATE_FORMAT.format(gameprofilebanentry.getExpires())));
}
@@ -423,7 +408,7 @@
} else if (this.ipBans.isBanned(socketaddress)) {
IpBanEntry ipbanentry = this.ipBans.get(socketaddress);
-@@ -431,17 +598,32 @@
+@@ -399,17 +565,32 @@
ichatmutablecomponent.append((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.banned_ip.expiration", PlayerList.BAN_DATE_FORMAT.format(ipbanentry.getExpires())));
}
@@ -436,13 +421,13 @@
+ if (this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile)) {
+ event.disallow(PlayerLoginEvent.Result.KICK_FULL, "The server is full");
+ }
-+ }
+ }
+
+ cserver.getPluginManager().callEvent(event);
+ if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
+ loginlistener.disconnect(event.getKickMessage());
+ return null;
- }
++ }
+ return entity;
}
@@ -461,7 +446,7 @@
UUID uuid = gameprofile.getId();
Set set = Sets.newIdentityHashSet();
Iterator iterator = this.players.iterator();
-@@ -469,22 +651,41 @@
+@@ -437,22 +618,41 @@
}
return !set.isEmpty();
@@ -481,8 +466,8 @@
this.players.remove(entityplayer);
entityplayer.serverLevel().removePlayerImmediately(entityplayer, entity_removalreason);
+ /* CraftBukkit start
- DimensionTransition dimensiontransition = entityplayer.findRespawnPositionAndUseSpawnBlock(flag, DimensionTransition.DO_NOTHING);
- WorldServer worldserver = dimensiontransition.newLevel();
+ TeleportTransition teleporttransition = entityplayer.findRespawnPositionAndUseSpawnBlock(!flag, TeleportTransition.DO_NOTHING);
+ WorldServer worldserver = teleporttransition.newLevel();
EntityPlayer entityplayer1 = new EntityPlayer(this.server, worldserver, entityplayer.getGameProfile(), entityplayer.clientInformation());
+ // */
+ EntityPlayer entityplayer1 = entityplayer;
@@ -496,7 +481,7 @@
entityplayer1.setMainArm(entityplayer.getMainArm());
+ // CraftBukkit - not required, just copies old location into reused entity
+ /*
- if (!dimensiontransition.missingRespawnBlock()) {
+ if (!teleporttransition.missingRespawnBlock()) {
entityplayer1.copyRespawnPosition(entityplayer);
}
+ */
@@ -504,35 +489,35 @@
Iterator iterator = entityplayer.getTags().iterator();
-@@ -494,11 +695,26 @@
+@@ -462,11 +662,26 @@
entityplayer1.addTag(s);
}
+ // CraftBukkit start - fire PlayerRespawnEvent
-+ DimensionTransition dimensiontransition;
++ TeleportTransition teleporttransition;
+ if (location == null) {
-+ dimensiontransition = entityplayer.findRespawnPositionAndUseSpawnBlock(flag, DimensionTransition.DO_NOTHING, reason);
++ teleporttransition = entityplayer.findRespawnPositionAndUseSpawnBlock(!flag, TeleportTransition.DO_NOTHING, reason);
+
+ if (!flag) entityplayer.reset(); // SPIGOT-4785
+ } else {
-+ dimensiontransition = new DimensionTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), Vec3D.ZERO, location.getYaw(), location.getPitch(), DimensionTransition.DO_NOTHING);
++ teleporttransition = new TeleportTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), Vec3D.ZERO, location.getYaw(), location.getPitch(), TeleportTransition.DO_NOTHING);
+ }
-+ WorldServer worldserver = dimensiontransition.newLevel();
++ WorldServer worldserver = teleporttransition.newLevel();
+ entityplayer1.spawnIn(worldserver);
+ entityplayer1.unsetRemoved();
+ entityplayer1.setShiftKeyDown(false);
- Vec3D vec3d = dimensiontransition.pos();
+ Vec3D vec3d = teleporttransition.position();
-- entityplayer1.moveTo(vec3d.x, vec3d.y, vec3d.z, dimensiontransition.yRot(), dimensiontransition.xRot());
-+ entityplayer1.forceSetPositionRotation(vec3d.x, vec3d.y, vec3d.z, dimensiontransition.yRot(), dimensiontransition.xRot());
+- entityplayer1.moveTo(vec3d.x, vec3d.y, vec3d.z, teleporttransition.yRot(), teleporttransition.xRot());
++ entityplayer1.forceSetPositionRotation(vec3d.x, vec3d.y, vec3d.z, teleporttransition.yRot(), teleporttransition.xRot());
+ // CraftBukkit end
- if (dimensiontransition.missingRespawnBlock()) {
+ if (teleporttransition.missingRespawnBlock()) {
entityplayer1.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.NO_RESPAWN_BLOCK_AVAILABLE, 0.0F));
+ entityplayer1.setRespawnPosition(null, null, 0f, false, false, PlayerSpawnChangeEvent.Cause.RESET); // CraftBukkit - SPIGOT-5988: Clear respawn location when obstructed
}
int i = flag ? 1 : 0;
-@@ -506,17 +722,19 @@
+@@ -474,17 +689,19 @@
WorldData worlddata = worldserver1.getLevelData();
entityplayer1.connection.send(new PacketPlayOutRespawn(entityplayer1.createCommonSpawnInfo(worldserver1), (byte) i));
@@ -555,9 +540,9 @@
+ }
+ // entityplayer1.initInventoryMenu();
entityplayer1.setHealth(entityplayer1.getHealth());
- if (!flag) {
- BlockPosition blockposition = BlockPosition.containing(dimensiontransition.pos());
-@@ -526,6 +744,27 @@
+ BlockPosition blockposition = entityplayer1.getRespawnPosition();
+ WorldServer worldserver2 = this.server.getLevel(entityplayer1.getRespawnDimension());
+@@ -496,6 +713,27 @@
entityplayer1.connection.send(new PacketPlayOutNamedSoundEffect(SoundEffects.RESPAWN_ANCHOR_DEPLETE, SoundCategory.BLOCKS, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), 1.0F, 1.0F, worldserver.getRandom().nextLong()));
}
}
@@ -585,7 +570,7 @@
return entityplayer1;
}
-@@ -554,7 +793,18 @@
+@@ -524,7 +762,18 @@
public void tick() {
if (++this.sendAllPlayerInfoIn > 600) {
@@ -605,7 +590,7 @@
this.sendAllPlayerInfoIn = 0;
}
-@@ -571,6 +821,25 @@
+@@ -541,6 +790,25 @@
}
@@ -631,7 +616,7 @@
public void broadcastAll(Packet> packet, ResourceKey resourcekey) {
Iterator iterator = this.players.iterator();
-@@ -649,7 +918,7 @@
+@@ -619,7 +887,7 @@
}
public void deop(GameProfile gameprofile) {
@@ -640,7 +625,7 @@
EntityPlayer entityplayer = this.getPlayer(gameprofile.getId());
if (entityplayer != null) {
-@@ -673,6 +942,7 @@
+@@ -643,6 +911,7 @@
entityplayer.connection.send(new PacketPlayOutEntityStatus(entityplayer, b0));
}
@@ -648,7 +633,7 @@
this.server.getCommands().sendCommands(entityplayer);
}
-@@ -703,6 +973,12 @@
+@@ -673,6 +942,12 @@
for (int i = 0; i < this.players.size(); ++i) {
EntityPlayer entityplayer = (EntityPlayer) this.players.get(i);
@@ -661,7 +646,7 @@
if (entityplayer != entityhuman && entityplayer.level().dimension() == resourcekey) {
double d4 = d0 - entityplayer.getX();
double d5 = d1 - entityplayer.getY();
-@@ -742,15 +1018,19 @@
+@@ -712,15 +987,19 @@
public void reloadWhiteList() {}
public void sendLevelInfo(EntityPlayer entityplayer, WorldServer worldserver) {
@@ -685,7 +670,7 @@
}
entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.LEVEL_CHUNKS_LOAD_START, 0.0F));
-@@ -759,8 +1039,16 @@
+@@ -729,8 +1008,16 @@
public void sendAllPlayerInfo(EntityPlayer entityplayer) {
entityplayer.inventoryMenu.sendAllDataToRemote();
@@ -695,15 +680,15 @@
+ entityplayer.refreshEntityData(entityplayer); // CraftBukkkit - SPIGOT-7218: sync metadata
entityplayer.connection.send(new PacketPlayOutHeldItemSlot(entityplayer.getInventory().selected));
+ // CraftBukkit start - from GameRules
-+ int i = entityplayer.level().getGameRules().getBoolean(GameRules.RULE_REDUCEDDEBUGINFO) ? 22 : 23;
++ int i = entityplayer.serverLevel().getGameRules().getBoolean(GameRules.RULE_REDUCEDDEBUGINFO) ? 22 : 23;
+ entityplayer.connection.send(new PacketPlayOutEntityStatus(entityplayer, (byte) i));
-+ float immediateRespawn = entityplayer.level().getGameRules().getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN) ? 1.0F: 0.0F;
++ float immediateRespawn = entityplayer.serverLevel().getGameRules().getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN) ? 1.0F: 0.0F;
+ entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.IMMEDIATE_RESPAWN, immediateRespawn));
+ // CraftBukkit end
}
public int getPlayerCount() {
-@@ -816,12 +1104,22 @@
+@@ -786,12 +1073,22 @@
}
public void removeAll() {
@@ -728,7 +713,7 @@
public void broadcastSystemMessage(IChatBaseComponent ichatbasecomponent, boolean flag) {
this.broadcastSystemMessage(ichatbasecomponent, (entityplayer) -> {
return ichatbasecomponent;
-@@ -879,16 +1177,23 @@
+@@ -849,16 +1146,23 @@
return playerchatmessage.hasSignature() && !playerchatmessage.hasExpiredServer(Instant.now());
}
@@ -756,7 +741,7 @@
Path path = file2.toPath();
if (FileUtils.isPathNormalized(path) && FileUtils.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) {
-@@ -897,7 +1202,7 @@
+@@ -867,7 +1171,7 @@
}
serverstatisticmanager = new ServerStatisticManager(this.server, file1);
@@ -765,7 +750,7 @@
}
return serverstatisticmanager;
-@@ -905,13 +1210,13 @@
+@@ -875,13 +1179,13 @@
public AdvancementDataPlayer getPlayerAdvancements(EntityPlayer entityplayer) {
UUID uuid = entityplayer.getUUID();
@@ -781,7 +766,7 @@
}
advancementdataplayer.setPlayer(entityplayer);
-@@ -962,13 +1267,20 @@
+@@ -932,13 +1236,20 @@
}
public void reloadResources() {
@@ -802,4 +787,4 @@
+ // CraftBukkit end
this.broadcastAll(new ClientboundUpdateTagsPacket(TagNetworkSerialization.serializeTagsToNetwork(this.registries)));
- PacketPlayOutRecipeUpdate packetplayoutrecipeupdate = new PacketPlayOutRecipeUpdate(this.server.getRecipeManager().getOrderedRecipes());
+ CraftingManager craftingmanager = this.server.getRecipeManager();
diff --git a/nms-patches/net/minecraft/stats/RecipeBookServer.patch b/nms-patches/net/minecraft/stats/RecipeBookServer.patch
new file mode 100644
index 00000000..38c18d21
--- /dev/null
+++ b/nms-patches/net/minecraft/stats/RecipeBookServer.patch
@@ -0,0 +1,38 @@
+--- a/net/minecraft/stats/RecipeBookServer.java
++++ b/net/minecraft/stats/RecipeBookServer.java
+@@ -29,6 +29,8 @@
+ import net.minecraft.world.item.crafting.display.RecipeDisplayId;
+ import org.slf4j.Logger;
+
++import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
++
+ public class RecipeBookServer extends RecipeBook {
+
+ public static final String RECIPE_BOOK_TAG = "recipeBook";
+@@ -72,7 +74,7 @@
+ RecipeHolder> recipeholder = (RecipeHolder) iterator.next();
+ ResourceKey> resourcekey = recipeholder.id();
+
+- if (!this.known.contains(resourcekey) && !recipeholder.value().isSpecial()) {
++ if (!this.known.contains(resourcekey) && !recipeholder.value().isSpecial() && CraftEventFactory.handlePlayerRecipeListUpdateEvent(entityplayer, resourcekey.location())) { // CraftBukkit
+ this.add(resourcekey);
+ this.addHighlight(resourcekey);
+ this.displayResolver.displaysForRecipe(resourcekey, (recipedisplayentry) -> {
+@@ -82,7 +84,7 @@
+ }
+ }
+
+- if (!list.isEmpty()) {
++ if (!list.isEmpty() && entityplayer.connection != null) { // SPIGOT-4478 during PlayerLoginEvent
+ entityplayer.connection.send(new ClientboundRecipeBookAddPacket(list, false));
+ }
+
+@@ -105,7 +107,7 @@
+ }
+ }
+
+- if (!list.isEmpty()) {
++ if (!list.isEmpty() && entityplayer.connection != null) { // SPIGOT-4478 during PlayerLoginEvent
+ entityplayer.connection.send(new ClientboundRecipeBookRemovePacket(list));
+ }
+
diff --git a/nms-patches/net/minecraft/stats/ServerStatisticManager.patch b/nms-patches/net/minecraft/stats/ServerStatisticManager.patch
new file mode 100644
index 00000000..ac3c4fff
--- /dev/null
+++ b/nms-patches/net/minecraft/stats/ServerStatisticManager.patch
@@ -0,0 +1,26 @@
+--- a/net/minecraft/stats/ServerStatisticManager.java
++++ b/net/minecraft/stats/ServerStatisticManager.java
+@@ -1,3 +1,4 @@
++// mc-dev import
+ package net.minecraft.stats;
+
+ import com.google.common.collect.Maps;
+@@ -158,13 +159,12 @@
+ }
+
+ private Optional> getStat(StatisticWrapper statisticwrapper, String s) {
+- Optional optional = Optional.ofNullable(MinecraftKey.tryParse(s));
+- IRegistry iregistry = statisticwrapper.getRegistry();
++ // CraftBukkit - decompile error start
++ Optional optional = Optional.ofNullable(MinecraftKey.tryParse(s));
++ IRegistry iregistry = statisticwrapper.getRegistry();
+
+- Objects.requireNonNull(iregistry);
+- optional = optional.flatMap(iregistry::getOptional);
+- Objects.requireNonNull(statisticwrapper);
+- return optional.map(statisticwrapper::get);
++ return optional.flatMap(iregistry::getOptional).map(statisticwrapper::get);
++ // CraftBukkit - decompile error end
+ }
+
+ private static NBTTagCompound fromJson(JsonObject jsonobject) {
diff --git a/nms-patches/net/minecraft/stats/StatisticManager.patch b/nms-patches/net/minecraft/stats/StatisticManager.patch
new file mode 100644
index 00000000..118075d5
--- /dev/null
+++ b/nms-patches/net/minecraft/stats/StatisticManager.patch
@@ -0,0 +1,15 @@
+--- a/net/minecraft/stats/StatisticManager.java
++++ b/net/minecraft/stats/StatisticManager.java
+@@ -16,6 +16,12 @@
+ public void increment(EntityHuman entityhuman, Statistic> statistic, int i) {
+ int j = (int) Math.min((long) this.getValue(statistic) + (long) i, 2147483647L);
+
++ // CraftBukkit start - fire Statistic events
++ org.bukkit.event.Cancellable cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.handleStatisticsIncrease(entityhuman, statistic, this.getValue(statistic), j);
++ if (cancellable != null && cancellable.isCancelled()) {
++ return;
++ }
++ // CraftBukkit end
+ this.setValue(entityhuman, statistic, j);
+ }
+
diff --git a/nms-patches/net/minecraft/util/SpawnUtil.patch b/nms-patches/net/minecraft/util/SpawnUtil.patch
new file mode 100644
index 00000000..47da6b11
--- /dev/null
+++ b/nms-patches/net/minecraft/util/SpawnUtil.patch
@@ -0,0 +1,34 @@
+--- a/net/minecraft/util/SpawnUtil.java
++++ b/net/minecraft/util/SpawnUtil.java
+@@ -21,6 +21,12 @@
+ public SpawnUtil() {}
+
+ public static Optional trySpawnMob(EntityTypes entitytypes, EntitySpawnReason entityspawnreason, WorldServer worldserver, BlockPosition blockposition, int i, int j, int k, SpawnUtil.a spawnutil_a) {
++ // CraftBukkit start
++ return trySpawnMob(entitytypes, entityspawnreason, worldserver, blockposition, i, j, k, spawnutil_a, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
++ }
++
++ public static Optional trySpawnMob(EntityTypes entitytypes, EntitySpawnReason entityspawnreason, WorldServer worldserver, BlockPosition blockposition, int i, int j, int k, SpawnUtil.a spawnutil_a, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
++ // CraftBukkit end
+ BlockPosition.MutableBlockPosition blockposition_mutableblockposition = blockposition.mutable();
+
+ for (int l = 0; l < i; ++l) {
+@@ -29,15 +35,15 @@
+
+ blockposition_mutableblockposition.setWithOffset(blockposition, i1, k, j1);
+ if (worldserver.getWorldBorder().isWithinBounds((BlockPosition) blockposition_mutableblockposition) && moveToPossibleSpawnPosition(worldserver, k, blockposition_mutableblockposition, spawnutil_a)) {
+- T t0 = (EntityInsentient) entitytypes.create(worldserver, (Consumer) null, blockposition_mutableblockposition, entityspawnreason, false, false);
++ T t0 = entitytypes.create(worldserver, (Consumer) null, blockposition_mutableblockposition, entityspawnreason, false, false); // CraftBukkit - decompile error
+
+ if (t0 != null) {
+ if (t0.checkSpawnRules(worldserver, entityspawnreason) && t0.checkSpawnObstruction(worldserver)) {
+- worldserver.addFreshEntityWithPassengers(t0);
++ worldserver.addFreshEntityWithPassengers(t0, reason); // CraftBukkit
+ return Optional.of(t0);
+ }
+
+- t0.discard();
++ t0.discard(null); // CraftBukkit - add Bukkit remove cause
+ }
+ }
+ }
diff --git a/nms-patches/net/minecraft/util/TickThrottler.patch b/nms-patches/net/minecraft/util/TickThrottler.patch
new file mode 100644
index 00000000..38e6ddbc
--- /dev/null
+++ b/nms-patches/net/minecraft/util/TickThrottler.patch
@@ -0,0 +1,53 @@
+--- a/net/minecraft/util/TickThrottler.java
++++ b/net/minecraft/util/TickThrottler.java
+@@ -1,10 +1,14 @@
+ package net.minecraft.util;
+
++// CraftBukkit start
++import java.util.concurrent.atomic.AtomicInteger;
++// CraftBukkit end
++
+ public class TickThrottler {
+
+ private final int incrementStep;
+ private final int threshold;
+- private int count;
++ private final AtomicInteger count = new AtomicInteger(); // CraftBukkit - multithreaded field
+
+ public TickThrottler(int i, int j) {
+ this.incrementStep = i;
+@@ -12,17 +16,32 @@
+ }
+
+ public void increment() {
+- this.count += this.incrementStep;
++ this.count.addAndGet(this.incrementStep); // CraftBukkit - use thread-safe field access instead
+ }
+
+ public void tick() {
++ // CraftBukkit start
++ for (int val; (val = this.count.get()) > 0 && !count.compareAndSet(val, val - 1); ) ;
++ /* Use thread-safe field access instead
+ if (this.count > 0) {
+ --this.count;
+ }
++ */
++ // CraftBukkit end
+
+ }
+
+ public boolean isUnderThreshold() {
+- return this.count < this.threshold;
++ // CraftBukkit start - use thread-safe field access instead
++ return this.count.get() < this.threshold;
++ }
++
++ public boolean isIncrementAndUnderThreshold() {
++ return isIncrementAndUnderThreshold(this.incrementStep, this.threshold);
++ }
++
++ public boolean isIncrementAndUnderThreshold(int incrementStep, int threshold) {
++ return this.count.addAndGet(incrementStep) < threshold;
++ // CraftBukkit end
+ }
+ }
diff --git a/nms-patches/net/minecraft/util/datafix/DataConverterRegistry.patch b/nms-patches/net/minecraft/util/datafix/DataConverterRegistry.patch
new file mode 100644
index 00000000..1148881f
--- /dev/null
+++ b/nms-patches/net/minecraft/util/datafix/DataConverterRegistry.patch
@@ -0,0 +1,82 @@
+--- a/net/minecraft/util/datafix/DataConverterRegistry.java
++++ b/net/minecraft/util/datafix/DataConverterRegistry.java
+@@ -510,6 +510,18 @@
+ datafixerbuilder.addFixer(new DataConverterItemFrame(schema44, false));
+ Schema schema45 = datafixerbuilder.addSchema(1458, DataConverterRegistry.SAME_NAMESPACED);
+
++ // CraftBukkit start
++ datafixerbuilder.addFixer(new com.mojang.datafixers.DataFix(schema45, false) {
++ @Override
++ protected com.mojang.datafixers.TypeRewriteRule makeRule() {
++ return this.fixTypeEverywhereTyped("Player CustomName", this.getInputSchema().getType(DataConverterTypes.PLAYER), (typed) -> {
++ return typed.update(DSL.remainderFinder(), (dynamic) -> {
++ return DataConverterCustomNameEntity.fixTagCustomName(dynamic);
++ });
++ });
++ }
++ });
++ // CraftBukkit end
+ datafixerbuilder.addFixer(new DataConverterCustomNameEntity(schema45, false));
+ datafixerbuilder.addFixer(new DataConverterCustomNameItem(schema45, false));
+ datafixerbuilder.addFixer(new DataConverterCustomNameTile(schema45, false));
+@@ -768,7 +780,8 @@
+ datafixerbuilder.addFixer(new DataConverterAddChoices(schema110, "Added Zoglin", DataConverterTypes.ENTITY));
+ Schema schema111 = datafixerbuilder.addSchema(2523, DataConverterRegistry.SAME_NAMESPACED);
+
+- datafixerbuilder.addFixer(new DataConverterAttributes(schema111, "Attribute renames", createRenamerNoNamespace(ImmutableMap.builder().put("generic.maxHealth", "minecraft:generic.max_health").put("Max Health", "minecraft:generic.max_health").put("zombie.spawnReinforcements", "minecraft:zombie.spawn_reinforcements").put("Spawn Reinforcements Chance", "minecraft:zombie.spawn_reinforcements").put("horse.jumpStrength", "minecraft:horse.jump_strength").put("Jump Strength", "minecraft:horse.jump_strength").put("generic.followRange", "minecraft:generic.follow_range").put("Follow Range", "minecraft:generic.follow_range").put("generic.knockbackResistance", "minecraft:generic.knockback_resistance").put("Knockback Resistance", "minecraft:generic.knockback_resistance").put("generic.movementSpeed", "minecraft:generic.movement_speed").put("Movement Speed", "minecraft:generic.movement_speed").put("generic.flyingSpeed", "minecraft:generic.flying_speed").put("Flying Speed", "minecraft:generic.flying_speed").put("generic.attackDamage", "minecraft:generic.attack_damage").put("generic.attackKnockback", "minecraft:generic.attack_knockback").put("generic.attackSpeed", "minecraft:generic.attack_speed").put("generic.armorToughness", "minecraft:generic.armor_toughness").build())));
++ // CraftBukkit - decompile error
++ datafixerbuilder.addFixer(new DataConverterAttributes(schema111, "Attribute renames", createRenamerNoNamespace(ImmutableMap.builder().put("generic.maxHealth", "minecraft:generic.max_health").put("Max Health", "minecraft:generic.max_health").put("zombie.spawnReinforcements", "minecraft:zombie.spawn_reinforcements").put("Spawn Reinforcements Chance", "minecraft:zombie.spawn_reinforcements").put("horse.jumpStrength", "minecraft:horse.jump_strength").put("Jump Strength", "minecraft:horse.jump_strength").put("generic.followRange", "minecraft:generic.follow_range").put("Follow Range", "minecraft:generic.follow_range").put("generic.knockbackResistance", "minecraft:generic.knockback_resistance").put("Knockback Resistance", "minecraft:generic.knockback_resistance").put("generic.movementSpeed", "minecraft:generic.movement_speed").put("Movement Speed", "minecraft:generic.movement_speed").put("generic.flyingSpeed", "minecraft:generic.flying_speed").put("Flying Speed", "minecraft:generic.flying_speed").put("generic.attackDamage", "minecraft:generic.attack_damage").put("generic.attackKnockback", "minecraft:generic.attack_knockback").put("generic.attackSpeed", "minecraft:generic.attack_speed").put("generic.armorToughness", "minecraft:generic.armor_toughness").build())));
+ Schema schema112 = datafixerbuilder.addSchema(2527, DataConverterRegistry.SAME_NAMESPACED);
+
+ datafixerbuilder.addFixer(new DataConverterBitStorageAlign(schema112));
+@@ -831,12 +844,14 @@
+ datafixerbuilder.addFixer(new DataConverterAddChoices(schema130, "Added Glow Squid", DataConverterTypes.ENTITY));
+ datafixerbuilder.addFixer(new DataConverterAddChoices(schema130, "Added Glow Item Frame", DataConverterTypes.ENTITY));
+ Schema schema131 = datafixerbuilder.addSchema(2690, DataConverterRegistry.SAME_NAMESPACED);
+- ImmutableMap immutablemap = ImmutableMap.builder().put("minecraft:weathered_copper_block", "minecraft:oxidized_copper_block").put("minecraft:semi_weathered_copper_block", "minecraft:weathered_copper_block").put("minecraft:lightly_weathered_copper_block", "minecraft:exposed_copper_block").put("minecraft:weathered_cut_copper", "minecraft:oxidized_cut_copper").put("minecraft:semi_weathered_cut_copper", "minecraft:weathered_cut_copper").put("minecraft:lightly_weathered_cut_copper", "minecraft:exposed_cut_copper").put("minecraft:weathered_cut_copper_stairs", "minecraft:oxidized_cut_copper_stairs").put("minecraft:semi_weathered_cut_copper_stairs", "minecraft:weathered_cut_copper_stairs").put("minecraft:lightly_weathered_cut_copper_stairs", "minecraft:exposed_cut_copper_stairs").put("minecraft:weathered_cut_copper_slab", "minecraft:oxidized_cut_copper_slab").put("minecraft:semi_weathered_cut_copper_slab", "minecraft:weathered_cut_copper_slab").put("minecraft:lightly_weathered_cut_copper_slab", "minecraft:exposed_cut_copper_slab").put("minecraft:waxed_semi_weathered_copper", "minecraft:waxed_weathered_copper").put("minecraft:waxed_lightly_weathered_copper", "minecraft:waxed_exposed_copper").put("minecraft:waxed_semi_weathered_cut_copper", "minecraft:waxed_weathered_cut_copper").put("minecraft:waxed_lightly_weathered_cut_copper", "minecraft:waxed_exposed_cut_copper").put("minecraft:waxed_semi_weathered_cut_copper_stairs", "minecraft:waxed_weathered_cut_copper_stairs").put("minecraft:waxed_lightly_weathered_cut_copper_stairs", "minecraft:waxed_exposed_cut_copper_stairs").put("minecraft:waxed_semi_weathered_cut_copper_slab", "minecraft:waxed_weathered_cut_copper_slab").put("minecraft:waxed_lightly_weathered_cut_copper_slab", "minecraft:waxed_exposed_cut_copper_slab").build();
++ // CraftBukkit - decompile error
++ ImmutableMap immutablemap = ImmutableMap.builder().put("minecraft:weathered_copper_block", "minecraft:oxidized_copper_block").put("minecraft:semi_weathered_copper_block", "minecraft:weathered_copper_block").put("minecraft:lightly_weathered_copper_block", "minecraft:exposed_copper_block").put("minecraft:weathered_cut_copper", "minecraft:oxidized_cut_copper").put("minecraft:semi_weathered_cut_copper", "minecraft:weathered_cut_copper").put("minecraft:lightly_weathered_cut_copper", "minecraft:exposed_cut_copper").put("minecraft:weathered_cut_copper_stairs", "minecraft:oxidized_cut_copper_stairs").put("minecraft:semi_weathered_cut_copper_stairs", "minecraft:weathered_cut_copper_stairs").put("minecraft:lightly_weathered_cut_copper_stairs", "minecraft:exposed_cut_copper_stairs").put("minecraft:weathered_cut_copper_slab", "minecraft:oxidized_cut_copper_slab").put("minecraft:semi_weathered_cut_copper_slab", "minecraft:weathered_cut_copper_slab").put("minecraft:lightly_weathered_cut_copper_slab", "minecraft:exposed_cut_copper_slab").put("minecraft:waxed_semi_weathered_copper", "minecraft:waxed_weathered_copper").put("minecraft:waxed_lightly_weathered_copper", "minecraft:waxed_exposed_copper").put("minecraft:waxed_semi_weathered_cut_copper", "minecraft:waxed_weathered_cut_copper").put("minecraft:waxed_lightly_weathered_cut_copper", "minecraft:waxed_exposed_cut_copper").put("minecraft:waxed_semi_weathered_cut_copper_stairs", "minecraft:waxed_weathered_cut_copper_stairs").put("minecraft:waxed_lightly_weathered_cut_copper_stairs", "minecraft:waxed_exposed_cut_copper_stairs").put("minecraft:waxed_semi_weathered_cut_copper_slab", "minecraft:waxed_weathered_cut_copper_slab").put("minecraft:waxed_lightly_weathered_cut_copper_slab", "minecraft:waxed_exposed_cut_copper_slab").build();
+
+ datafixerbuilder.addFixer(DataConverterItemName.create(schema131, "Renamed copper block items to new oxidized terms", createRenamer(immutablemap)));
+ datafixerbuilder.addFixer(DataConverterBlockRename.create(schema131, "Renamed copper blocks to new oxidized terms", createRenamer(immutablemap)));
+ Schema schema132 = datafixerbuilder.addSchema(2691, DataConverterRegistry.SAME_NAMESPACED);
+- ImmutableMap immutablemap1 = ImmutableMap.builder().put("minecraft:waxed_copper", "minecraft:waxed_copper_block").put("minecraft:oxidized_copper_block", "minecraft:oxidized_copper").put("minecraft:weathered_copper_block", "minecraft:weathered_copper").put("minecraft:exposed_copper_block", "minecraft:exposed_copper").build();
++ // CraftBukkit - decompile error
++ ImmutableMap immutablemap1 = ImmutableMap.builder().put("minecraft:waxed_copper", "minecraft:waxed_copper_block").put("minecraft:oxidized_copper_block", "minecraft:oxidized_copper").put("minecraft:weathered_copper_block", "minecraft:weathered_copper").put("minecraft:exposed_copper_block", "minecraft:exposed_copper").build();
+
+ datafixerbuilder.addFixer(DataConverterItemName.create(schema132, "Rename copper item suffixes", createRenamer(immutablemap1)));
+ datafixerbuilder.addFixer(DataConverterBlockRename.create(schema132, "Rename copper blocks suffixes", createRenamer(immutablemap1)));
+@@ -844,7 +859,8 @@
+
+ datafixerbuilder.addFixer(new AddFlagIfNotPresentFix(schema133, DataConverterTypes.WORLD_GEN_SETTINGS, "has_increased_height_already", false));
+ Schema schema134 = datafixerbuilder.addSchema(2696, DataConverterRegistry.SAME_NAMESPACED);
+- ImmutableMap immutablemap2 = ImmutableMap.builder().put("minecraft:grimstone", "minecraft:deepslate").put("minecraft:grimstone_slab", "minecraft:cobbled_deepslate_slab").put("minecraft:grimstone_stairs", "minecraft:cobbled_deepslate_stairs").put("minecraft:grimstone_wall", "minecraft:cobbled_deepslate_wall").put("minecraft:polished_grimstone", "minecraft:polished_deepslate").put("minecraft:polished_grimstone_slab", "minecraft:polished_deepslate_slab").put("minecraft:polished_grimstone_stairs", "minecraft:polished_deepslate_stairs").put("minecraft:polished_grimstone_wall", "minecraft:polished_deepslate_wall").put("minecraft:grimstone_tiles", "minecraft:deepslate_tiles").put("minecraft:grimstone_tile_slab", "minecraft:deepslate_tile_slab").put("minecraft:grimstone_tile_stairs", "minecraft:deepslate_tile_stairs").put("minecraft:grimstone_tile_wall", "minecraft:deepslate_tile_wall").put("minecraft:grimstone_bricks", "minecraft:deepslate_bricks").put("minecraft:grimstone_brick_slab", "minecraft:deepslate_brick_slab").put("minecraft:grimstone_brick_stairs", "minecraft:deepslate_brick_stairs").put("minecraft:grimstone_brick_wall", "minecraft:deepslate_brick_wall").put("minecraft:chiseled_grimstone", "minecraft:chiseled_deepslate").build();
++ // CraftBukkit - decompile error
++ ImmutableMap immutablemap2 = ImmutableMap.builder().put("minecraft:grimstone", "minecraft:deepslate").put("minecraft:grimstone_slab", "minecraft:cobbled_deepslate_slab").put("minecraft:grimstone_stairs", "minecraft:cobbled_deepslate_stairs").put("minecraft:grimstone_wall", "minecraft:cobbled_deepslate_wall").put("minecraft:polished_grimstone", "minecraft:polished_deepslate").put("minecraft:polished_grimstone_slab", "minecraft:polished_deepslate_slab").put("minecraft:polished_grimstone_stairs", "minecraft:polished_deepslate_stairs").put("minecraft:polished_grimstone_wall", "minecraft:polished_deepslate_wall").put("minecraft:grimstone_tiles", "minecraft:deepslate_tiles").put("minecraft:grimstone_tile_slab", "minecraft:deepslate_tile_slab").put("minecraft:grimstone_tile_stairs", "minecraft:deepslate_tile_stairs").put("minecraft:grimstone_tile_wall", "minecraft:deepslate_tile_wall").put("minecraft:grimstone_bricks", "minecraft:deepslate_bricks").put("minecraft:grimstone_brick_slab", "minecraft:deepslate_brick_slab").put("minecraft:grimstone_brick_stairs", "minecraft:deepslate_brick_stairs").put("minecraft:grimstone_brick_wall", "minecraft:deepslate_brick_wall").put("minecraft:chiseled_grimstone", "minecraft:chiseled_deepslate").build();
+
+ datafixerbuilder.addFixer(DataConverterItemName.create(schema134, "Renamed grimstone block items to deepslate", createRenamer(immutablemap2)));
+ datafixerbuilder.addFixer(DataConverterBlockRename.create(schema134, "Renamed grimstone blocks to deepslate", createRenamer(immutablemap2)));
+@@ -931,10 +947,11 @@
+ datafixerbuilder.addFixer(new DataConverterAddChoices(schema159, "Added Allay", DataConverterTypes.ENTITY));
+ Schema schema160 = datafixerbuilder.addSchema(3084, DataConverterRegistry.SAME_NAMESPACED);
+
+- datafixerbuilder.addFixer(new NamespacedTypeRenameFix(schema160, "game_event_renames_3084", DataConverterTypes.GAME_EVENT_NAME, createRenamer(ImmutableMap.builder().put("minecraft:block_press", "minecraft:block_activate").put("minecraft:block_switch", "minecraft:block_activate").put("minecraft:block_unpress", "minecraft:block_deactivate").put("minecraft:block_unswitch", "minecraft:block_deactivate").put("minecraft:drinking_finish", "minecraft:drink").put("minecraft:elytra_free_fall", "minecraft:elytra_glide").put("minecraft:entity_damaged", "minecraft:entity_damage").put("minecraft:entity_dying", "minecraft:entity_die").put("minecraft:entity_killed", "minecraft:entity_die").put("minecraft:mob_interact", "minecraft:entity_interact").put("minecraft:ravager_roar", "minecraft:entity_roar").put("minecraft:ring_bell", "minecraft:block_change").put("minecraft:shulker_close", "minecraft:container_close").put("minecraft:shulker_open", "minecraft:container_open").put("minecraft:wolf_shaking", "minecraft:entity_shake").build())));
++ // CraftBukkit - decompile error
++ datafixerbuilder.addFixer(new NamespacedTypeRenameFix(schema160, "game_event_renames_3084", DataConverterTypes.GAME_EVENT_NAME, createRenamer(ImmutableMap.builder().put("minecraft:block_press", "minecraft:block_activate").put("minecraft:block_switch", "minecraft:block_activate").put("minecraft:block_unpress", "minecraft:block_deactivate").put("minecraft:block_unswitch", "minecraft:block_deactivate").put("minecraft:drinking_finish", "minecraft:drink").put("minecraft:elytra_free_fall", "minecraft:elytra_glide").put("minecraft:entity_damaged", "minecraft:entity_damage").put("minecraft:entity_dying", "minecraft:entity_die").put("minecraft:entity_killed", "minecraft:entity_die").put("minecraft:mob_interact", "minecraft:entity_interact").put("minecraft:ravager_roar", "minecraft:entity_roar").put("minecraft:ring_bell", "minecraft:block_change").put("minecraft:shulker_close", "minecraft:container_close").put("minecraft:shulker_open", "minecraft:container_open").put("minecraft:wolf_shaking", "minecraft:entity_shake").build())));
+ Schema schema161 = datafixerbuilder.addSchema(3086, DataConverterRegistry.SAME_NAMESPACED);
+ TypeReference typereference = DataConverterTypes.ENTITY;
+- Int2ObjectOpenHashMap int2objectopenhashmap = (Int2ObjectOpenHashMap) SystemUtils.make(new Int2ObjectOpenHashMap(), (int2objectopenhashmap1) -> {
++ Int2ObjectOpenHashMap int2objectopenhashmap = (Int2ObjectOpenHashMap) SystemUtils.make(new Int2ObjectOpenHashMap(), (int2objectopenhashmap1) -> { // CraftBukkit - decompile error
+ int2objectopenhashmap1.defaultReturnValue("minecraft:tabby");
+ int2objectopenhashmap1.put(0, "minecraft:tabby");
+ int2objectopenhashmap1.put(1, "minecraft:black");
+@@ -951,7 +968,8 @@
+
+ Objects.requireNonNull(int2objectopenhashmap);
+ datafixerbuilder.addFixer(new EntityVariantFix(schema161, "Change cat variant type", typereference, "minecraft:cat", "CatType", int2objectopenhashmap::get));
+- ImmutableMap immutablemap3 = ImmutableMap.builder().put("textures/entity/cat/tabby.png", "minecraft:tabby").put("textures/entity/cat/black.png", "minecraft:black").put("textures/entity/cat/red.png", "minecraft:red").put("textures/entity/cat/siamese.png", "minecraft:siamese").put("textures/entity/cat/british_shorthair.png", "minecraft:british").put("textures/entity/cat/calico.png", "minecraft:calico").put("textures/entity/cat/persian.png", "minecraft:persian").put("textures/entity/cat/ragdoll.png", "minecraft:ragdoll").put("textures/entity/cat/white.png", "minecraft:white").put("textures/entity/cat/jellie.png", "minecraft:jellie").put("textures/entity/cat/all_black.png", "minecraft:all_black").build();
++ // CraftBukkit - decompile error
++ ImmutableMap immutablemap3 = ImmutableMap.builder().put("textures/entity/cat/tabby.png", "minecraft:tabby").put("textures/entity/cat/black.png", "minecraft:black").put("textures/entity/cat/red.png", "minecraft:red").put("textures/entity/cat/siamese.png", "minecraft:siamese").put("textures/entity/cat/british_shorthair.png", "minecraft:british").put("textures/entity/cat/calico.png", "minecraft:calico").put("textures/entity/cat/persian.png", "minecraft:persian").put("textures/entity/cat/ragdoll.png", "minecraft:ragdoll").put("textures/entity/cat/white.png", "minecraft:white").put("textures/entity/cat/jellie.png", "minecraft:jellie").put("textures/entity/cat/all_black.png", "minecraft:all_black").build();
+
+ datafixerbuilder.addFixer(new CriteriaRenameFix(schema161, "Migrate cat variant advancement", "minecraft:husbandry/complete_catalogue", (s) -> {
+ return (String) immutablemap3.getOrDefault(s, s);
diff --git a/nms-patches/net/minecraft/util/datafix/fixes/DataConverterFlatten.patch b/nms-patches/net/minecraft/util/datafix/fixes/DataConverterFlatten.patch
new file mode 100644
index 00000000..6916dff5
--- /dev/null
+++ b/nms-patches/net/minecraft/util/datafix/fixes/DataConverterFlatten.patch
@@ -0,0 +1,11 @@
+--- a/net/minecraft/util/datafix/fixes/DataConverterFlatten.java
++++ b/net/minecraft/util/datafix/fixes/DataConverterFlatten.java
+@@ -376,7 +376,7 @@
+ Typed> typed2 = typed.getOrCreateTyped(opticfinder1);
+ Dynamic> dynamic1 = (Dynamic) typed2.get(DSL.remainderFinder());
+
+- dynamic1 = dynamic1.set("Damage", dynamic1.createInt(i));
++ if (i != 0) dynamic1 = dynamic1.set("Damage", dynamic1.createInt(i)); // CraftBukkit
+ typed1 = typed1.set(opticfinder1, typed2.set(DSL.remainderFinder(), dynamic1));
+ }
+
diff --git a/nms-patches/net/minecraft/util/datafix/fixes/DataConverterMap.patch b/nms-patches/net/minecraft/util/datafix/fixes/DataConverterMap.patch
new file mode 100644
index 00000000..41b8ab11
--- /dev/null
+++ b/nms-patches/net/minecraft/util/datafix/fixes/DataConverterMap.patch
@@ -0,0 +1,11 @@
+--- a/net/minecraft/util/datafix/fixes/DataConverterMap.java
++++ b/net/minecraft/util/datafix/fixes/DataConverterMap.java
+@@ -32,7 +32,7 @@
+ Typed> typed1 = typed.getOrCreateTyped(opticfinder1);
+ Dynamic> dynamic1 = (Dynamic) typed1.get(DSL.remainderFinder());
+
+- dynamic1 = dynamic1.set("map", dynamic1.createInt(dynamic.get("Damage").asInt(0)));
++ if (!dynamic1.getElement("map").result().isPresent()) dynamic1 = dynamic1.set("map", dynamic1.createInt(dynamic.get("Damage").asInt(0))); // CraftBukkit
+ return typed.set(opticfinder1, typed1.set(DSL.remainderFinder(), dynamic1));
+ } else {
+ return typed;
diff --git a/nms-patches/net/minecraft/util/worldupdate/WorldUpgrader.patch b/nms-patches/net/minecraft/util/worldupdate/WorldUpgrader.patch
new file mode 100644
index 00000000..722e0a99
--- /dev/null
+++ b/nms-patches/net/minecraft/util/worldupdate/WorldUpgrader.patch
@@ -0,0 +1,32 @@
+--- a/net/minecraft/util/worldupdate/WorldUpgrader.java
++++ b/net/minecraft/util/worldupdate/WorldUpgrader.java
+@@ -80,7 +80,7 @@
+
+ public WorldUpgrader(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, IRegistryCustom iregistrycustom, boolean flag, boolean flag1) {
+ this.dimensions = iregistrycustom.lookupOrThrow(Registries.LEVEL_STEM);
+- this.levels = (Set) this.dimensions.registryKeySet().stream().map(Registries::levelStemToLevel).collect(Collectors.toUnmodifiableSet());
++ this.levels = (Set) java.util.stream.Stream.of(convertable_conversionsession.dimensionType).map(Registries::levelStemToLevel).collect(Collectors.toUnmodifiableSet()); // CraftBukkit
+ this.eraseCache = flag;
+ this.dataFixer = datafixer;
+ this.levelStorage = convertable_conversionsession;
+@@ -197,9 +197,9 @@
+ if (nbttagcompound != null) {
+ int i = IChunkLoader.getVersion(nbttagcompound);
+ ChunkGenerator chunkgenerator = ((WorldDimension) WorldUpgrader.this.dimensions.getValueOrThrow(Registries.levelToLevelStem(resourcekey))).generator();
+- NBTTagCompound nbttagcompound1 = ichunkloader.upgradeChunkTag(resourcekey, () -> {
++ NBTTagCompound nbttagcompound1 = ichunkloader.upgradeChunkTag(Registries.levelToLevelStem(resourcekey), () -> { // CraftBukkit
+ return WorldUpgrader.this.overworldDataStorage;
+- }, nbttagcompound, chunkgenerator.getTypeNameForDataFixer());
++ }, nbttagcompound, chunkgenerator.getTypeNameForDataFixer(), chunkcoordintpair, null); // CraftBukkit
+ ChunkCoordIntPair chunkcoordintpair1 = new ChunkCoordIntPair(nbttagcompound1.getInt("xPos"), nbttagcompound1.getInt("zPos"));
+
+ if (!chunkcoordintpair1.equals(chunkcoordintpair)) {
+@@ -321,7 +321,7 @@
+ WorldUpgrader.c worldupgrader_c = (WorldUpgrader.c) iterator.next();
+ ResourceKey resourcekey = worldupgrader_c.dimensionKey;
+ ListIterator listiterator = worldupgrader_c.files;
+- T t0 = (AutoCloseable) worldupgrader_c.storage;
++ T t0 = (T) worldupgrader_c.storage; // CraftBukkit - decompile error
+
+ if (listiterator.hasNext()) {
+ WorldUpgrader.e worldupgrader_e = (WorldUpgrader.e) listiterator.next();
diff --git a/nms-patches/net/minecraft/world/ChestLock.patch b/nms-patches/net/minecraft/world/ChestLock.patch
deleted file mode 100644
index a6fe4a98..00000000
--- a/nms-patches/net/minecraft/world/ChestLock.patch
+++ /dev/null
@@ -1,35 +0,0 @@
---- a/net/minecraft/world/ChestLock.java
-+++ b/net/minecraft/world/ChestLock.java
-@@ -6,6 +6,11 @@
- import net.minecraft.network.chat.IChatBaseComponent;
- import net.minecraft.world.item.ItemStack;
-
-+// CraftBukkit start
-+import org.bukkit.ChatColor;
-+import org.bukkit.craftbukkit.util.CraftChatMessage;
-+// CraftBukkit end
-+
- public record ChestLock(String key) {
-
- public static final ChestLock NO_LOCK = new ChestLock("");
-@@ -18,7 +23,19 @@
- } else {
- IChatBaseComponent ichatbasecomponent = (IChatBaseComponent) itemstack.get(DataComponents.CUSTOM_NAME);
-
-- return ichatbasecomponent != null && this.key.equals(ichatbasecomponent.getString());
-+ // CraftBukkit start - SPIGOT-6307: Check for color codes if the lock contains color codes
-+ if (this.key.isEmpty()) return true;
-+ if (ichatbasecomponent != null) {
-+ if (this.key.indexOf(ChatColor.COLOR_CHAR) == -1) {
-+ // The lock key contains no color codes, so let's ignore colors in the item display name (vanilla Minecraft behavior):
-+ return this.key.equals(ichatbasecomponent.getString());
-+ } else {
-+ // The lock key contains color codes, so let's take them into account:
-+ return this.key.equals(CraftChatMessage.fromComponent(ichatbasecomponent));
-+ }
-+ }
-+ return false;
-+ // CraftBukkit end
- }
- }
-
diff --git a/nms-patches/net/minecraft/world/damagesource/DamageSources.patch b/nms-patches/net/minecraft/world/damagesource/DamageSources.patch
index 86fc05e2..2397a45a 100644
--- a/nms-patches/net/minecraft/world/damagesource/DamageSources.patch
+++ b/nms-patches/net/minecraft/world/damagesource/DamageSources.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/world/damagesource/DamageSources.java
+++ b/net/minecraft/world/damagesource/DamageSources.java
-@@ -42,9 +42,15 @@
+@@ -43,9 +43,15 @@
private final DamageSource stalagmite;
private final DamageSource outsideBorder;
private final DamageSource genericKill;
@@ -9,15 +9,15 @@
+ private final DamageSource poison;
public DamageSources(IRegistryCustom iregistrycustom) {
- this.damageTypes = iregistrycustom.registryOrThrow(Registries.DAMAGE_TYPE);
+ this.damageTypes = iregistrycustom.lookupOrThrow(Registries.DAMAGE_TYPE);
+ this.melting = this.source(DamageTypes.ON_FIRE).melting();
+ this.poison = this.source(DamageTypes.MAGIC).poison();
+ // CraftBukkit end
this.inFire = this.source(DamageTypes.IN_FIRE);
this.campfire = this.source(DamageTypes.CAMPFIRE);
this.lightningBolt = this.source(DamageTypes.LIGHTNING_BOLT);
-@@ -83,6 +89,16 @@
- return new DamageSource(this.damageTypes.getHolderOrThrow(resourcekey), entity, entity1);
+@@ -85,6 +91,16 @@
+ return new DamageSource(this.damageTypes.getOrThrow(resourcekey), entity, entity1);
}
+ // CraftBukkit start
@@ -33,7 +33,7 @@
public DamageSource inFire() {
return this.inFire;
}
-@@ -248,7 +264,13 @@
+@@ -254,7 +270,13 @@
}
public DamageSource explosion(@Nullable Entity entity, @Nullable Entity entity1) {
@@ -48,17 +48,17 @@
}
public DamageSource sonicBoom(Entity entity) {
-@@ -256,7 +278,13 @@
+@@ -262,7 +284,13 @@
}
public DamageSource badRespawnPointExplosion(Vec3D vec3d) {
-- return new DamageSource(this.damageTypes.getHolderOrThrow(DamageTypes.BAD_RESPAWN_POINT), vec3d);
+- return new DamageSource(this.damageTypes.getOrThrow(DamageTypes.BAD_RESPAWN_POINT), vec3d);
+ // CraftBukkit start
+ return badRespawnPointExplosion(vec3d, null);
+ }
+
+ public DamageSource badRespawnPointExplosion(Vec3D vec3d, org.bukkit.block.BlockState blockState) {
-+ return new DamageSource(this.damageTypes.getHolderOrThrow(DamageTypes.BAD_RESPAWN_POINT), vec3d).directBlockState(blockState);
++ return new DamageSource(this.damageTypes.getOrThrow(DamageTypes.BAD_RESPAWN_POINT), vec3d).directBlockState(blockState);
+ // CraftBukkit end
}
diff --git a/nms-patches/net/minecraft/world/effect/HealOrHarmMobEffect.patch b/nms-patches/net/minecraft/world/effect/HealOrHarmMobEffect.patch
index 539a0856..f6f28110 100644
--- a/nms-patches/net/minecraft/world/effect/HealOrHarmMobEffect.patch
+++ b/nms-patches/net/minecraft/world/effect/HealOrHarmMobEffect.patch
@@ -1,15 +1,15 @@
--- a/net/minecraft/world/effect/HealOrHarmMobEffect.java
+++ b/net/minecraft/world/effect/HealOrHarmMobEffect.java
-@@ -16,7 +16,7 @@
+@@ -17,7 +17,7 @@
@Override
- public boolean applyEffectTick(EntityLiving entityliving, int i) {
+ public boolean applyEffectTick(WorldServer worldserver, EntityLiving entityliving, int i) {
if (this.isHarm == entityliving.isInvertedHealAndHarm()) {
- entityliving.heal((float) Math.max(4 << i, 0));
+ entityliving.heal((float) Math.max(4 << i, 0), org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.MAGIC); // CraftBukkit
} else {
- entityliving.hurt(entityliving.damageSources().magic(), (float) (6 << i));
+ entityliving.hurtServer(worldserver, entityliving.damageSources().magic(), (float) (6 << i));
}
-@@ -30,7 +30,7 @@
+@@ -31,7 +31,7 @@
if (this.isHarm == entityliving.isInvertedHealAndHarm()) {
j = (int) (d0 * (double) (4 << i) + 0.5D);
diff --git a/nms-patches/net/minecraft/world/effect/HungerMobEffect.patch b/nms-patches/net/minecraft/world/effect/HungerMobEffect.patch
index 3bfa8f79..f3a3c206 100644
--- a/nms-patches/net/minecraft/world/effect/HungerMobEffect.patch
+++ b/nms-patches/net/minecraft/world/effect/HungerMobEffect.patch
@@ -1,8 +1,8 @@
--- a/net/minecraft/world/effect/HungerMobEffect.java
+++ b/net/minecraft/world/effect/HungerMobEffect.java
-@@ -12,7 +12,7 @@
+@@ -13,7 +13,7 @@
@Override
- public boolean applyEffectTick(EntityLiving entityliving, int i) {
+ public boolean applyEffectTick(WorldServer worldserver, EntityLiving entityliving, int i) {
if (entityliving instanceof EntityHuman entityhuman) {
- entityhuman.causeFoodExhaustion(0.005F * (float) (i + 1));
+ entityhuman.causeFoodExhaustion(0.005F * (float) (i + 1), org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.HUNGER_EFFECT); // CraftBukkit - EntityExhaustionEvent
diff --git a/nms-patches/net/minecraft/world/effect/InfestedMobEffect.patch b/nms-patches/net/minecraft/world/effect/InfestedMobEffect.patch
index 60861865..ce145e52 100644
--- a/nms-patches/net/minecraft/world/effect/InfestedMobEffect.patch
+++ b/nms-patches/net/minecraft/world/effect/InfestedMobEffect.patch
@@ -1,12 +1,12 @@
--- a/net/minecraft/world/effect/InfestedMobEffect.java
+++ b/net/minecraft/world/effect/InfestedMobEffect.java
-@@ -47,7 +47,11 @@
+@@ -48,7 +48,11 @@
- entitysilverfish.moveTo(d0, d1, d2, world.getRandom().nextFloat() * 360.0F, 0.0F);
+ entitysilverfish.moveTo(d0, d1, d2, worldserver.getRandom().nextFloat() * 360.0F, 0.0F);
entitysilverfish.setDeltaMovement(new Vec3D(vector3f));
-- world.addFreshEntity(entitysilverfish);
+- worldserver.addFreshEntity(entitysilverfish);
+ // CraftBukkit start
-+ if (!world.addFreshEntity(entitysilverfish, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.POTION_EFFECT)) {
++ if (!worldserver.addFreshEntity(entitysilverfish, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.POTION_EFFECT)) {
+ return;
+ }
+ // CraftBukkit end
diff --git a/nms-patches/net/minecraft/world/effect/OozingMobEffect.patch b/nms-patches/net/minecraft/world/effect/OozingMobEffect.patch
index 02adb1c7..1619b976 100644
--- a/nms-patches/net/minecraft/world/effect/OozingMobEffect.patch
+++ b/nms-patches/net/minecraft/world/effect/OozingMobEffect.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/world/effect/OozingMobEffect.java
+++ b/net/minecraft/world/effect/OozingMobEffect.java
-@@ -51,7 +51,7 @@
+@@ -52,7 +52,7 @@
if (entityslime != null) {
entityslime.setSize(2, true);
entityslime.moveTo(d0, d1, d2, world.getRandom().nextFloat() * 360.0F, 0.0F);
diff --git a/nms-patches/net/minecraft/world/effect/PoisonMobEffect.patch b/nms-patches/net/minecraft/world/effect/PoisonMobEffect.patch
index e493de93..14617da0 100644
--- a/nms-patches/net/minecraft/world/effect/PoisonMobEffect.patch
+++ b/nms-patches/net/minecraft/world/effect/PoisonMobEffect.patch
@@ -1,11 +1,11 @@
--- a/net/minecraft/world/effect/PoisonMobEffect.java
+++ b/net/minecraft/world/effect/PoisonMobEffect.java
-@@ -11,7 +11,7 @@
+@@ -12,7 +12,7 @@
@Override
- public boolean applyEffectTick(EntityLiving entityliving, int i) {
+ public boolean applyEffectTick(WorldServer worldserver, EntityLiving entityliving, int 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.hurtServer(worldserver, entityliving.damageSources().magic(), 1.0F);
++ entityliving.hurtServer(worldserver, entityliving.damageSources().poison(), 1.0F); // CraftBukkit - DamageSource.MAGIC -> CraftEventFactory.POISON
}
return true;
diff --git a/nms-patches/net/minecraft/world/effect/RegenerationMobEffect.patch b/nms-patches/net/minecraft/world/effect/RegenerationMobEffect.patch
index 7ec7c8c0..4ca57f37 100644
--- a/nms-patches/net/minecraft/world/effect/RegenerationMobEffect.patch
+++ b/nms-patches/net/minecraft/world/effect/RegenerationMobEffect.patch
@@ -1,8 +1,8 @@
--- a/net/minecraft/world/effect/RegenerationMobEffect.java
+++ b/net/minecraft/world/effect/RegenerationMobEffect.java
-@@ -11,7 +11,7 @@
+@@ -12,7 +12,7 @@
@Override
- public boolean applyEffectTick(EntityLiving entityliving, int i) {
+ public boolean applyEffectTick(WorldServer worldserver, EntityLiving entityliving, int i) {
if (entityliving.getHealth() < entityliving.getMaxHealth()) {
- entityliving.heal(1.0F);
+ entityliving.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.MAGIC_REGEN); // CraftBukkit
diff --git a/nms-patches/net/minecraft/world/effect/SaturationMobEffect.patch b/nms-patches/net/minecraft/world/effect/SaturationMobEffect.patch
index 390177b4..ebf1e21e 100644
--- a/nms-patches/net/minecraft/world/effect/SaturationMobEffect.patch
+++ b/nms-patches/net/minecraft/world/effect/SaturationMobEffect.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/world/effect/SaturationMobEffect.java
+++ b/net/minecraft/world/effect/SaturationMobEffect.java
-@@ -3,6 +3,11 @@
+@@ -4,6 +4,11 @@
import net.minecraft.world.entity.EntityLiving;
import net.minecraft.world.entity.player.EntityHuman;
@@ -12,10 +12,10 @@
class SaturationMobEffect extends InstantMobEffect {
protected SaturationMobEffect(MobEffectInfo mobeffectinfo, int i) {
-@@ -12,7 +17,15 @@
+@@ -13,7 +18,15 @@
@Override
- public boolean applyEffectTick(EntityLiving entityliving, int i) {
- if (!entityliving.level().isClientSide && entityliving instanceof EntityHuman entityhuman) {
+ public boolean applyEffectTick(WorldServer worldserver, EntityLiving entityliving, int i) {
+ if (entityliving instanceof EntityHuman entityhuman) {
- entityhuman.getFoodData().eat(i + 1, 1.0F);
+ // CraftBukkit start
+ int oldFoodLevel = entityhuman.getFoodData().foodLevel;
diff --git a/nms-patches/net/minecraft/world/entity/ConversionType.patch b/nms-patches/net/minecraft/world/entity/ConversionType.patch
new file mode 100644
index 00000000..4aaf08e2
--- /dev/null
+++ b/nms-patches/net/minecraft/world/entity/ConversionType.patch
@@ -0,0 +1,41 @@
+--- a/net/minecraft/world/entity/ConversionType.java
++++ b/net/minecraft/world/entity/ConversionType.java
+@@ -12,6 +12,11 @@
+ import net.minecraft.world.item.ItemStack;
+ import net.minecraft.world.scores.Scoreboard;
+
++// CraftBukkit start
++import net.minecraft.core.BlockPosition;
++import org.bukkit.event.entity.EntityRemoveEvent;
++// CraftBukkit end
++
+ public enum ConversionType {
+
+ SINGLE(true) {
+@@ -31,7 +36,7 @@
+ while (iterator.hasNext()) {
+ entity1 = (Entity) iterator.next();
+ entity1.stopRiding();
+- entity1.remove(Entity.RemovalReason.DISCARDED);
++ entity1.remove(Entity.RemovalReason.DISCARDED, EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - add Bukkit remove cause
+ }
+
+ entity.startRiding(entityinsentient1);
+@@ -64,7 +69,7 @@
+ entityinsentient1.hurtTime = entityinsentient.hurtTime;
+ entityinsentient1.yBodyRot = entityinsentient.yBodyRot;
+ entityinsentient1.setOnGround(entityinsentient.onGround());
+- Optional optional = entityinsentient.getSleepingPos();
++ Optional optional = entityinsentient.getSleepingPos(); // CraftBukkit - decompile error
+
+ Objects.requireNonNull(entityinsentient1);
+ optional.ifPresent(entityinsentient1::setSleepingPos);
+@@ -156,7 +161,7 @@
+ entityinsentient1.setNoGravity(entityinsentient.isNoGravity());
+ entityinsentient1.setPortalCooldown(entityinsentient.getPortalCooldown());
+ entityinsentient1.setSilent(entityinsentient.isSilent());
+- Set set = entityinsentient.getTags();
++ Set set = entityinsentient.getTags(); // CraftBukkit - decompile error
+
+ Objects.requireNonNull(entityinsentient1);
+ set.forEach(entityinsentient1::addTag);
diff --git a/nms-patches/net/minecraft/world/entity/Entity.patch b/nms-patches/net/minecraft/world/entity/Entity.patch
index 86ac3ad8..cf4d28c9 100644
--- a/nms-patches/net/minecraft/world/entity/Entity.patch
+++ b/nms-patches/net/minecraft/world/entity/Entity.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
-@@ -131,8 +131,72 @@
+@@ -139,8 +139,67 @@
import net.minecraft.world.scores.ScoreboardTeamBase;
import org.slf4j.Logger;
@@ -42,7 +42,7 @@
+import org.bukkit.plugin.PluginManager;
+// CraftBukkit end
+
- public abstract class Entity implements SyncedDataHolder, INamableTileEntity, EntityAccess, ICommandListener, ScoreHolder {
+ public abstract class Entity implements SyncedDataHolder, INamableTileEntity, EntityAccess, ScoreHolder {
+ // CraftBukkit start
+ private static final int CURRENT_LEVEL = 2;
@@ -59,11 +59,6 @@
+ return bukkitEntity;
+ }
+
-+ @Override
-+ public CommandSender getBukkitSender(CommandListenerWrapper wrapper) {
-+ return getBukkitEntity();
-+ }
-+
+ // CraftBukkit - SPIGOT-6907: re-implement LivingEntity#setMaximumAir()
+ public int getDefaultMaxAirSupply() {
+ return TOTAL_AIR_SUPPLY;
@@ -73,10 +68,10 @@
private static final Logger LOGGER = LogUtils.getLogger();
public static final String ID_TAG = "id";
public static final String PASSENGERS_TAG = "Passengers";
-@@ -245,6 +309,30 @@
- public boolean hasVisualFire;
- @Nullable
- private IBlockData inBlockState;
+@@ -253,6 +312,30 @@
+ private final List movementThisTick;
+ private final Set blocksInside;
+ private final LongSet visitedBlocks;
+ // CraftBukkit start
+ public boolean forceDrops;
+ public boolean persist = true;
@@ -104,10 +99,10 @@
public Entity(EntityTypes> entitytypes, World world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
-@@ -351,12 +439,18 @@
+@@ -362,12 +445,18 @@
}
- public void kill() {
+ public void kill(WorldServer worldserver) {
- this.remove(Entity.RemovalReason.KILLED);
+ this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause
this.gameEvent(GameEvent.ENTITY_DIE);
@@ -125,7 +120,7 @@
}
protected abstract void defineSynchedData(DataWatcher.a datawatcher_a);
-@@ -365,6 +459,16 @@
+@@ -376,6 +465,16 @@
return this.entityData;
}
@@ -142,7 +137,7 @@
public boolean equals(Object object) {
return object instanceof Entity ? ((Entity) object).id == this.id : false;
}
-@@ -374,12 +478,24 @@
+@@ -385,7 +484,13 @@
}
public void remove(Entity.RemovalReason entity_removalreason) {
@@ -157,6 +152,8 @@
}
public void onClientRemoval() {}
+@@ -393,6 +498,12 @@
+ public void onRemoval(Entity.RemovalReason entity_removalreason) {}
public void setPose(EntityPose entitypose) {
+ // CraftBukkit start
@@ -168,7 +165,7 @@
this.entityData.set(Entity.DATA_POSE, entitypose);
}
-@@ -404,6 +520,33 @@
+@@ -417,6 +528,33 @@
}
protected void setRot(float f, float f1) {
@@ -202,7 +199,7 @@
this.setYRot(f % 360.0F);
this.setXRot(f1 % 360.0F);
}
-@@ -445,6 +588,15 @@
+@@ -458,6 +596,15 @@
this.baseTick();
}
@@ -216,18 +213,18 @@
+ // CraftBukkit end
+
public void baseTick() {
- this.level().getProfiler().push("entityBaseTick");
- this.inBlockState = null;
-@@ -459,7 +611,7 @@
- this.walkDistO = this.walkDist;
- this.xRotO = this.getXRot();
- this.yRotO = this.getYRot();
+ GameProfilerFiller gameprofilerfiller = Profiler.get();
+
+@@ -471,7 +618,7 @@
+ --this.boardingCooldown;
+ }
+
- this.handlePortal();
+ if (this instanceof EntityPlayer) this.handlePortal(); // CraftBukkit - // Moved up to postTick
if (this.canSpawnSprintParticle()) {
this.spawnSprintParticle();
}
-@@ -494,6 +646,10 @@
+@@ -510,6 +657,10 @@
if (this.isInLava()) {
this.lavaHurt();
this.fallDistance *= 0.5F;
@@ -238,21 +235,20 @@
}
this.checkBelowWorld();
-@@ -503,7 +659,7 @@
-
- this.firstTick = false;
- if (!this.level().isClientSide && this instanceof Leashable) {
-- Leashable.tickLeash((Entity) ((Leashable) this));
-+ Leashable.tickLeash((Entity & Leashable) this); // CraftBukkit - decompile error
+@@ -521,7 +672,7 @@
+ world = this.level();
+ if (world instanceof WorldServer worldserver) {
+ if (this instanceof Leashable) {
+- Leashable.tickLeash(worldserver, (Entity) ((Leashable) this));
++ Leashable.tickLeash(worldserver, (Entity & Leashable) this); // CraftBukkit - decompile error
+ }
}
- this.level().getProfiler().pop();
-@@ -545,15 +701,47 @@
+@@ -564,15 +715,32 @@
public void lavaHurt() {
if (!this.fireImmune()) {
- this.igniteForSeconds(15.0F);
-- 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
@@ -268,13 +264,22 @@
+ // This will be called every single tick the entity is in lava, so don't throw an event
+ this.igniteForSeconds(15.0F, false);
+ }
-+
-+ 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);
++ // CraftBukkit end
+ World world = this.level();
+
+ if (world instanceof WorldServer) {
+ WorldServer worldserver = (WorldServer) world;
+
+- if (this.hurtServer(worldserver, this.damageSources().lava(), 4.0F) && this.shouldPlayLavaHurtSound() && !this.isSilent()) {
++ // CraftBukkit start
++ if (this.hurtServer(worldserver, this.damageSources().lava().directBlock(level, lastLavaContact), 4.0F) && this.shouldPlayLavaHurtSound() && !this.isSilent()) {
+ worldserver.playSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), SoundEffects.GENERIC_BURN, this.getSoundSource(), 0.4F, 2.0F + this.random.nextFloat() * 0.4F);
+ }
++ // CraftBukkit end - we also don't throw an event unless the object in lava is living, to save on some event calls
}
-+ // CraftBukkit end - we also don't throw an event unless the object in lava is living, to save on some event calls
}
+@@ -583,6 +751,22 @@
}
public final void igniteForSeconds(float f) {
@@ -297,7 +302,7 @@
this.igniteForTicks(MathHelper.floor(f * 20.0F));
}
-@@ -577,7 +765,7 @@
+@@ -606,7 +790,7 @@
}
protected void onBelowWorld() {
@@ -306,8 +311,8 @@
}
public boolean isFree(double d0, double d1, double d2) {
-@@ -702,6 +890,28 @@
- block.updateEntityAfterFallOn(this.level(), this);
+@@ -739,6 +923,28 @@
+ }
}
+ // CraftBukkit start
@@ -332,10 +337,10 @@
+ }
+ // CraftBukkit end
+
- if (this.onGround()) {
- block.stepOn(this.level(), blockposition, iblockdata, this);
- }
-@@ -1073,6 +1283,20 @@
+ if (!this.level().isClientSide() || this.isControlledByLocalInstance()) {
+ Entity.MovementEmission entity_movementemission = this.getMovementEmission();
+
+@@ -1120,6 +1326,20 @@
return SoundEffects.GENERIC_SPLASH;
}
@@ -353,10 +358,10 @@
+ }
+ // CraftBukkit end
+
- 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);
-@@ -1512,6 +1736,7 @@
+ public void recordMovementThroughBlocks(Vec3D vec3d, Vec3D vec3d1) {
+ this.movementThisTick.add(new Entity.b(vec3d, vec3d1));
+ }
+@@ -1586,6 +1806,7 @@
this.yo = d1;
this.zo = d4;
this.setPos(d3, d1, d4);
@@ -364,7 +369,7 @@
}
public void moveTo(Vec3D vec3d) {
-@@ -1718,6 +1943,12 @@
+@@ -1838,6 +2059,12 @@
return false;
}
@@ -377,7 +382,7 @@
public void awardKillScore(Entity entity, int i, DamageSource damagesource) {
if (entity instanceof EntityPlayer) {
CriterionTriggers.ENTITY_KILLED_PLAYER.trigger((EntityPlayer) entity, this, damagesource);
-@@ -1746,16 +1977,22 @@
+@@ -1866,16 +2093,22 @@
}
public boolean saveAsPassenger(NBTTagCompound nbttagcompound) {
@@ -402,7 +407,7 @@
return true;
}
}
-@@ -1766,16 +2003,38 @@
+@@ -1886,16 +2119,38 @@
}
public NBTTagCompound saveWithoutId(NBTTagCompound nbttagcompound) {
@@ -445,7 +450,7 @@
nbttagcompound.put("Rotation", this.newFloatList(this.getYRot(), this.getXRot()));
nbttagcompound.putFloat("FallDistance", this.fallDistance);
nbttagcompound.putShort("Fire", (short) this.remainingFireTicks);
-@@ -1783,7 +2042,28 @@
+@@ -1903,7 +2158,28 @@
nbttagcompound.putBoolean("OnGround", this.onGround());
nbttagcompound.putBoolean("Invulnerable", this.invulnerable);
nbttagcompound.putInt("PortalCooldown", this.portalCooldown);
@@ -475,7 +480,7 @@
IChatBaseComponent ichatbasecomponent = this.getCustomName();
if (ichatbasecomponent != null) {
-@@ -1832,7 +2112,7 @@
+@@ -1952,7 +2228,7 @@
nbttagcompound.put("Tags", nbttaglist);
}
@@ -484,7 +489,7 @@
if (this.isVehicle()) {
nbttaglist = new NBTTagList();
iterator = this.getPassengers().iterator();
-@@ -1841,7 +2121,7 @@
+@@ -1961,7 +2237,7 @@
Entity entity = (Entity) iterator.next();
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
@@ -493,7 +498,7 @@
nbttaglist.add(nbttagcompound1);
}
}
-@@ -1851,6 +2131,11 @@
+@@ -1971,6 +2247,11 @@
}
}
@@ -505,7 +510,7 @@
return nbttagcompound;
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
-@@ -1934,6 +2219,45 @@
+@@ -2055,6 +2336,45 @@
} else {
throw new IllegalStateException("Entity has invalid position");
}
@@ -551,7 +556,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Entity being loaded");
-@@ -1955,6 +2279,12 @@
+@@ -2076,6 +2396,12 @@
return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null;
}
@@ -564,8 +569,8 @@
protected abstract void readAdditionalSaveData(NBTTagCompound nbttagcompound);
protected abstract void addAdditionalSaveData(NBTTagCompound nbttagcompound);
-@@ -2009,9 +2339,22 @@
- } else if (this.level().isClientSide) {
+@@ -2128,9 +2454,22 @@
+ if (itemstack.isEmpty()) {
return null;
} else {
+ // CraftBukkit start - Capture drops for death event
@@ -574,7 +579,7 @@
+ return null;
+ }
+ // CraftBukkit end
- EntityItem entityitem = new EntityItem(this.level(), this.getX(), this.getY() + (double) f, this.getZ(), itemstack);
+ EntityItem entityitem = new EntityItem(worldserver, this.getX(), this.getY() + (double) f, this.getZ(), itemstack);
entityitem.setDefaultPickUpDelay();
+ // CraftBukkit start
@@ -584,10 +589,10 @@
+ return null;
+ }
+ // CraftBukkit end
- this.level().addFreshEntity(entityitem);
+ worldserver.addFreshEntity(entityitem);
return entityitem;
}
-@@ -2040,6 +2383,12 @@
+@@ -2159,6 +2498,12 @@
if (this.isAlive() && this instanceof Leashable leashable) {
if (leashable.getLeashHolder() == entityhuman) {
if (!this.level().isClientSide()) {
@@ -600,7 +605,7 @@
leashable.dropLeash(true, !entityhuman.hasInfiniteMaterials());
this.gameEvent(GameEvent.ENTITY_INTERACT, entityhuman);
}
-@@ -2051,6 +2400,13 @@
+@@ -2170,6 +2515,13 @@
if (itemstack.is(Items.LEAD) && leashable.canHaveALeashAttachedToIt()) {
if (!this.level().isClientSide()) {
@@ -614,7 +619,7 @@
leashable.setLeashedTo(entityhuman, true);
}
-@@ -2134,6 +2490,27 @@
+@@ -2255,6 +2607,27 @@
if (!flag && (!this.canRide(entity) || !entity.canAddPassenger(this))) {
return false;
} else {
@@ -642,7 +647,7 @@
if (this.isPassenger()) {
this.stopRiding();
}
-@@ -2167,7 +2544,7 @@
+@@ -2288,7 +2661,7 @@
Entity entity = this.vehicle;
this.vehicle = null;
@@ -651,7 +656,7 @@
}
}
-@@ -2198,10 +2575,38 @@
+@@ -2319,10 +2692,38 @@
}
}
@@ -691,7 +696,7 @@
if (this.passengers.size() == 1 && this.passengers.get(0) == entity) {
this.passengers = ImmutableList.of();
} else {
-@@ -2213,6 +2618,7 @@
+@@ -2334,6 +2735,7 @@
entity.boardingCooldown = 60;
this.gameEvent(GameEvent.ENTITY_DISMOUNT, entity);
}
@@ -699,16 +704,16 @@
}
protected boolean canAddPassenger(Entity entity) {
-@@ -2307,7 +2713,7 @@
- if (dimensiontransition != null) {
- WorldServer worldserver1 = dimensiontransition.newLevel();
+@@ -2434,7 +2836,7 @@
+ if (teleporttransition != null) {
+ WorldServer worldserver1 = teleporttransition.newLevel();
-- if (worldserver.getServer().isLevelEnabled(worldserver1) && (worldserver1.dimension() == worldserver.dimension() || this.canChangeDimensions(worldserver, worldserver1))) {
-+ if (this instanceof EntityPlayer || (worldserver1 != null && (worldserver1.dimension() == worldserver.dimension() || this.canChangeDimensions(worldserver, worldserver1)))) { // CraftBukkit - always call event for players
- this.changeDimension(dimensiontransition);
+- if (worldserver.getServer().isLevelEnabled(worldserver1) && (worldserver1.dimension() == worldserver.dimension() || this.canTeleport(worldserver, worldserver1))) {
++ if (this instanceof EntityPlayer || (worldserver1 != null && (worldserver1.dimension() == worldserver.dimension() || this.canTeleport(worldserver, worldserver1)))) { // CraftBukkit - always call event for players
+ this.teleport(teleporttransition);
}
}
-@@ -2414,6 +2820,13 @@
+@@ -2541,6 +2943,13 @@
}
public void setSwimming(boolean flag) {
@@ -722,7 +727,7 @@
this.setSharedFlag(4, flag);
}
-@@ -2463,8 +2876,12 @@
+@@ -2594,8 +3003,12 @@
return this.getTeam() != null ? this.getTeam().isAlliedTo(scoreboardteambase) : false;
}
@@ -736,7 +741,7 @@
}
public boolean getSharedFlag(int i) {
-@@ -2483,7 +2900,7 @@
+@@ -2614,7 +3027,7 @@
}
public int getMaxAirSupply() {
@@ -745,7 +750,7 @@
}
public int getAirSupply() {
-@@ -2491,7 +2908,18 @@
+@@ -2622,7 +3035,18 @@
}
public void setAirSupply(int i) {
@@ -765,7 +770,7 @@
}
public int getTicksFrozen() {
-@@ -2518,11 +2946,40 @@
+@@ -2649,11 +3073,40 @@
public void thunderHit(WorldServer worldserver, EntityLightning entitylightning) {
this.setRemainingFireTicks(this.remainingFireTicks + 1);
@@ -786,7 +791,7 @@
+ // CraftBukkit end
}
-- this.hurt(this.damageSources().lightningBolt(), 5.0F);
+- this.hurtServer(worldserver, this.damageSources().lightningBolt(), 5.0F);
+ // CraftBukkit start
+ if (thisBukkitEntity instanceof Hanging) {
+ HangingBreakByEntityEvent hangingEvent = new HangingBreakByEntityEvent((Hanging) thisBukkitEntity, stormBukkitEntity);
@@ -801,47 +806,47 @@
+ return;
+ }
+
-+ if (!this.hurt(this.damageSources().lightningBolt().customEntityDamager(entitylightning), 5.0F)) {
++ if (!this.hurtServer(worldserver, this.damageSources().lightningBolt().customEntityDamager(entitylightning), 5.0F)) {
+ return;
+ }
+ // CraftBukkit end
}
public void onAboveBubbleCol(boolean flag) {
-@@ -2691,6 +3148,15 @@
+@@ -2822,6 +3275,18 @@
if (world instanceof WorldServer worldserver) {
if (!this.isRemoved()) {
+ // CraftBukkit start
-+ Location to = new Location(dimensiontransition.newLevel().getWorld(), dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), dimensiontransition.xRot());
++ PositionMoveRotation absolutePosition = PositionMoveRotation.calculateAbsolute(PositionMoveRotation.of(this), PositionMoveRotation.of(teleporttransition), teleporttransition.relatives());
++ Location to = CraftLocation.toBukkit(absolutePosition.position(), teleporttransition.newLevel().getWorld(), absolutePosition.yRot(), absolutePosition.xRot());
+ EntityTeleportEvent teleEvent = CraftEventFactory.callEntityTeleportEvent(this, to);
+ if (teleEvent.isCancelled()) {
+ return null;
+ }
-+ to = teleEvent.getTo();
-+ dimensiontransition = new DimensionTransition(((CraftWorld) to.getWorld()).getHandle(), CraftLocation.toVec3D(to), dimensiontransition.speed(), to.getYaw(), to.getPitch(), dimensiontransition.missingRespawnBlock(), dimensiontransition.postDimensionTransition(), dimensiontransition.cause());
++ if (!to.equals(teleEvent.getTo())) {
++ to = teleEvent.getTo();
++ teleporttransition = new TeleportTransition(((CraftWorld) to.getWorld()).getHandle(), CraftLocation.toVec3D(to), Vec3D.ZERO, to.getYaw(), to.getPitch(), teleporttransition.missingRespawnBlock(), teleporttransition.asPassenger(), Set.of(), teleporttransition.postTeleportTransition(), teleporttransition.cause());
++ }
+ // CraftBukkit end
- WorldServer worldserver1 = dimensiontransition.newLevel();
- List list = this.getPassengers();
-
-@@ -2716,11 +3182,15 @@
- if (this != entity2) {
- entity2.restoreFrom(this);
- this.removeAfterChangingDimensions();
-+ // CraftBukkit start - Forward the CraftEntity to the new entity
-+ this.getBukkitEntity().setHandle(entity2);
-+ entity2.bukkitEntity = this.getBukkitEntity();
-+ // CraftBukkit end
- }
+ WorldServer worldserver1 = teleporttransition.newLevel();
+ boolean flag = worldserver1.dimension() != worldserver.dimension();
- entity2.moveTo(dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), entity2.getXRot());
- entity2.setDeltaMovement(dimensiontransition.speed());
-- if (this != entity2) {
-+ if (this != entity2 && this.inWorld) { // CraftBukkit - Don't spawn the new entity if the current entity isn't spawned
- worldserver1.addDuringTeleport(entity2);
- }
+@@ -2890,8 +3355,12 @@
+ } else {
+ entity.restoreFrom(this);
+ this.removeAfterChangingDimensions();
++ // CraftBukkit start - Forward the CraftEntity to the new entity
++ this.getBukkitEntity().setHandle(entity);
++ entity.bukkitEntity = this.getBukkitEntity();
++ // CraftBukkit end
+ entity.teleportSetPosition(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives());
+- worldserver.addDuringTeleport(entity);
++ if (this.inWorld) worldserver.addDuringTeleport(entity); // CraftBukkit - Don't spawn the new entity if the current entity isn't spawned
+ Iterator iterator1 = list1.iterator();
-@@ -2754,8 +3224,9 @@
+ while (iterator1.hasNext()) {
+@@ -2965,8 +3434,9 @@
}
protected void removeAfterChangingDimensions() {
@@ -852,7 +857,7 @@
leashable.dropLeash(true, false);
}
-@@ -2765,6 +3236,20 @@
+@@ -2976,6 +3446,20 @@
return BlockPortalShape.getRelativePosition(blockutil_rectangle, enumdirection_enumaxis, this.position(), this.getDimensions(this.getPose()));
}
@@ -873,35 +878,25 @@
public boolean canUsePortal(boolean flag) {
return (flag || !this.isPassenger()) && this.isAlive();
}
-@@ -2877,6 +3362,12 @@
+@@ -3104,9 +3588,15 @@
return (Boolean) this.entityData.get(Entity.DATA_CUSTOM_NAME_VISIBLE);
}
+- public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1, boolean flag) {
+ // CraftBukkit start
-+ public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
-+ return this.teleportTo(worldserver, d0, d1, d2, set, f, f1);
++ public final boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1, boolean flag) {
++ return teleportTo(worldserver, d0, d1, d2, set, f, f1, flag, PlayerTeleportEvent.TeleportCause.UNKNOWN);
+ }
-+ // CraftBukkit end
+
- public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1) {
++ public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1, boolean flag, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
float f2 = MathHelper.clamp(f1, -90.0F, 90.0F);
+- Entity entity = this.teleport(new TeleportTransition(worldserver, new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f2, set, TeleportTransition.DO_NOTHING));
++ Entity entity = this.teleport(new TeleportTransition(worldserver, new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f2, set, TeleportTransition.DO_NOTHING, cause));
++ // CraftBukkit end
-@@ -2895,8 +3386,12 @@
- entity.restoreFrom(this);
- entity.moveTo(d0, d1, d2, f, f2);
- entity.setYHeadRot(f);
-- this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION);
-- worldserver.addDuringTeleport(entity);
-+ this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION, null); // CraftBukkit - add Bukkit remove cause
-+ // CraftBukkit start - Don't spawn the new entity if the current entity isn't spawned
-+ if (inWorld) {
-+ worldserver.addDuringTeleport(entity);
-+ }
-+ // CraftBukkit end
- }
-
- return true;
-@@ -3023,7 +3518,26 @@
+ return entity != null;
+ }
+@@ -3228,7 +3718,26 @@
}
public final void setBoundingBox(AxisAlignedBB axisalignedbb) {
@@ -929,7 +924,7 @@
}
public final float getEyeHeight(EntityPose entitypose) {
-@@ -3332,6 +3846,11 @@
+@@ -3525,6 +4034,11 @@
vec3d = vec3d.add(vec3d1);
++k1;
}
@@ -941,7 +936,7 @@
}
}
}
-@@ -3601,6 +4120,14 @@
+@@ -3792,6 +4306,14 @@
@Override
public final void setRemoved(Entity.RemovalReason entity_removalreason) {
diff --git a/nms-patches/net/minecraft/world/entity/EntityAgeable.patch b/nms-patches/net/minecraft/world/entity/EntityAgeable.patch
index b5e1154c..77d10c6a 100644
--- a/nms-patches/net/minecraft/world/entity/EntityAgeable.patch
+++ b/nms-patches/net/minecraft/world/entity/EntityAgeable.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/EntityAgeable.java
+++ b/net/minecraft/world/entity/EntityAgeable.java
-@@ -20,6 +20,7 @@
+@@ -21,6 +21,7 @@
protected int age;
protected int forcedAge;
protected int forcedAgeTimer;
@@ -8,7 +8,7 @@
protected EntityAgeable(EntityTypes extends EntityAgeable> entitytypes, World world) {
super(entitytypes, world);
-@@ -103,6 +104,7 @@
+@@ -104,6 +105,7 @@
super.addAdditionalSaveData(nbttagcompound);
nbttagcompound.putInt("Age", this.getAge());
nbttagcompound.putInt("ForcedAge", this.forcedAge);
@@ -16,7 +16,7 @@
}
@Override
-@@ -110,6 +112,7 @@
+@@ -111,6 +113,7 @@
super.readAdditionalSaveData(nbttagcompound);
this.setAge(nbttagcompound.getInt("Age"));
this.forcedAge = nbttagcompound.getInt("ForcedAge");
@@ -24,7 +24,7 @@
}
@Override
-@@ -124,7 +127,7 @@
+@@ -125,7 +128,7 @@
@Override
public void aiStep() {
super.aiStep();
diff --git a/nms-patches/net/minecraft/world/entity/EntityAreaEffectCloud.patch b/nms-patches/net/minecraft/world/entity/EntityAreaEffectCloud.patch
index ee7c7306..3f2bb941 100644
--- a/nms-patches/net/minecraft/world/entity/EntityAreaEffectCloud.patch
+++ b/nms-patches/net/minecraft/world/entity/EntityAreaEffectCloud.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/EntityAreaEffectCloud.java
+++ b/net/minecraft/world/entity/EntityAreaEffectCloud.java
-@@ -32,6 +32,12 @@
+@@ -33,6 +33,12 @@
import net.minecraft.world.level.material.EnumPistonReaction;
import org.slf4j.Logger;
@@ -13,81 +13,81 @@
public class EntityAreaEffectCloud extends Entity implements TraceableEntity {
private static final Logger LOGGER = LogUtils.getLogger();
-@@ -188,7 +194,7 @@
- }
- } else {
- if (this.tickCount >= this.waitTime + this.duration) {
-- this.discard();
-+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
- return;
- }
+@@ -200,7 +206,7 @@
-@@ -205,7 +211,7 @@
- if (this.radiusPerTick != 0.0F) {
- f += this.radiusPerTick;
- if (f < 0.5F) {
-- this.discard();
-+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
- return;
- }
+ private void serverTick(WorldServer worldserver) {
+ if (this.tickCount >= this.waitTime + this.duration) {
+- this.discard();
++ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
+ } else {
+ boolean flag = this.isWaiting();
+ boolean flag1 = this.tickCount < this.waitTime;
+@@ -215,7 +221,7 @@
+ if (this.radiusPerTick != 0.0F) {
+ f += this.radiusPerTick;
+ if (f < 0.5F) {
+- this.discard();
++ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
+ return;
+ }
-@@ -239,11 +245,12 @@
- if (!list1.isEmpty()) {
- Iterator iterator1 = list1.iterator();
+@@ -249,11 +255,12 @@
+ if (!list1.isEmpty()) {
+ Iterator iterator1 = list1.iterator();
-+ List entities = new java.util.ArrayList(); // CraftBukkit
- while (iterator1.hasNext()) {
- EntityLiving entityliving = (EntityLiving) iterator1.next();
++ List entities = new java.util.ArrayList(); // CraftBukkit
+ while (iterator1.hasNext()) {
+ EntityLiving entityliving = (EntityLiving) iterator1.next();
- if (!this.victims.containsKey(entityliving) && entityliving.isAffectedByPotions()) {
-- Stream stream = list.stream();
-+ Stream stream = list.stream(); // CraftBukkit - decompile error
+ if (!this.victims.containsKey(entityliving) && entityliving.isAffectedByPotions()) {
+- Stream stream = list.stream();
++ Stream stream = list.stream(); // CraftBukkit - decompile error
- Objects.requireNonNull(entityliving);
- if (!stream.noneMatch(entityliving::canBeAffected)) {
-@@ -252,6 +259,19 @@
- double d5 = d3 * d3 + d4 * d4;
+ Objects.requireNonNull(entityliving);
+ if (!stream.noneMatch(entityliving::canBeAffected)) {
+@@ -262,6 +269,19 @@
+ double d2 = d0 * d0 + d1 * d1;
- if (d5 <= (double) (f * f)) {
-+ // CraftBukkit start
-+ entities.add((LivingEntity) entityliving.getBukkitEntity());
+ if (d2 <= (double) (f * f)) {
++ // CraftBukkit start
++ entities.add((LivingEntity) entityliving.getBukkitEntity());
++ }
+ }
+ }
+ }
-+ }
-+ {
-+ org.bukkit.event.entity.AreaEffectCloudApplyEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callAreaEffectCloudApplyEvent(this, entities);
-+ if (!event.isCancelled()) {
-+ for (LivingEntity entity : event.getAffectedEntities()) {
-+ if (entity instanceof CraftLivingEntity) {
-+ EntityLiving entityliving = ((CraftLivingEntity) entity).getHandle();
-+ // CraftBukkit end
- this.victims.put(entityliving, this.tickCount + this.reapplicationDelay);
- Iterator iterator2 = list.iterator();
++ {
++ org.bukkit.event.entity.AreaEffectCloudApplyEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callAreaEffectCloudApplyEvent(this, entities);
++ if (!event.isCancelled()) {
++ for (LivingEntity entity : event.getAffectedEntities()) {
++ if (entity instanceof CraftLivingEntity) {
++ EntityLiving entityliving = ((CraftLivingEntity) entity).getHandle();
++ // CraftBukkit end
+ this.victims.put(entityliving, this.tickCount + this.reapplicationDelay);
+ Iterator iterator2 = list.iterator();
-@@ -261,14 +281,14 @@
- if (((MobEffectList) mobeffect1.getEffect().value()).isInstantenous()) {
- ((MobEffectList) mobeffect1.getEffect().value()).applyInstantenousEffect(this, this.getOwner(), entityliving, mobeffect1.getAmplifier(), 0.5D);
- } else {
-- entityliving.addEffect(new MobEffect(mobeffect1), this);
-+ entityliving.addEffect(new MobEffect(mobeffect1), this, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.AREA_EFFECT_CLOUD); // CraftBukkit
+@@ -271,14 +291,14 @@
+ if (((MobEffectList) mobeffect1.getEffect().value()).isInstantenous()) {
+ ((MobEffectList) mobeffect1.getEffect().value()).applyInstantenousEffect(worldserver, this, this.getOwner(), entityliving, mobeffect1.getAmplifier(), 0.5D);
+ } else {
+- entityliving.addEffect(new MobEffect(mobeffect1), this);
++ entityliving.addEffect(new MobEffect(mobeffect1), this, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.AREA_EFFECT_CLOUD); // CraftBukkit
+ }
}
- }
- if (this.radiusOnUse != 0.0F) {
- f += this.radiusOnUse;
- if (f < 0.5F) {
-- this.discard();
-+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
- return;
- }
+ if (this.radiusOnUse != 0.0F) {
+ f += this.radiusOnUse;
+ if (f < 0.5F) {
+- this.discard();
++ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
+ return;
+ }
-@@ -278,7 +298,7 @@
- if (this.durationOnUse != 0) {
- this.duration += this.durationOnUse;
- if (this.duration <= 0) {
-- this.discard();
-+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
- return;
+@@ -288,7 +308,7 @@
+ if (this.durationOnUse != 0) {
+ this.duration += this.durationOnUse;
+ if (this.duration <= 0) {
+- this.discard();
++ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
+ return;
+ }
}
- }
diff --git a/nms-patches/net/minecraft/world/entity/EntityExperienceOrb.patch b/nms-patches/net/minecraft/world/entity/EntityExperienceOrb.patch
index 4ada992e..48c47f28 100644
--- a/nms-patches/net/minecraft/world/entity/EntityExperienceOrb.patch
+++ b/nms-patches/net/minecraft/world/entity/EntityExperienceOrb.patch
@@ -47,7 +47,7 @@
Vec3D vec3d = new Vec3D(this.followingPlayer.getX() - this.getX(), this.followingPlayer.getY() + (double) this.followingPlayer.getEyeHeight() / 2.0D - this.getY(), this.followingPlayer.getZ() - this.getZ());
double d0 = vec3d.lengthSqr();
-@@ -118,7 +142,7 @@
+@@ -119,7 +143,7 @@
++this.age;
if (this.age >= 6000) {
@@ -56,7 +56,7 @@
}
}
-@@ -187,7 +211,7 @@
+@@ -188,7 +212,7 @@
private void merge(EntityExperienceOrb entityexperienceorb) {
this.count += entityexperienceorb.count;
this.age = Math.min(this.age, entityexperienceorb.age);
@@ -65,7 +65,7 @@
}
private void setUnderwaterMovement() {
-@@ -209,7 +233,7 @@
+@@ -213,7 +237,7 @@
this.markHurt();
this.health = (int) ((float) this.health - f);
if (this.health <= 0) {
@@ -74,7 +74,7 @@
}
return true;
-@@ -236,17 +260,17 @@
+@@ -240,17 +264,17 @@
public void playerTouch(EntityHuman entityhuman) {
if (entityhuman instanceof EntityPlayer entityplayer) {
if (entityhuman.takeXpDelay == 0) {
@@ -95,7 +95,7 @@
}
}
-@@ -260,12 +284,20 @@
+@@ -264,12 +288,20 @@
ItemStack itemstack = ((EnchantedItemInUse) optional.get()).itemStack();
int j = EnchantmentManager.modifyDurabilityToRepairFromXp(entityplayer.serverLevel(), itemstack, i);
int k = Math.min(j, itemstack.getDamageValue());
@@ -116,7 +116,7 @@
return this.repairPlayerItems(entityplayer, l);
}
}
-@@ -285,6 +317,24 @@
+@@ -289,6 +321,24 @@
}
public static int getExperienceValue(int i) {
diff --git a/nms-patches/net/minecraft/world/entity/EntityInsentient.patch b/nms-patches/net/minecraft/world/entity/EntityInsentient.patch
index 54e16c0d..a27e3229 100644
--- a/nms-patches/net/minecraft/world/entity/EntityInsentient.patch
+++ b/nms-patches/net/minecraft/world/entity/EntityInsentient.patch
@@ -1,15 +1,13 @@
--- a/net/minecraft/world/entity/EntityInsentient.java
+++ b/net/minecraft/world/entity/EntityInsentient.java
-@@ -87,6 +87,20 @@
+@@ -89,6 +89,18 @@
import net.minecraft.world.level.storage.loot.parameters.LootContextParameters;
import net.minecraft.world.phys.AxisAlignedBB;
+// CraftBukkit start
-+import net.minecraft.server.level.EntityPlayer;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.event.entity.CreatureSpawnEvent;
-+import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
+import org.bukkit.event.entity.EntityTargetEvent;
@@ -21,7 +19,7 @@
public abstract class EntityInsentient extends EntityLiving implements EquipmentUser, Leashable, Targeting {
private static final DataWatcherObject DATA_MOB_FLAGS_ID = DataWatcher.defineId(EntityInsentient.class, DataWatcherRegistry.BYTE);
-@@ -134,6 +148,8 @@
+@@ -136,6 +148,8 @@
private BlockPosition restrictCenter;
private float restrictRadius;
@@ -30,7 +28,7 @@
protected EntityInsentient(EntityTypes extends EntityInsentient> entitytypes, World world) {
super(entitytypes, world);
this.handItems = NonNullList.withSize(2, ItemStack.EMPTY);
-@@ -161,6 +177,12 @@
+@@ -164,6 +178,12 @@
}
@@ -43,7 +41,7 @@
protected void registerGoals() {}
public static AttributeProvider.Builder createMobAttributes() {
-@@ -265,11 +287,42 @@
+@@ -268,11 +288,42 @@
@Nullable
protected final EntityLiving getTargetFromBrain() {
@@ -87,7 +85,7 @@
}
@Override
-@@ -405,6 +458,12 @@
+@@ -403,6 +454,12 @@
return null;
}
@@ -100,7 +98,7 @@
@Override
public void addAdditionalSaveData(NBTTagCompound nbttagcompound) {
super.addAdditionalSaveData(nbttagcompound);
-@@ -478,16 +537,26 @@
+@@ -476,16 +533,26 @@
nbttagcompound.putBoolean("NoAI", this.isNoAi());
}
@@ -112,7 +110,7 @@
super.readAdditionalSaveData(nbttagcompound);
+
+ // CraftBukkit start - If looting or persistence is false only use it if it was set after we started using it
- if (nbttagcompound.contains("CanPickUpLoot", 1)) {
+ if (nbttagcompound.contains("CanPickUpLoot", 99)) {
- this.setCanPickUpLoot(nbttagcompound.getBoolean("CanPickUpLoot"));
+ boolean data = nbttagcompound.getBoolean("CanPickUpLoot");
+ if (isLevelAtLeast(nbttagcompound, 1) || data) {
@@ -129,7 +127,7 @@
NBTTagList nbttaglist;
NBTTagCompound nbttagcompound1;
int i;
-@@ -541,6 +610,11 @@
+@@ -539,6 +606,11 @@
}
this.setNoAi(nbttagcompound.getBoolean("NoAI"));
@@ -141,12 +139,12 @@
}
@Override
-@@ -615,20 +689,26 @@
+@@ -615,20 +687,26 @@
- protected void pickUpItem(EntityItem entityitem) {
+ protected void pickUpItem(WorldServer worldserver, EntityItem entityitem) {
ItemStack itemstack = entityitem.getItem();
-- ItemStack itemstack1 = this.equipItemIfPossible(itemstack.copy());
-+ ItemStack itemstack1 = this.equipItemIfPossible(itemstack.copy(), entityitem); // CraftBukkit - add item
+- ItemStack itemstack1 = this.equipItemIfPossible(worldserver, itemstack.copy());
++ ItemStack itemstack1 = this.equipItemIfPossible(worldserver, itemstack.copy(), entityitem); // CraftBukkit - add item
if (!itemstack1.isEmpty()) {
this.onItemPickup(entityitem);
@@ -160,17 +158,17 @@
}
- public ItemStack equipItemIfPossible(ItemStack itemstack) {
+ public ItemStack equipItemIfPossible(WorldServer worldserver, ItemStack itemstack) {
+ // CraftBukkit start - add item
-+ return this.equipItemIfPossible(itemstack, null);
++ return this.equipItemIfPossible(worldserver, itemstack, null);
+ }
+
-+ public ItemStack equipItemIfPossible(ItemStack itemstack, EntityItem entityitem) {
++ public ItemStack equipItemIfPossible(WorldServer worldserver, ItemStack itemstack, EntityItem entityitem) {
+ // CraftBukkit end
EnumItemSlot enumitemslot = this.getEquipmentSlotForItem(itemstack);
ItemStack itemstack1 = this.getItemBySlot(enumitemslot);
- boolean flag = this.canReplaceCurrentItem(itemstack, itemstack1);
-@@ -639,11 +719,19 @@
+ boolean flag = this.canReplaceCurrentItem(itemstack, itemstack1, enumitemslot);
+@@ -639,11 +717,19 @@
flag = itemstack1.isEmpty();
}
@@ -186,12 +184,12 @@
if (!itemstack1.isEmpty() && (double) Math.max(this.random.nextFloat() - 0.1F, 0.0F) < d0) {
+ this.forceDrops = true; // CraftBukkit
- this.spawnAtLocation(itemstack1);
+ this.spawnAtLocation(worldserver, itemstack1);
+ this.forceDrops = false; // CraftBukkit
}
ItemStack itemstack2 = enumitemslot.limit(itemstack);
-@@ -772,7 +860,7 @@
+@@ -770,7 +856,7 @@
@Override
public void checkDespawn() {
if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL && this.shouldDespawnInPeaceful()) {
@@ -200,7 +198,7 @@
} else if (!this.isPersistenceRequired() && !this.requiresCustomPersistence()) {
EntityHuman entityhuman = this.level().getNearestPlayer(this, -1.0D);
-@@ -782,14 +870,14 @@
+@@ -780,14 +866,14 @@
int j = i * i;
if (d0 > (double) j && this.removeWhenFarAway(d0)) {
@@ -217,15 +215,15 @@
} else if (d0 < (double) l) {
this.noActionTime = 0;
}
-@@ -803,6 +891,7 @@
+@@ -801,6 +887,7 @@
@Override
protected final void serverAiStep() {
++this.noActionTime;
+ if (!this.aware) return; // CraftBukkit
- GameProfilerFiller gameprofilerfiller = this.level().getProfiler();
+ GameProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("sensing");
-@@ -1354,7 +1443,7 @@
+@@ -1340,7 +1427,7 @@
if (itemstack.getItem() instanceof ItemMonsterEgg) {
if (this.level() instanceof WorldServer) {
ItemMonsterEgg itemmonsteregg = (ItemMonsterEgg) itemstack.getItem();
@@ -234,51 +232,71 @@
optional.ifPresent((entityinsentient) -> {
this.onOffspringSpawnedFromEgg(entityhuman, entityinsentient);
-@@ -1403,12 +1492,19 @@
+@@ -1391,12 +1478,19 @@
return this.restrictRadius != -1.0F;
}
+ // CraftBukkit start
@Nullable
- public T convertTo(EntityTypes entitytypes, boolean flag) {
-+ return this.convertTo(entitytypes, flag, EntityTransformEvent.TransformReason.UNKNOWN, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ public T convertTo(EntityTypes entitytypes, ConversionParams conversionparams, EntitySpawnReason entityspawnreason, ConversionParams.a conversionparams_a) {
++ return this.convertTo(entitytypes, conversionparams, entityspawnreason, conversionparams_a, EntityTransformEvent.TransformReason.UNKNOWN, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ @Nullable
-+ public T convertTo(EntityTypes entitytypes, boolean flag, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
++ public T convertTo(EntityTypes entitytypes, ConversionParams conversionparams, EntitySpawnReason entityspawnreason, ConversionParams.a conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
+ // CraftBukkit end
if (this.isRemoved()) {
return null;
} else {
-- T t0 = (EntityInsentient) entitytypes.create(this.level());
-+ T t0 = entitytypes.create(this.level()); // CraftBukkit - decompile error
+- T t0 = (EntityInsentient) entitytypes.create(this.level(), entityspawnreason);
++ T t0 = entitytypes.create(this.level(), EntitySpawnReason.CONVERSION); // CraftBukkit - decompile error
if (t0 == null) {
return null;
-@@ -1442,7 +1538,12 @@
- }
- }
+@@ -1405,14 +1499,24 @@
+ conversionparams_a.finalizeConversion(t0);
+ World world = this.level();
-- this.level().addFreshEntity(t0);
+ // CraftBukkit start
++ if (transformReason == null) {
++ // Special handling for slime split and pig lightning
++ return t0;
++ }
++
+ if (CraftEventFactory.callEntityTransformEvent(this, t0, transformReason).isCancelled()) {
+ return null;
+ }
-+ this.level().addFreshEntity(t0, spawnReason);
+ // CraftBukkit end
- if (this.isPassenger()) {
- Entity entity = this.getVehicle();
+ if (world instanceof WorldServer) {
+ WorldServer worldserver = (WorldServer) world;
+
+- worldserver.addFreshEntity(t0);
++ worldserver.addFreshEntity(t0, spawnReason); // CraftBukkit
+ }
-@@ -1450,7 +1551,7 @@
- t0.startRiding(entity, true);
+ if (conversionparams.type().shouldDiscardAfterConversion()) {
+- this.discard();
++ this.discard(EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - add Bukkit remove cause
}
-- this.discard();
-+ this.discard(EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - add Bukkit remove cause
return t0;
- }
- }
-@@ -1492,6 +1593,7 @@
+@@ -1422,7 +1526,14 @@
+
+ @Nullable
+ public T convertTo(EntityTypes entitytypes, ConversionParams conversionparams, ConversionParams.a conversionparams_a) {
+- return this.convertTo(entitytypes, conversionparams, EntitySpawnReason.CONVERSION, conversionparams_a);
++ // CraftBukkit start
++ return this.convertTo(entitytypes, conversionparams, conversionparams_a, EntityTransformEvent.TransformReason.UNKNOWN, CreatureSpawnEvent.SpawnReason.DEFAULT);
++ }
++
++ @Nullable
++ public T convertTo(EntityTypes entitytypes, ConversionParams conversionparams, ConversionParams.a conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
++ return this.convertTo(entitytypes, conversionparams, EntitySpawnReason.CONVERSION, conversionparams_a, transformReason, spawnReason);
++ // CraftBukkit end
+ }
+
+ @Nullable
+@@ -1461,6 +1572,7 @@
boolean flag1 = super.startRiding(entity, flag);
if (flag1 && this.isLeashed()) {
@@ -286,10 +304,10 @@
this.dropLeash(true, true);
}
-@@ -1578,7 +1680,7 @@
- if (f1 > 0.0F && entity instanceof EntityLiving) {
- EntityLiving entityliving = (EntityLiving) entity;
+@@ -1545,7 +1657,7 @@
+ if (f1 > 0.0F && entity instanceof EntityLiving) {
+ entityliving = (EntityLiving) entity;
- entityliving.knockback((double) (f1 * 0.5F), (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)));
+ entityliving.knockback((double) (f1 * 0.5F), (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)), this, org.bukkit.event.entity.EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); // CraftBukkit
this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D));
diff --git a/nms-patches/net/minecraft/world/entity/EntityLightning.patch b/nms-patches/net/minecraft/world/entity/EntityLightning.patch
index 84f36215..04073819 100644
--- a/nms-patches/net/minecraft/world/entity/EntityLightning.patch
+++ b/nms-patches/net/minecraft/world/entity/EntityLightning.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/EntityLightning.java
+++ b/net/minecraft/world/entity/EntityLightning.java
-@@ -30,6 +30,11 @@
+@@ -31,6 +31,11 @@
import net.minecraft.world.phys.AxisAlignedBB;
import net.minecraft.world.phys.Vec3D;
@@ -12,7 +12,7 @@
public class EntityLightning extends Entity {
private static final int START_LIFE = 2;
-@@ -121,7 +126,7 @@
+@@ -120,7 +125,7 @@
}
}
@@ -21,7 +21,7 @@
} else if (this.life < -this.random.nextInt(10)) {
--this.flashes;
this.life = 1;
-@@ -130,7 +135,7 @@
+@@ -129,7 +134,7 @@
}
}
@@ -30,37 +30,37 @@
if (!(this.level() instanceof WorldServer)) {
this.level().setSkyFlashTime(2);
} else if (!this.visualOnly) {
-@@ -164,8 +169,12 @@
- IBlockData iblockdata = BlockFireAbstract.getState(this.level(), blockposition);
+@@ -169,8 +174,12 @@
+ IBlockData iblockdata = BlockFireAbstract.getState(this.level(), blockposition);
- if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) {
-- this.level().setBlockAndUpdate(blockposition, iblockdata);
-- ++this.blocksSetOnFire;
-+ // CraftBukkit start - add "!visualOnly"
-+ if (!visualOnly && !CraftEventFactory.callBlockIgniteEvent(this.level(), blockposition, this).isCancelled()) {
-+ this.level().setBlockAndUpdate(blockposition, iblockdata);
-+ ++this.blocksSetOnFire;
-+ }
-+ // CraftBukkit end
- }
+ if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) {
+- this.level().setBlockAndUpdate(blockposition, iblockdata);
+- ++this.blocksSetOnFire;
++ // CraftBukkit start - add "!visualOnly"
++ if (!visualOnly && !CraftEventFactory.callBlockIgniteEvent(this.level(), blockposition, this).isCancelled()) {
++ this.level().setBlockAndUpdate(blockposition, iblockdata);
++ ++this.blocksSetOnFire;
++ }
++ // CraftBukkit end
+ }
- for (int j = 0; j < i; ++j) {
-@@ -173,8 +182,12 @@
+ for (int j = 0; j < i; ++j) {
+@@ -178,8 +187,12 @@
- iblockdata = BlockFireAbstract.getState(this.level(), blockposition1);
- if (this.level().getBlockState(blockposition1).isAir() && iblockdata.canSurvive(this.level(), blockposition1)) {
-- this.level().setBlockAndUpdate(blockposition1, iblockdata);
-- ++this.blocksSetOnFire;
-+ // CraftBukkit start - add "!visualOnly"
-+ if (!visualOnly && !CraftEventFactory.callBlockIgniteEvent(this.level(), blockposition1, this).isCancelled()) {
-+ this.level().setBlockAndUpdate(blockposition1, iblockdata);
-+ ++this.blocksSetOnFire;
-+ }
-+ // CraftBukkit end
- }
- }
+ iblockdata = BlockFireAbstract.getState(this.level(), blockposition1);
+ if (this.level().getBlockState(blockposition1).isAir() && iblockdata.canSurvive(this.level(), blockposition1)) {
+- this.level().setBlockAndUpdate(blockposition1, iblockdata);
+- ++this.blocksSetOnFire;
++ // CraftBukkit start - add "!visualOnly"
++ if (!visualOnly && !CraftEventFactory.callBlockIgniteEvent(this.level(), blockposition1, this).isCancelled()) {
++ this.level().setBlockAndUpdate(blockposition1, iblockdata);
++ ++this.blocksSetOnFire;
++ }
++ // CraftBukkit end
+ }
+ }
-@@ -238,8 +251,9 @@
+@@ -247,8 +260,9 @@
iblockdata = world.getBlockState(blockposition1);
} while (!(iblockdata.getBlock() instanceof WeatheringCopper));
diff --git a/nms-patches/net/minecraft/world/entity/EntityLiving.patch b/nms-patches/net/minecraft/world/entity/EntityLiving.patch
index 1db9c0fb..730ea72b 100644
--- a/nms-patches/net/minecraft/world/entity/EntityLiving.patch
+++ b/nms-patches/net/minecraft/world/entity/EntityLiving.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/EntityLiving.java
+++ b/net/minecraft/world/entity/EntityLiving.java
-@@ -132,6 +132,32 @@
+@@ -137,6 +137,33 @@
import net.minecraft.world.scores.ScoreboardTeam;
import org.slf4j.Logger;
@@ -8,10 +8,11 @@
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
-+import com.google.common.base.Function;
++import java.util.LinkedList;
+import java.util.UUID;
+import net.minecraft.nbt.NBTTagFloat;
+import net.minecraft.nbt.NBTTagInt;
++import net.minecraft.world.item.component.Consumable;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.attribute.CraftAttributeMap;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
@@ -33,18 +34,9 @@
public abstract class EntityLiving extends Entity implements Attackable {
private static final Logger LOGGER = LogUtils.getLogger();
-@@ -157,7 +183,7 @@
- private static final double MAX_LINE_OF_SIGHT_TEST_RANGE = 128.0D;
- protected static final int LIVING_ENTITY_FLAG_IS_USING = 1;
- protected static final int LIVING_ENTITY_FLAG_OFF_HAND = 2;
-- protected static final int LIVING_ENTITY_FLAG_SPIN_ATTACK = 4;
-+ public static final int LIVING_ENTITY_FLAG_SPIN_ATTACK = 4;
- protected static final DataWatcherObject DATA_LIVING_ENTITY_FLAGS = DataWatcher.defineId(EntityLiving.class, DataWatcherRegistry.BYTE);
- public static final DataWatcherObject DATA_HEALTH_ID = DataWatcher.defineId(EntityLiving.class, DataWatcherRegistry.FLOAT);
- private static final DataWatcherObject> DATA_EFFECT_PARTICLES = DataWatcher.defineId(EntityLiving.class, DataWatcherRegistry.PARTICLES);
-@@ -249,6 +275,19 @@
+@@ -262,6 +289,19 @@
protected boolean skipDropExperience;
- private final Reference2ObjectMap> activeLocationDependentEnchantments;
+ private final EnumMap>> activeLocationDependentEnchantments;
protected float appliedScale;
+ // CraftBukkit start
+ public int expToDrop;
@@ -62,8 +54,8 @@
protected EntityLiving(EntityTypes extends EntityLiving> entitytypes, World world) {
super(entitytypes, world);
-@@ -264,7 +303,9 @@
- this.activeLocationDependentEnchantments = new Reference2ObjectArrayMap();
+@@ -278,7 +318,9 @@
+ this.activeLocationDependentEnchantments = new EnumMap(EnumItemSlot.class);
this.appliedScale = 1.0F;
this.attributes = new AttributeMapBase(AttributeDefaults.getSupplier(entitytypes));
- this.setHealth(this.getMaxHealth());
@@ -73,22 +65,22 @@
this.blocksBuilding = true;
this.rotA = (float) ((Math.random() + 1.0D) * 0.009999999776482582D);
this.reapplyPosition();
-@@ -344,7 +385,13 @@
+@@ -358,7 +400,13 @@
double d8 = Math.min((double) (0.2F + f / 15.0F), 2.5D);
int i = (int) (150.0D * d8);
-- ((WorldServer) this.level()).sendParticles(new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D);
+- worldserver.sendParticles(new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D);
+ // CraftBukkit start - visiblity api
+ if (this instanceof EntityPlayer) {
-+ ((WorldServer) this.level()).sendParticles((EntityPlayer) this, new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, false);
++ worldserver.sendParticles((EntityPlayer) this, new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, false);
+ } else {
-+ ((WorldServer) this.level()).sendParticles(new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D);
++ worldserver.sendParticles(new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D);
+ }
+ // CraftBukkit end
}
}
}
-@@ -555,7 +602,7 @@
+@@ -573,7 +621,7 @@
++this.deathTime;
if (this.deathTime >= 20 && !this.level().isClientSide() && !this.isRemoved()) {
this.level().broadcastEntityEvent(this, (byte) 60);
@@ -97,7 +89,7 @@
}
}
-@@ -661,13 +708,19 @@
+@@ -679,13 +727,19 @@
}
public void onEquipItem(EnumItemSlot enumitemslot, ItemStack itemstack, ItemStack itemstack1) {
@@ -107,18 +99,18 @@
+
+ public void onEquipItem(EnumItemSlot enumitemslot, ItemStack itemstack, ItemStack itemstack1, boolean silent) {
+ // CraftBukkit end
- boolean flag = itemstack1.isEmpty() && itemstack.isEmpty();
+ if (!this.level().isClientSide() && !this.isSpectator()) {
+ boolean flag = itemstack1.isEmpty() && itemstack.isEmpty();
- if (!flag && !ItemStack.isSameItemSameComponents(itemstack, itemstack1) && !this.firstTick) {
- Equipable equipable = Equipable.get(itemstack1);
+ if (!flag && !ItemStack.isSameItemSameComponents(itemstack, itemstack1) && !this.firstTick) {
+ Equippable equippable = (Equippable) itemstack1.get(DataComponents.EQUIPPABLE);
- if (!this.level().isClientSide() && !this.isSpectator()) {
-- if (!this.isSilent() && equipable != null && equipable.getEquipmentSlot() == enumitemslot) {
-+ if (!this.isSilent() && equipable != null && equipable.getEquipmentSlot() == enumitemslot && !silent) { // CraftBukkit
- this.level().playSeededSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), equipable.getEquipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong());
+- if (!this.isSilent() && equippable != null && enumitemslot == equippable.slot()) {
++ if (!this.isSilent() && equippable != null && enumitemslot == equippable.slot() && !silent) { // CraftBukkit
+ this.level().playSeededSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), equippable.equipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong());
}
-@@ -681,11 +734,18 @@
+@@ -699,6 +753,13 @@
@Override
public void remove(Entity.RemovalReason entity_removalreason) {
@@ -130,7 +122,10 @@
+ public void remove(Entity.RemovalReason entity_removalreason, EntityRemoveEvent.Cause cause) {
+ // CraftBukkit end
if (entity_removalreason == Entity.RemovalReason.KILLED || entity_removalreason == Entity.RemovalReason.DISCARDED) {
- this.triggerOnDeathMobEffects(entity_removalreason);
+ World world = this.level();
+
+@@ -709,7 +770,7 @@
+ }
}
- super.remove(entity_removalreason);
@@ -138,15 +133,15 @@
this.brain.clearMemories();
}
-@@ -698,6 +758,7 @@
- mobeffect.onMobRemoved(this, entity_removalreason);
+@@ -722,6 +783,7 @@
+ mobeffect.onMobRemoved(worldserver, this, entity_removalreason);
}
+ this.removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause.DEATH); // CraftBukkit
this.activeEffects.clear();
}
-@@ -757,6 +818,17 @@
+@@ -781,6 +843,17 @@
}
}
@@ -164,7 +159,7 @@
if (nbttagcompound.contains("Health", 99)) {
this.setHealth(nbttagcompound.getFloat("Health"));
}
-@@ -795,9 +867,32 @@
+@@ -819,9 +892,32 @@
}
@@ -197,7 +192,7 @@
try {
while (iterator.hasNext()) {
Holder holder = (Holder) iterator.next();
-@@ -807,6 +902,12 @@
+@@ -831,6 +927,12 @@
this.onEffectUpdated(mobeffect, true, (Entity) null);
})) {
if (!this.level().isClientSide) {
@@ -208,9 +203,9 @@
+ }
+ // CraftBukkit end
iterator.remove();
- this.onEffectRemoved(mobeffect);
+ this.onEffectsRemoved(List.of(mobeffect));
}
-@@ -817,6 +918,17 @@
+@@ -841,6 +943,17 @@
} catch (ConcurrentModificationException concurrentmodificationexception) {
;
}
@@ -228,7 +223,7 @@
if (this.effectsDirty) {
if (!this.level().isClientSide) {
-@@ -932,7 +1044,13 @@
+@@ -952,17 +1065,36 @@
this.entityData.set(EntityLiving.DATA_EFFECT_PARTICLES, List.of());
}
@@ -241,24 +236,35 @@
+ // CraftBukkit end
if (this.level().isClientSide) {
return false;
+ } else if (this.activeEffects.isEmpty()) {
+ return false;
} else {
-@@ -941,7 +1059,14 @@
- boolean flag;
+- Map, MobEffect> map = Maps.newHashMap(this.activeEffects);
++ // CraftBukkit start
++ List toRemove = new LinkedList<>();
++ Iterator iterator = this.activeEffects.values().iterator();
- for (flag = false; iterator.hasNext(); flag = true) {
-- this.onEffectRemoved((MobEffect) iterator.next());
-+ // CraftBukkit start
-+ MobEffect effect = (MobEffect) iterator.next();
+- this.activeEffects.clear();
+- this.onEffectsRemoved(map.values());
+- return true;
++ while (iterator.hasNext()) {
++ MobEffect effect = iterator.next();
+ EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent(this, effect, null, cause, EntityPotionEffectEvent.Action.CLEARED);
+ if (event.isCancelled()) {
+ continue;
+ }
-+ this.onEffectRemoved(effect);
-+ // CraftBukkit end
- iterator.remove();
- }
++
++ iterator.remove();
++ toRemove.add(effect);
++ }
++
++ this.onEffectsRemoved(toRemove);
++ return !toRemove.isEmpty();
++ // CraftBukkit end
+ }
+ }
-@@ -970,20 +1095,50 @@
+@@ -987,20 +1119,50 @@
return this.addEffect(mobeffect, (Entity) null);
}
@@ -310,7 +316,7 @@
flag = true;
}
-@@ -1014,13 +1169,39 @@
+@@ -1031,13 +1193,39 @@
return this.getType().is(TagsEntity.INVERTED_HEALING_AND_HARM);
}
@@ -350,8 +356,8 @@
+ // CraftBukkit end
if (mobeffect != null) {
- this.onEffectRemoved(mobeffect);
-@@ -1118,20 +1299,55 @@
+ this.onEffectsRemoved(List.of(mobeffect));
+@@ -1142,20 +1330,55 @@
}
@@ -408,18 +414,18 @@
this.entityData.set(EntityLiving.DATA_HEALTH_ID, MathHelper.clamp(f, 0.0F, this.getMaxHealth()));
}
-@@ -1145,7 +1361,7 @@
- return false;
- } else if (this.level().isClientSide) {
+@@ -1167,7 +1390,7 @@
+ public boolean hurtServer(WorldServer worldserver, DamageSource damagesource, float f) {
+ if (this.isInvulnerableTo(worldserver, damagesource)) {
return false;
- } else if (this.isDeadOrDying()) {
+ } else if (this.isRemoved() || this.dead || this.getHealth() <= 0.0F) { // CraftBukkit - Don't allow entities that got set to dead/killed elsewhere to get damaged and die
return false;
} else if (damagesource.is(DamageTypeTags.IS_FIRE) && this.hasEffect(MobEffects.FIRE_RESISTANCE)) {
return false;
-@@ -1156,10 +1372,11 @@
+@@ -1182,10 +1405,11 @@
+ }
- this.noActionTime = 0;
float f1 = f;
- boolean flag = false;
+ boolean flag = f > 0.0F && this.isDamageSourceBlocked(damagesource); // Copied from below
@@ -431,7 +437,7 @@
this.hurtCurrentlyUsedShield(f);
f2 = f;
f = 0.0F;
-@@ -1176,30 +1393,50 @@
+@@ -1202,15 +1426,26 @@
flag = true;
}
@@ -458,6 +464,10 @@
+ // CraftBukkit end
+
this.walkAnimation.setSpeed(1.5F);
+ if (Float.isNaN(f) || Float.isInfinite(f)) {
+ f = Float.MAX_VALUE;
+@@ -1218,18 +1453,27 @@
+
boolean flag1 = true;
- if ((float) this.invulnerableTime > 10.0F && !damagesource.is(DamageTypeTags.BYPASSES_COOLDOWN)) {
@@ -466,9 +476,9 @@
return false;
}
-- this.actuallyHurt(damagesource, f - this.lastHurt);
+- this.actuallyHurt(worldserver, damagesource, f - this.lastHurt);
+ // CraftBukkit start
-+ if (!this.actuallyHurt(damagesource, (float) event.getFinalDamage() - this.lastHurt, event)) {
++ if (!this.actuallyHurt(worldserver, damagesource, (float) event.getFinalDamage() - this.lastHurt, event)) {
+ return false;
+ }
+ // CraftBukkit end
@@ -476,20 +486,20 @@
flag1 = false;
} else {
+ // CraftBukkit start
-+ if (!this.actuallyHurt(damagesource, (float) event.getFinalDamage(), event)) {
++ if (!this.actuallyHurt(worldserver, damagesource, (float) event.getFinalDamage(), event)) {
+ return false;
+ }
this.lastHurt = f;
- this.invulnerableTime = 20;
-- this.actuallyHurt(damagesource, f);
+- this.actuallyHurt(worldserver, damagesource, f);
+ this.invulnerableTime = this.invulnerableDuration; // CraftBukkit - restore use of maxNoDamageTicks
-+ // this.actuallyHurt(damagesource, f);
++ // this.actuallyHurt(worldserver, damagesource, f);
+ // CraftBukkit end
this.hurtDuration = 10;
this.hurtTime = this.hurtDuration;
}
-@@ -1245,7 +1482,7 @@
- this.level().broadcastDamageEvent(this, damagesource);
+@@ -1275,7 +1519,7 @@
+ worldserver.broadcastDamageEvent(this, damagesource);
}
- if (!damagesource.is(DamageTypeTags.NO_IMPACT) && (!flag || f > 0.0F)) {
@@ -497,7 +507,7 @@
this.markHurt();
}
-@@ -1265,7 +1502,7 @@
+@@ -1295,7 +1539,7 @@
d1 = damagesource.getSourcePosition().z() - this.getZ();
}
@@ -506,7 +516,7 @@
if (!flag) {
this.indicateDamage(d0, d1);
}
-@@ -1284,7 +1521,7 @@
+@@ -1314,7 +1558,7 @@
this.playHurtSound(damagesource);
}
@@ -515,7 +525,7 @@
if (flag2) {
this.lastDamageSource = damagesource;
-@@ -1318,7 +1555,7 @@
+@@ -1352,7 +1596,7 @@
}
protected void blockedByShield(EntityLiving entityliving) {
@@ -524,7 +534,7 @@
}
private boolean checkTotemDeathProtection(DamageSource damagesource) {
-@@ -1329,19 +1566,32 @@
+@@ -1364,20 +1608,33 @@
EnumHand[] aenumhand = EnumHand.values();
int i = aenumhand.length;
@@ -536,7 +546,8 @@
- ItemStack itemstack1 = this.getItemInHand(enumhand);
+ itemstack1 = this.getItemInHand(enumhand);
- if (itemstack1.is(Items.TOTEM_OF_UNDYING)) {
+ deathprotection = (DeathProtection) itemstack1.get(DataComponents.DEATH_PROTECTION);
+ if (deathprotection != null) {
+ hand = enumhand; // CraftBukkit
itemstack = itemstack1.copy();
- itemstack1.shrink(1);
@@ -560,30 +571,8 @@
+ // CraftBukkit end
EntityPlayer entityplayer = (EntityPlayer) this;
- entityplayer.awardStat(StatisticList.ITEM_USED.get(Items.TOTEM_OF_UNDYING));
-@@ -1350,14 +1600,16 @@
- }
-
- this.setHealth(1.0F);
-- this.removeAllEffects();
-- this.addEffect(new MobEffect(MobEffects.REGENERATION, 900, 1));
-- this.addEffect(new MobEffect(MobEffects.ABSORPTION, 100, 1));
-- this.addEffect(new MobEffect(MobEffects.FIRE_RESISTANCE, 800, 0));
-+ // CraftBukkit start
-+ this.removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM);
-+ this.addEffect(new MobEffect(MobEffects.REGENERATION, 900, 1), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM);
-+ this.addEffect(new MobEffect(MobEffects.ABSORPTION, 100, 1), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM);
-+ this.addEffect(new MobEffect(MobEffects.FIRE_RESISTANCE, 800, 0), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM);
-+ // CraftBukkit end
- this.level().broadcastEntityEvent(this, (byte) 35);
- }
-
-- return itemstack != null;
-+ return !event.isCancelled();
- }
- }
-
-@@ -1464,14 +1716,22 @@
+ entityplayer.awardStat(StatisticList.ITEM_USED.get(itemstack.getItem()));
+@@ -1501,14 +1758,22 @@
IBlockData iblockdata = Blocks.WITHER_ROSE.defaultBlockState();
if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) {
@@ -608,13 +597,13 @@
this.level().addFreshEntity(entityitem);
}
}
-@@ -1482,26 +1742,41 @@
+@@ -1519,22 +1784,37 @@
protected void dropAllDeathLoot(WorldServer worldserver, DamageSource damagesource) {
boolean flag = this.lastHurtByPlayerTime > 0;
-+ this.dropEquipment(); // CraftBukkit - from below
++ this.dropEquipment(worldserver); // CraftBukkit - from below
if (this.shouldDropLoot() && worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
- this.dropFromLootTable(damagesource, flag);
+ this.dropFromLootTable(worldserver, damagesource, flag);
this.dropCustomDeathLoot(worldserver, damagesource, flag);
}
+ // CraftBukkit start - Call death event
@@ -622,38 +611,34 @@
+ this.drops = new ArrayList<>();
+ // CraftBukkit end
-- this.dropEquipment();
-+ // this.dropEquipment();// CraftBukkit - moved up
- this.dropExperience(damagesource.getEntity());
+- this.dropEquipment(worldserver);
++ // this.dropEquipment(worldserver);// CraftBukkit - moved up
+ this.dropExperience(worldserver, damagesource.getEntity());
}
- protected void dropEquipment() {}
+ protected void dropEquipment(WorldServer worldserver) {}
-- protected void dropExperience(@Nullable Entity entity) {
-+ public int getExpReward(@Nullable Entity entity) { // CraftBukkit
- World world = this.level();
-
- if (world instanceof WorldServer worldserver) {
- if (!this.wasExperienceConsumed() && (this.isAlwaysExperienceDropper() || this.lastHurtByPlayerTime > 0 && this.shouldDropExperience() && this.level().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT))) {
-- EntityExperienceOrb.award(worldserver, this.position(), this.getExperienceReward(worldserver, entity));
-+ return this.getExperienceReward(worldserver, entity); // CraftBukkit
- }
+- protected void dropExperience(WorldServer worldserver, @Nullable Entity entity) {
++ public int getExpReward(WorldServer worldserver, @Nullable Entity entity) { // CraftBukkit
+ if (!this.wasExperienceConsumed() && (this.isAlwaysExperienceDropper() || this.lastHurtByPlayerTime > 0 && this.shouldDropExperience() && worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT))) {
+- EntityExperienceOrb.award(worldserver, this.position(), this.getExperienceReward(worldserver, entity));
++ return this.getExperienceReward(worldserver, entity); // CraftBukkit }
}
+ return 0; // CraftBukkit
+ }
+
-+ protected void dropExperience(@Nullable Entity entity) {
++ protected void dropExperience(WorldServer worldserver, @Nullable Entity entity) {
+ // CraftBukkit start - Update getExpReward() above if the removed if() changes!
+ if (!(this instanceof net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon)) { // CraftBukkit - SPIGOT-2420: Special case ender dragon will drop the xp over time
-+ EntityExperienceOrb.award((WorldServer) this.level(), this.position(), this.expToDrop);
++ EntityExperienceOrb.award(worldserver, this.position(), this.expToDrop);
+ this.expToDrop = 0;
+ }
+ // CraftBukkit end
}
protected void dropCustomDeathLoot(WorldServer worldserver, DamageSource damagesource, boolean flag) {}
-@@ -1540,9 +1815,14 @@
+@@ -1601,9 +1881,14 @@
}
public void knockback(double d0, double d1, double d2) {
@@ -670,7 +655,7 @@
Vec3D vec3d;
-@@ -1552,7 +1832,14 @@
+@@ -1613,7 +1898,14 @@
Vec3D vec3d1 = (new Vec3D(d1, 0.0D, d2)).normalize().scale(d0);
@@ -686,8 +671,8 @@
}
}
-@@ -1613,6 +1900,28 @@
- return itemstack.getEatingSound();
+@@ -1668,6 +1960,20 @@
+ return new EntityLiving.a(SoundEffects.GENERIC_SMALL_FALL, SoundEffects.GENERIC_BIG_FALL);
}
+ // CraftBukkit start - Add delegate methods
@@ -702,25 +687,17 @@
+ public SoundEffect getFallDamageSound0(int fallHeight) {
+ return getFallDamageSound(fallHeight);
+ }
-+
-+ public SoundEffect getDrinkingSound0(ItemStack itemstack) {
-+ return getDrinkingSound(itemstack);
-+ }
-+
-+ public SoundEffect getEatingSound0(ItemStack itemstack) {
-+ return getEatingSound(itemstack);
-+ }
+ // CraftBukkit end
+
public Optional getLastClimbablePos() {
return this.lastClimbablePos;
}
-@@ -1666,9 +1975,14 @@
+@@ -1746,9 +2052,14 @@
int i = this.calculateFallDamage(f, f1);
if (i > 0) {
+ // CraftBukkit start
-+ if (!this.hurt(damagesource, (float) i)) {
++ if (!this.hurtServer((WorldServer) this.level(), damagesource, (float) i)) {
+ return true;
+ }
+ // CraftBukkit end
@@ -731,7 +708,7 @@
return true;
} else {
return flag;
-@@ -1738,7 +2052,7 @@
+@@ -1819,7 +2130,7 @@
protected float getDamageAfterArmorAbsorb(DamageSource damagesource, float f) {
if (!damagesource.is(DamageTypeTags.BYPASSES_ARMOR)) {
@@ -740,7 +717,7 @@
f = CombatMath.getDamageAfterAbsorb(this, f, damagesource, (float) this.getArmorValue(), (float) this.getAttributeValue(GenericAttributes.ARMOR_TOUGHNESS));
}
-@@ -1749,7 +2063,8 @@
+@@ -1830,7 +2141,8 @@
if (damagesource.is(DamageTypeTags.BYPASSES_EFFECTS)) {
return f;
} else {
@@ -750,16 +727,16 @@
int i = (this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5;
int j = 25 - i;
float f1 = f * (float) j;
-@@ -1792,15 +2107,140 @@
+@@ -1873,15 +2185,140 @@
}
}
-- protected void actuallyHurt(DamageSource damagesource, float f) {
+- protected void actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f) {
+ // CraftBukkit start
+ private EntityDamageEvent handleEntityDamage(final DamageSource damagesource, float f) {
+ float originalDamage = f;
+
-+ Function freezing = new Function() {
++ com.google.common.base.Function freezing = new com.google.common.base.Function() {
+ @Override
+ public Double apply(Double f) {
+ if (damagesource.is(DamageTypeTags.IS_FREEZING) && EntityLiving.this.getType().is(TagsEntity.FREEZE_HURTS_EXTRA_TYPES)) {
@@ -771,7 +748,7 @@
+ float freezingModifier = freezing.apply((double) f).floatValue();
+ f += freezingModifier;
+
-+ Function hardHat = new Function() {
++ com.google.common.base.Function hardHat = new com.google.common.base.Function() {
+ @Override
+ public Double apply(Double f) {
+ if (damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !EntityLiving.this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
@@ -783,7 +760,7 @@
+ float hardHatModifier = hardHat.apply((double) f).floatValue();
+ f += hardHatModifier;
+
-+ Function blocking = new Function() {
++ com.google.common.base.Function blocking = new com.google.common.base.Function() {
+ @Override
+ public Double apply(Double f) {
+ return -((EntityLiving.this.isDamageSourceBlocked(damagesource)) ? f : 0.0);
@@ -792,7 +769,7 @@
+ float blockingModifier = blocking.apply((double) f).floatValue();
+ f += blockingModifier;
+
-+ Function armor = new Function() {
++ com.google.common.base.Function armor = new com.google.common.base.Function() {
+ @Override
+ public Double apply(Double f) {
+ return -(f - EntityLiving.this.getDamageAfterArmorAbsorb(damagesource, f.floatValue()));
@@ -801,7 +778,7 @@
+ float armorModifier = armor.apply((double) f).floatValue();
+ f += armorModifier;
+
-+ Function resistance = new Function() {
++ com.google.common.base.Function resistance = new com.google.common.base.Function() {
+ @Override
+ public Double apply(Double f) {
+ if (!damagesource.is(DamageTypeTags.BYPASSES_EFFECTS) && EntityLiving.this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && !damagesource.is(DamageTypeTags.BYPASSES_RESISTANCE)) {
@@ -816,7 +793,7 @@
+ float resistanceModifier = resistance.apply((double) f).floatValue();
+ f += resistanceModifier;
+
-+ Function magic = new Function() {
++ com.google.common.base.Function magic = new com.google.common.base.Function() {
+ @Override
+ public Double apply(Double f) {
+ return -(f - EntityLiving.this.getDamageAfterMagicAbsorb(damagesource, f.floatValue()));
@@ -825,7 +802,7 @@
+ float magicModifier = magic.apply((double) f).floatValue();
+ f += magicModifier;
+
-+ Function absorption = new Function() {
++ com.google.common.base.Function absorption = new com.google.common.base.Function() {
+ @Override
+ public Double apply(Double f) {
+ return -(Math.max(f - Math.max(f - EntityLiving.this.getAbsorptionAmount(), 0.0F), 0.0F));
@@ -836,8 +813,8 @@
+ return CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, freezingModifier, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, freezing, hardHat, blocking, armor, resistance, magic, absorption);
+ }
+
-+ protected boolean actuallyHurt(final DamageSource damagesource, float f, final EntityDamageEvent event) { // void -> boolean, add final
- if (!this.isInvulnerableTo(damagesource)) {
++ protected boolean actuallyHurt(WorldServer worldserver, final DamageSource damagesource, float f, final EntityDamageEvent event) { // void -> boolean, add final
+ if (!this.isInvulnerableTo(worldserver, damagesource)) {
- f = this.getDamageAfterArmorAbsorb(damagesource, f);
- f = this.getDamageAfterMagicAbsorb(damagesource, f);
- float f1 = f;
@@ -898,7 +875,7 @@
if (f2 > 0.0F && f2 < 3.4028235E37F) {
Entity entity = damagesource.getEntity();
-@@ -1812,13 +2252,48 @@
+@@ -1893,13 +2330,48 @@
}
}
@@ -949,7 +926,7 @@
}
public CombatTracker getCombatTracker() {
-@@ -1843,9 +2318,19 @@
+@@ -1924,9 +2396,19 @@
}
public final void setArrowCount(int i) {
@@ -970,7 +947,7 @@
public final int getStingerCount() {
return (Integer) this.entityData.get(EntityLiving.DATA_STINGER_COUNT_ID);
}
-@@ -2086,6 +2571,12 @@
+@@ -2171,6 +2653,12 @@
public abstract ItemStack getItemBySlot(EnumItemSlot enumitemslot);
@@ -983,15 +960,7 @@
public abstract void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack);
public Iterable getHandSlots() {
-@@ -2336,6 +2827,7 @@
- }
-
- if (this.onGround() && !this.level().isClientSide) {
-+ if (getSharedFlag(7) && !CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) // CraftBukkit
- this.setSharedFlag(7, false);
- }
- } else {
-@@ -2506,7 +2998,7 @@
+@@ -2623,7 +3111,7 @@
}
}
@@ -1000,8 +969,8 @@
if (this.tickCount % 20 == 0) {
this.getCombatTracker().recheckStatus();
}
-@@ -2610,7 +3102,7 @@
-
+@@ -2730,7 +3218,7 @@
+ this.elytraAnimationState.tick();
}
- public void detectEquipmentUpdates() {
@@ -1009,15 +978,15 @@
Map map = this.collectEquipmentChanges();
if (map != null) {
-@@ -2949,6 +3441,7 @@
- }
-
+@@ -3052,6 +3540,7 @@
+ this.checkSlowFallDistance();
if (!this.level().isClientSide) {
-+ if (flag != this.getSharedFlag(7) && !CraftEventFactory.callToggleGlideEvent(this, flag).isCancelled()) // CraftBukkit
- this.setSharedFlag(7, flag);
- }
-
-@@ -3141,13 +3634,20 @@
+ if (!this.canGlide()) {
++ if (this.getSharedFlag(7) != false && !CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) // CraftBukkit
+ this.setSharedFlag(7, false);
+ return;
+ }
+@@ -3298,14 +3787,21 @@
@Override
public boolean isPickable() {
@@ -1029,30 +998,22 @@
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() {
-@@ -3245,7 +3745,7 @@
-
- }
-
-- protected void setLivingEntityFlag(int i, boolean flag) {
-+ public void setLivingEntityFlag(int i, boolean flag) {
- int j = (Byte) this.entityData.get(EntityLiving.DATA_LIVING_ENTITY_FLAGS);
-
- if (flag) {
-@@ -3346,7 +3846,29 @@
+ return this.yHeadRot;
+@@ -3476,7 +3972,30 @@
+ this.releaseUsingItem();
} else {
if (!this.useItem.isEmpty() && this.isUsingItem()) {
- this.triggerItemUseEffects(this.useItem, 16);
- ItemStack itemstack = this.useItem.finishUsingItem(this.level(), this);
+ // CraftBukkit start - fire PlayerItemConsumeEvent
+ ItemStack itemstack;
@@ -1064,8 +1025,9 @@
+
+ if (event.isCancelled()) {
+ // Update client
-+ if (this.useItem.getItem() instanceof net.minecraft.world.item.ItemSuspiciousStew itemSuspiciousStew) {
-+ itemSuspiciousStew.cancelUsingItem(entityPlayer, this.useItem);
++ Consumable consumable = this.useItem.get(DataComponents.CONSUMABLE);
++ if (consumable != null) {
++ consumable.cancelUsingItem(entityPlayer, this.useItem);
+ }
+ entityPlayer.getBukkitEntity().updateInventory();
+ entityPlayer.getBukkitEntity().updateScaledHealth();
@@ -1080,7 +1042,7 @@
if (itemstack != this.useItem) {
this.setItemInHand(enumhand, itemstack);
-@@ -3424,6 +3946,12 @@
+@@ -3561,6 +4080,12 @@
}
public boolean randomTeleport(double d0, double d1, double d2, boolean flag) {
@@ -1093,7 +1055,7 @@
double d3 = this.getX();
double d4 = this.getY();
double d5 = this.getZ();
-@@ -3448,16 +3976,41 @@
+@@ -3585,16 +4110,41 @@
}
if (flag2) {
@@ -1121,7 +1083,7 @@
+ }
+ } else {
+ // player teleport event is called in the underlining code
-+ if (!((EntityPlayer) this).connection.teleport(d0, d6, d2, this.getYRot(), this.getXRot(), java.util.Collections.emptySet(), cause)) {
++ if (!((EntityPlayer) this).connection.teleport(d0, d6, d2, this.getYRot(), this.getXRot(), cause)) {
+ return Optional.empty();
+ }
+ }
@@ -1138,7 +1100,7 @@
} else {
if (flag) {
world.broadcastEntityEvent(this, (byte) 46);
-@@ -3469,7 +4022,7 @@
+@@ -3606,7 +4156,7 @@
entitycreature.getNavigation().stop();
}
@@ -1147,7 +1109,7 @@
}
}
-@@ -3562,7 +4115,7 @@
+@@ -3699,7 +4249,7 @@
}
public void stopSleeping() {
@@ -1156,7 +1118,7 @@
World world = this.level();
java.util.Objects.requireNonNull(world);
-@@ -3596,7 +4149,7 @@
+@@ -3733,7 +4283,7 @@
@Nullable
public EnumDirection getBedOrientation() {
@@ -1165,12 +1127,3 @@
return blockposition != null ? BlockBed.getBedOrientation(this.level(), blockposition) : null;
}
-@@ -3633,7 +4186,7 @@
- FoodInfo.b foodinfo_b = (FoodInfo.b) iterator.next();
-
- if (this.random.nextFloat() < foodinfo_b.probability()) {
-- this.addEffect(foodinfo_b.effect());
-+ this.addEffect(foodinfo_b.effect(), EntityPotionEffectEvent.Cause.FOOD); // CraftBukkit
- }
- }
-
diff --git a/nms-patches/net/minecraft/world/entity/EntityTameableAnimal.patch b/nms-patches/net/minecraft/world/entity/EntityTameableAnimal.patch
index cd568c29..c7f83229 100644
--- a/nms-patches/net/minecraft/world/entity/EntityTameableAnimal.patch
+++ b/nms-patches/net/minecraft/world/entity/EntityTameableAnimal.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/EntityTameableAnimal.java
+++ b/net/minecraft/world/entity/EntityTameableAnimal.java
-@@ -27,6 +27,12 @@
+@@ -28,6 +28,12 @@
import net.minecraft.world.level.pathfinder.PathfinderNormal;
import net.minecraft.world.scores.ScoreboardTeam;
@@ -13,7 +13,7 @@
public abstract class EntityTameableAnimal extends EntityAnimal implements OwnableEntity {
public static final int TELEPORT_WHEN_DISTANCE_IS_SQ = 144;
-@@ -281,7 +287,14 @@
+@@ -292,7 +298,14 @@
if (!this.canTeleportTo(new BlockPosition(i, j, k))) {
return false;
} else {
diff --git a/nms-patches/net/minecraft/world/entity/EntityTypes.patch b/nms-patches/net/minecraft/world/entity/EntityTypes.patch
index fc45d0b2..a57f473f 100644
--- a/nms-patches/net/minecraft/world/entity/EntityTypes.patch
+++ b/nms-patches/net/minecraft/world/entity/EntityTypes.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/EntityTypes.java
+++ b/net/minecraft/world/entity/EntityTypes.java
-@@ -168,6 +168,7 @@
+@@ -176,6 +176,7 @@
import net.minecraft.world.phys.Vec3D;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapes;
@@ -8,83 +8,81 @@
import org.slf4j.Logger;
public class EntityTypes