Skip to content

Commit 3214311

Browse files
committed
Slightly optimize entity capability retrieval
1 parent d0fd498 commit 3214311

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.embeddedt.modernfix.forge.mixin.perf.forge_cap_retrieval;
2+
3+
import net.minecraft.core.Direction;
4+
import net.minecraft.world.entity.LivingEntity;
5+
import net.minecraftforge.common.capabilities.Capability;
6+
import net.minecraftforge.items.CapabilityItemHandler;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Redirect;
10+
11+
import javax.annotation.Nullable;
12+
13+
@Mixin(LivingEntity.class)
14+
public class LivingEntityMixin {
15+
/**
16+
* @author embeddedt (issue noted by XFactHD)
17+
* @reason check capability equality before checking that entity is alive, the latter requires a lot more
18+
* indirection
19+
*/
20+
@Redirect(method = "getCapability", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;isAlive()Z"))
21+
private <T> boolean checkAliveAfterCap(LivingEntity entity, Capability<T> capability, @Nullable Direction facing) {
22+
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && entity.isAlive();
23+
}
24+
}

0 commit comments

Comments
 (0)