HomeJavaModsDodge Cruel Death
Dodge Cruel 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

Method Signature

protected void onDropItem(final ItemStack stack, final boolean throwRandomly, final boolean retainOwnership, final CallbackInfoReturnable<ItemEntity> cir)

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.

  2. 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.

  3. 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.

Quick facts

Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.

Verified by MCModsHub

These come from our own check of the pack file, not from the source page.

Explore more