[1.18-pre8] Code review/input #1860
Unanswered
kwpugh
asked this question in
Mod Dev Support
Replies: 1 comment 1 reply
-
I can't really comment on the overall approach (I don't know that much about this area of the game). But your approach does seem reasonable.
You know fabric already has events to handle player deaths For retaining inventory position, I think you need to mixin the PlayerInventory.dropAll() and either
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm working on an enchantment like the classic Soul Bound that allows the player to "keep" the enchanted item after death.
Full GitHub: https://github.com/kwpugh/MoreGems/tree/1.18-pre8
I approached it by mixing into 2 classes.
Mixin#1:
@mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixinBound
{
@Inject(method="copyFrom", at = @at(value="RETURN"))
public void moregemsCopyFrom(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo ci)
{
if(!alive)
{
ServerPlayerEntity currentPlayer = (ServerPlayerEntity) (Object) this;
boolean ruleTest = currentPlayer.world.getGameRules().getBoolean(GameRules.KEEP_INVENTORY);
}
This seemed necessary to effectively copy the player inventory from old to new player.
Mixin#2
@Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @at("HEAD"), cancellable = true)
private void moregemsDropItem(@NotNull ItemStack stack, boolean throwRandomly, boolean retainOwnership, CallbackInfoReturnable cir)
{
PlayerEntity currentPlayer = (PlayerEntity) (Object) this;
World world = currentPlayer.world;
With this mixin, I wanted to perform the check and return null, but that would work. I resorted to giving the player back the stack if it has the enchantment on it.
Questions:
This works, but there is a delay after the player respawns, before the items reappear in inventory. Works on both SP and MP. It would be nice to have the items to remain in the same slots they were in prior to death.
Thank you for any input I receive.
Beta Was this translation helpful? Give feedback.
All reactions