Disable eating in <=1.14.4 whilst in creative (#578)

* Disable eating whilst in creative <=1.14.4

* Requested Changes
This commit is contained in:
lowercasebtw 2024-10-10 18:14:34 -04:00 committed by GitHub
parent 5183745d02
commit 7394c86e2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,6 +31,7 @@ import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.HungerManager;
import net.minecraft.entity.player.PlayerAbilities;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
@ -65,6 +66,9 @@ public abstract class MixinPlayerEntity extends LivingEntity {
@Final
PlayerInventory inventory;
@Shadow
protected HungerManager hungerManager;
@Unique
private static final EntityDimensions viaFabricPlus$sneaking_dimensions_v1_13_2 = EntityDimensions.changing(0.6F, 1.65F).withEyeHeight(1.54F).
withAttachments(EntityAttachments.builder().add(EntityAttachmentType.VEHICLE, PlayerEntity.VEHICLE_ATTACHMENT_POS));
@ -121,6 +125,13 @@ public abstract class MixinPlayerEntity extends LivingEntity {
return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_15_2) && instance.hasStatusEffect(registryEntry);
}
@Inject(method = "canConsume", at = @At("HEAD"), cancellable = true)
private void preventEatingFoodInCreative(boolean ignoreHunger, CallbackInfoReturnable<Boolean> cir) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_14_4)) {
cir.setReturnValue(!this.abilities.invulnerable && (ignoreHunger || this.hungerManager.isNotFull()));
}
}
@Inject(method = "checkFallFlying", at = @At("HEAD"), cancellable = true)
private void replaceFallFlyingCondition(CallbackInfoReturnable<Boolean> cir) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_14_4)) {