Skip to content

Commit

Permalink
Fix: clear items with Curse of Vanishing from immediate_respawn behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Nov 11, 2024
1 parent c0bc6c6 commit 4a8fb43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.lovetropics.minigames.common.core.game.behavior.event.EventRegistrar;
import com.lovetropics.minigames.common.core.game.behavior.event.GameLivingEntityEvents;
import com.lovetropics.minigames.common.core.game.behavior.event.GamePlayerEvents;
import com.lovetropics.minigames.common.core.game.behavior.instances.ImmediateRespawnBehavior;
import com.lovetropics.minigames.common.core.game.state.GameProgressionState;
import com.lovetropics.minigames.common.core.game.state.ProgressionPeriod;
import com.mojang.serialization.Codec;
Expand Down Expand Up @@ -53,7 +54,7 @@ public void register(IGamePhase game, EventRegistrar events) throws GameExceptio

private InteractionResult onPlayerDeath(ServerPlayer player, DamageSource damageSource) {
if (forceDropItemsOnDeath && player.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY)) {
destroyVanishingCursedItems(player.getInventory());
ImmediateRespawnBehavior.destroyVanishingCursedItems(player.getInventory());
player.getInventory().dropAll();
}
return InteractionResult.PASS;
Expand All @@ -73,12 +74,5 @@ private InteractionResult onPlayerAttackEntity(ServerPlayer player, Entity targe
return InteractionResult.PASS;
}

private void destroyVanishingCursedItems(Container inventory) {
for (int i = 0; i < inventory.getContainerSize(); ++i) {
ItemStack itemstack = inventory.getItem(i);
if (!itemstack.isEmpty() && EnchantmentHelper.has(itemstack, EnchantmentEffectComponents.PREVENT_EQUIPMENT_DROP)) {
inventory.removeItemNoUpdate(i);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.Container;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
import net.minecraft.world.item.enchantment.EnchantmentHelper;

import javax.annotation.Nullable;
import java.util.Map;
Expand All @@ -39,6 +42,7 @@ public void register(IGamePhase game, EventRegistrar events) {
}

private InteractionResult onPlayerDeath(IGamePhase game, ServerPlayer player, DamageSource source) {
destroyVanishingCursedItems(player.getInventory());
if (dropInventory) {
player.getInventory().dropAll();
}
Expand Down Expand Up @@ -80,4 +84,12 @@ private void sendDeathMessage(IGamePhase game, ServerPlayer player) {
game.allPlayers().sendMessage(message);
}
}

public static void destroyVanishingCursedItems(Container inventory) {
for (int i = 0; i < inventory.getContainerSize(); ++i) {
if (EnchantmentHelper.has(inventory.getItem(i), EnchantmentEffectComponents.PREVENT_EQUIPMENT_DROP)) {
inventory.removeItemNoUpdate(i);
}
}
}
}

0 comments on commit 4a8fb43

Please sign in to comment.