Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug with cancelAirIncrement #597

Open
wants to merge 1 commit into
base: arch-1.20.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions common/src/main/java/draylar/identity/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,6 @@ private void onDeath(DamageSource source, CallbackInfo ci) {
}
}

@Redirect(
method = "baseTick",
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;setAir(I)V", ordinal = 2)
)
private void cancelAirIncrement(LivingEntity livingEntity, int air) {
// Aquatic creatures should not regenerate breath on land
if ((Object) this instanceof PlayerEntity player) {
LivingEntity identity = PlayerIdentity.getIdentity(player);

if (identity != null) {
if (Identity.isAquatic(identity)) {
return;
}
}
}

this.setAir(this.getNextAirOnLand(this.getAir()));
}

@Redirect(
method = "travel",
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;hasStatusEffect(Lnet/minecraft/entity/effect/StatusEffect;)Z", ordinal = 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package draylar.identity.mixin;

import draylar.identity.Identity;
import draylar.identity.api.PlayerIdentity;
import net.minecraft.entity.*;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin extends Entity {

@Shadow
protected abstract int getNextAirOnLand(int air);

protected LivingEntityMixin(EntityType<?> type, World world) {
super(type, world);
}

@Redirect(
method = "baseTick",
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;setAir(I)V", ordinal = 2)
)
private void cancelAirIncrement(LivingEntity livingEntity, int air) {
// Aquatic creatures should not regenerate breath on land
if ((Object) this instanceof PlayerEntity player) {
LivingEntity identity = PlayerIdentity.getIdentity(player);

if (identity != null) {
if (Identity.isAquatic(identity)) {
return;
}
}
}

this.setAir(this.getNextAirOnLand(this.getAir()));
}
}
1 change: 1 addition & 0 deletions fabric/src/main/resources/identity-fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"package": "draylar.identity.fabric.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
"LivingEntityMixin",
"WitherEntityMixin"
],
"client": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package tocraft.walkers.forge;

import net.minecraft.entity.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.event.entity.living.LivingBreatheEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import draylar.identity.Identity;
import draylar.identity.api.PlayerIdentity;

@Mod.EventBusSubscriber(modid = "identity")
public class WalkersForgeEventHandler {

@SubscribeEvent
public static void livingBreath(LivingBreatheEvent event) {
if (event.getEntity() instanceof PlayerEntity) {
LivingEntity identity = PlayerIdentity.getIdentity((PlayerEntity) event.getEntity());

if (identity != null) {
if (Identity.isAquatic(identity)) {
event.setCanBreathe(false);

}
}
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ maven_group=dev.draylar
fabric_loader_version=0.14.21
fabric_api_version=0.84.0+1.20.1
yarn_mappings=1.20.1+build.8
forge_version=47.0.43
forge_version=47.1.43

# Dependency Versions
architectury_version=9.0.8