跳到正文

Dodge Cruel Death

作者:electroluxv2

Extend live of items dropped on death

收藏

介绍

中文介绍正在准备中,下面暂时显示原文。

This code is written in Java and is a mixin for modifying the behavior of Minecraft, a popular sandbox game. The mixin is specifically designed to modify the dropItem method in a Minecraft class, changing how items are handled when an entity drops them. Let’s break it down step by step:

Annotations

  • @Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At("RETURN")): This annotation specifies that the mixin should inject code into the dropItem method. The method parameter specifies the signature of the method, including its name (dropItem), its parameters (Lnet/minecraft/item/ItemStack;ZZ), and its return type (Lnet/minecraft/entity/ItemEntity). The at parameter specifies where in the method to inject the code. In this case, it’s injected at the RETURN point, meaning right before the method returns.

Method Signature

protected void onDropItem(final ItemStack stack, final boolean throwRandomly, final boolean retainOwnership, final CallbackInfoReturnable<ItemEntity> cir)
  • protected void onDropItem: This is the method being injected into the original dropItem method. It has the protected access modifier and returns void.
  • final ItemStack stack: The first parameter, stack, represents the item stack being dropped.
  • final boolean throwRandomly: The second parameter indicates whether the item should be thrown randomly.
  • final boolean retainOwnership: The third parameter indicates whether the entity should retain ownership of the item.
  • final CallbackInfoReturnable<ItemEntity> cir: This is a special parameter provided by mixin to get information about the method call, including its return value.

Method Body

  1. Check if the entity is alive:
   if (this.isAlive()) return;

If the entity that dropped the item is still alive, the method returns immediately and does nothing. This ensures that the rest of the code only executes if the entity is not alive.

  1. Get the dropped item entity:
   final var entity = (ItemEntityAccessor) cir.getReturnValue();
   if (entity == null) return;

The code retrieves the returned ItemEntity object from the original dropItem method using cir.getReturnValue(). If the returned entity is null, the method returns immediately and does nothing.

  1. Set the item age:
   entity.setItemAge(Short.MIN_VALUE + 1);

If the entity is valid, its age is set to Short.MIN_VALUE + 1. In Minecraft, setting an item’s age to Short.MIN_VALUE causes it to live indefinitely. By adding 1, it avoids the exact MIN_VALUE but still sets a very low age, effectively making the item last a very long time.

Summary

This mixin modifies the behavior of the dropItem method in Minecraft so that when an entity drops an item and the entity is not alive, the dropped item’s age is set to a very low value, making the item live almost indefinitely. This is done by injecting code at the point where the original method returns, ensuring the modification happens only after the item has been successfully created and returned.

常见问题

Dodge Cruel Death 支持哪些 Minecraft 版本?

Dodge Cruel Death 支持 Minecraft Java 版 1.21,可用的加载器:Fabric。下载时注意选择和你游戏版本一致的文件。

Dodge Cruel Death 怎么安装?

先用 PCL2 或 HMCL 启动器安装对应版本的 Fabric,再把下载的 .jar 文件放进游戏目录的 mods 文件夹,重新启动游戏即可。开启了版本隔离的,mods 文件夹在 versions/版本名 下面。运行环境:客户端 / 服务端。

评论

登录后评论和评分

electroluxv2 的其他作品

查看全部 →