-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for Inventory Totem #123
- Loading branch information
1 parent
27cdcd9
commit 7932723
Showing
3 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
common/src/main/java/net/blay09/mods/hardcorerevival/compat/InventoryTotemAddon.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.blay09.mods.hardcorerevival.compat; | ||
|
||
import net.blay09.mods.balm.api.Balm; | ||
import net.blay09.mods.hardcorerevival.api.PlayerAboutToKnockOutEvent; | ||
import net.minecraft.core.component.DataComponents; | ||
|
||
public class InventoryTotemAddon { | ||
public InventoryTotemAddon() { | ||
Balm.getEvents().onEvent(PlayerAboutToKnockOutEvent.class, event -> { | ||
final var player = event.getPlayer(); | ||
final var inventory = player.getInventory(); | ||
for (int i = 0; i < inventory.getContainerSize(); i++) { | ||
final var itemStack = inventory.getItem(i); | ||
final var deathProtection = itemStack.get(DataComponents.DEATH_PROTECTION); | ||
if (deathProtection != null) { | ||
event.setCanceled(true); | ||
} | ||
} | ||
}); | ||
} | ||
} |