Androids no longer get hunger from "eating" raw food

This commit is contained in:
DBotThePony 2023-03-26 15:35:48 +07:00
parent 7869d686f7
commit faf43657fc
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 45 additions and 0 deletions

View File

@ -12,7 +12,10 @@ import net.minecraft.server.level.ServerPlayer
import net.minecraft.tags.TagKey import net.minecraft.tags.TagKey
import net.minecraft.world.Difficulty import net.minecraft.world.Difficulty
import net.minecraft.world.effect.MobEffect import net.minecraft.world.effect.MobEffect
import net.minecraft.world.effect.MobEffectInstance
import net.minecraft.world.effect.MobEffects
import net.minecraft.world.entity.Entity import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.MobSpawnType import net.minecraft.world.entity.MobSpawnType
import net.minecraft.world.entity.boss.wither.WitherBoss import net.minecraft.world.entity.boss.wither.WitherBoss
import net.minecraft.world.entity.monster.Phantom import net.minecraft.world.entity.monster.Phantom
@ -1259,6 +1262,26 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
} }
} }
/**
* hooked into LivingEntity through coremod script
*/
@JvmStatic
fun addEatEffectHook(iterator: Iterator<com.mojang.datafixers.util.Pair<MobEffectInstance, Float>>, entity: LivingEntity): Iterator<com.mojang.datafixers.util.Pair<MobEffectInstance, Float>> {
if (entity !is Player) {
return iterator
}
val mattery = entity.matteryPlayer ?: return iterator
if (mattery.isAndroid) {
return iterator.filter {
it.first.effect != MobEffects.HUNGER
}
}
return iterator
}
/** /**
* this method is hooked through coremod transformer * this method is hooked through coremod transformer
*/ */

View File

@ -599,6 +599,28 @@ function initializeCoreMod() {
return node return node
}), }),
'LivingEntity#addEatEffect patch for androids': method('net.minecraft.world.entity.LivingEntity.m_21063_(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/LivingEntity;)V', function(node) {
for (var i = 0; i < node.instructions.size(); i++) {
var instr = node.instructions.get(i)
if (instr.getOpcode() == opcodesRemapped.invokeinterface && instr.name == "iterator") {
putInstructions(node, node.instructions.get(i), [
new VarInsnNode(opcodesRemapped.aload, 0),
new MethodInsnNode(
opcodesRemapped.invokestatic,
'ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability',
'addEatEffectHook',
'(Ljava/util/Iterator;Lnet/minecraft/world/entity/LivingEntity;)Ljava/util/Iterator;'
),
])
return node
}
}
return node
}),
'Inventory#dropAll': injectAtTail( 'Inventory#dropAll': injectAtTail(
'net.minecraft.world.entity.player.Inventory.m_36071_()V', 'net.minecraft.world.entity.player.Inventory.m_36071_()V',
[ [