Skip to content

Commit

Permalink
Readd items to inventory if bukkit set keepInv to true
Browse files Browse the repository at this point in the history
  • Loading branch information
JustRed23 committed Jul 30, 2024
1 parent fb241ab commit 475efbd
Showing 1 changed file with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@

boolean flag = this.lastHurtByPlayerTime > 0;
if (this.shouldDropLoot() && this.level().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
@@ -1349,15 +_,76 @@
@@ -1349,15 +_,74 @@
}

this.dropEquipment();
Expand All @@ -751,26 +751,24 @@
+ if (this instanceof ServerPlayer s) handlePlayerDeath(s, drops); //Ketting
+
+ if (!net.minecraftforge.common.ForgeHooks.onLivingDrops(this, p_21192_, drops, i, lastHurtByPlayerTime > 0))
+ drops.forEach(e -> level().addFreshEntity(e));
+ drops.forEach(e -> {
+ //Ketting start
+ if (this instanceof ServerPlayer s && handlePlayerDeath$cbKeepInv)
+ s.getInventory().add(e.getItem());
+ else
+ level().addFreshEntity(e);
+ //Ketting end
+ });
+
+ if (this instanceof ServerPlayer s && handlePlayerDeath$swap)
+ s.level().getGameRules().getRule(GameRules.RULE_KEEPINVENTORY).set(handlePlayerDeath$originalKeepInv, s.getServer()); //Ketting
+
+ /*if (!net.minecraftforge.common.ForgeHooks.onLivingDrops(this, p_21192_, drops, i, lastHurtByPlayerTime > 0))
+ //Ketting start - recapture if ServerPlayer
+ {
+ if (this instanceof ServerPlayer)
+ this.captureDrops(drops);
+ else
+ drops.forEach(e -> level().addFreshEntity(e));
+ }
+ //Ketting end*/
+
+ this.dropExperience(); //Ketting
+ }
+
+ //Ketting start
+ private boolean handlePlayerDeath$originalKeepInv;
+ private boolean handlePlayerDeath$cbKeepInv;
+ private boolean handlePlayerDeath$swap;
+ protected org.bukkit.event.entity.PlayerDeathEvent handlePlayerDeath$event;
+ private void handlePlayerDeath(ServerPlayer cast, Collection<ItemEntity> drops) {
Expand All @@ -782,16 +780,16 @@
+ return itemEntity;
+ });
+
+ handlePlayerDeath$originalKeepInv = cast.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || cast.isSpectator();
+ handlePlayerDeath$originalKeepInv = cast.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY);
+
+ cast.keepLevel = handlePlayerDeath$originalKeepInv; // SPIGOT-2222: pre-set keepLevel
+ cast.keepLevel = handlePlayerDeath$originalKeepInv || cast.isSpectator(); // SPIGOT-2222: pre-set keepLevel
+
+ org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory.callPlayerDeathEvent$skipDrops.set(true); //item drops are handled by forge
+ handlePlayerDeath$event = org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory.callPlayerDeathEvent(cast, bukkitDrops, cast.getCombatTracker().getDeathMessage().getString(), handlePlayerDeath$originalKeepInv);
+ handlePlayerDeath$event = org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory.callPlayerDeathEvent(cast, bukkitDrops, cast.getCombatTracker().getDeathMessage().getString(), handlePlayerDeath$originalKeepInv || cast.isSpectator());
+
+ boolean cbKeepInv = handlePlayerDeath$event.getKeepInventory();
+ handlePlayerDeath$swap = handlePlayerDeath$originalKeepInv ^ cbKeepInv;
+ if (handlePlayerDeath$swap) cast.level().getGameRules().getRule(GameRules.RULE_KEEPINVENTORY).set(cbKeepInv, cast.getServer());
+ handlePlayerDeath$cbKeepInv = handlePlayerDeath$event.getKeepInventory();
+ handlePlayerDeath$swap = handlePlayerDeath$originalKeepInv ^ handlePlayerDeath$cbKeepInv;
+ if (handlePlayerDeath$swap) cast.level().getGameRules().getRule(GameRules.RULE_KEEPINVENTORY).set(handlePlayerDeath$cbKeepInv, cast.getServer());
+ }
+ //Ketting end

Expand Down

0 comments on commit 475efbd

Please sign in to comment.