Skip to content

Commit

Permalink
Make breath meter deplete in space
Browse files Browse the repository at this point in the history
  • Loading branch information
gdavid04 committed Feb 19, 2024
1 parent 885ef87 commit 617d258
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ A WIP space mod for Fabric 1.20.1 with 6DOF movement.
- [x] look around
- [ ] fix third person front view rotation controls
- [x] controls for roll
- [ ] camera relative movement (hook Entity.movementInputToVelocity)
- [x] camera relative movement
- [ ] sync orientation
- [x] animate transition back to upright (roll)

## Air
- [ ] make breath meter deplete in space
- [x] make breath meter deplete in space
- [ ] oxygen tanks
- [ ] pressurization system
- [ ] airlocks
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/gdavid/sixdoftest/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import gdavid.sixdoftest.SpaceManager;
import net.minecraft.entity.LivingEntity;
import net.minecraft.registry.tag.FluidTags;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(LivingEntity.class)
Expand All @@ -21,5 +23,21 @@ private void noFallDamageIn6DOFSpace(float fallDistance, float damageMultiplier,
if (!SpaceManager.isIn6dof(self())) return;
callback.setReturnValue(0);
}

@Inject(method = "getNextAirOnLand", at = @At("HEAD"), cancellable = true)
private void noAirInSpace(int air, CallbackInfoReturnable<Integer> callback) {
if (!SpaceManager.isIn6dof(self())) return;
callback.setReturnValue(air); // Prevent refilling air
}

@Inject(method = "baseTick", at = @At("HEAD"))
private void depleteAirInSpace(CallbackInfo callback) {
if (!SpaceManager.isIn6dof(self()) || self().isSubmergedIn(FluidTags.WATER)) return;
self().setAir(self().getAir() - 1);
if (self().getAir() == -20) {
self().setAir(0);
self().damage(self().getDamageSources().drown(), 2.0F);
}
}

}

0 comments on commit 617d258

Please sign in to comment.