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

feat: improvements to oxygen and suffocation #395

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"galacticraft:suffocation"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"galacticraft:suffocation"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"galacticraft:suffocation"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"values": [
"galacticraft:vine_poison",
"galacticraft:suffocation",
"galacticraft:sulfuric_acid"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"values": [
"galacticraft:vine_poison",
"galacticraft:suffocation",
"galacticraft:sulfuric_acid"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"galacticraft:vine_poison",
"galacticraft:sulfuric_acid"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"values": [
"galacticraft:vine_poison",
"galacticraft:suffocation",
"galacticraft:sulfuric_acid"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@

package dev.galacticraft.api.accessor;

import dev.galacticraft.api.item.OxygenGear;
import dev.galacticraft.api.item.OxygenMask;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.Container;
import net.minecraft.world.item.Item;

public interface GearInventoryProvider {
default Container galacticraft$getGearInv() {
Expand All @@ -42,6 +45,22 @@ public interface GearInventoryProvider {
throw new RuntimeException("This should be overridden by mixin!");
}

default boolean galacticraft$hasMaskAndGear() {
boolean mask = false;
boolean gear = false;
for (int i = 0; i < this.galacticraft$getAccessories().getContainerSize(); i++) {
Item item = this.galacticraft$getAccessories().getItem(i).getItem();
if (!mask && item instanceof OxygenMask) {
mask = true;
if (gear) break;
} else if (!gear && item instanceof OxygenGear) {
gear = true;
if (mask) break;
}
}
return mask && gear;
}

default void galacticraft$writeGearToNbt(CompoundTag tag) {
throw new RuntimeException("This should be overridden by mixin!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import dev.galacticraft.api.item.OxygenGear;
import dev.galacticraft.api.item.OxygenMask;
import dev.galacticraft.impl.internal.fabric.GalacticraftAPI;
import dev.galacticraft.mod.content.entity.damage.GCDamageTypes;
import dev.galacticraft.mod.Galacticraft;
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
Expand All @@ -37,9 +38,13 @@
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.tags.FluidTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.Container;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
Expand Down Expand Up @@ -67,12 +72,36 @@ public LivingEntityMixin(EntityType<?> type, Level world) {
}

@Shadow protected abstract int increaseAirSupply(int air);
@Shadow protected abstract int decreaseAirSupply(int air);

@Inject(method = "baseTick", at = @At(value = "HEAD"))
private void galacticraft_oxygenCheck(CallbackInfo ci) {
LivingEntity entity = ((LivingEntity) (Object) this);
if (entity.isAlive()) {
if (!entity.level().isBreathable(entity.blockPosition().relative(Direction.UP, (int) Math.floor(entity.getEyeHeight(entity.getPose()))))) {
if (!entity.isEyeInFluid(FluidTags.WATER) && (!(entity instanceof Player) || !((Player)entity).getAbilities().invulnerable)) {
entity.setAirSupply(this.decreaseAirSupply(entity.getAirSupply()));
if (entity.getAirSupply() == -20) {
entity.setAirSupply(0);
entity.hurt(new DamageSource(entity.level().registryAccess()
.registryOrThrow(Registries.DAMAGE_TYPE)
.getHolderOrThrow(GCDamageTypes.SUFFOCATION)), 2.0f);
}
}
}
}
}

@Redirect(method = "baseTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;isEyeInFluid(Lnet/minecraft/tags/TagKey;)Z", ordinal = 0))
private boolean galacticraft_testForBreathability(LivingEntity entity, TagKey<Fluid> tag) {
return entity.isEyeInFluid(tag) || !entity.level().isBreathable(entity.blockPosition().relative(Direction.UP, (int) Math.floor(this.getEyeHeight(entity.getPose()))));
}

@Redirect(method = "baseTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;canBreatheUnderwater()Z"))
private boolean galacticraft_suffocationDamage(LivingEntity entity) {
return entity.canBreatheUnderwater() || !entity.isEyeInFluid(FluidTags.WATER);
}

@Inject(method = "tick", at = @At(value = "RETURN"))
private void tickAccessories(CallbackInfo ci) {
LivingEntity thisEntity = ((LivingEntity) (Object) this);
Expand All @@ -91,20 +120,7 @@ private void galacticraft_modifyAirLevel(int air, CallbackInfoReturnable<Integer
ci.setReturnValue(this.increaseAirSupply(air));
}

boolean mask = false;
boolean gear = false;
for (int i = 0; i < this.galacticraft$getAccessories().getContainerSize(); i++) {
Item item = this.galacticraft$getAccessories().getItem(i).getItem();
if (!mask && item instanceof OxygenMask) {
mask = true;
if (gear) break;
} else if (!gear && item instanceof OxygenGear) {
gear = true;
if (mask) break;
}
}

if (mask && gear) {
if (this.galacticraft$hasMaskAndGear()) {
InventoryStorage tankInv = InventoryStorage.of(galacticraft$getOxygenTanks(), null);
for (int i = 0; i < tankInv.getSlotCount(); i++) {
Storage<FluidVariant> storage = ContainerItemContext.ofSingleSlot(tankInv.getSlot(i)).find(FluidStorage.ITEM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,23 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.core.Holder;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.Container;

public class OxygenOverlay {
public static void onHudRender(GuiGraphics graphics, DeltaTracker delta) {
Minecraft mc = Minecraft.getInstance();
if (mc.level != null && mc.player != null && !mc.player.isSpectator()) {
if (!mc.options.hideGui && mc.level != null && mc.player != null && !mc.player.isSpectator()) {
Holder<CelestialBody<?, ?>> body = mc.level.galacticraft$getCelestialBody();
if (body != null && !body.value().atmosphere().breathable()) {
boolean nonBreathable = (body != null) && !body.value().atmosphere().breathable();
if (mc.player.galacticraft$hasMaskAndGear() || nonBreathable) {
Container inv = mc.player.galacticraft$getOxygenTanks();
final int outline = 0x99FFFFFF;
final int y = 4;
for (int i = 0; i < inv.getContainerSize(); i++) {
Storage<FluidVariant> storage = ContainerItemContext.withConstant(inv.getItem(i)).find(FluidStorage.ITEM);
int x = mc.getWindow().getGuiScaledWidth() - ((Constant.TextureCoordinate.OVERLAY_WIDTH + y) * (i + 1));

int outline = 0x99FFFFFF;
final int n = inv.getContainerSize();
for (int i = n; i > 0; i--) {
Storage<FluidVariant> storage = ContainerItemContext.withConstant(inv.getItem(n - i)).find(FluidStorage.ITEM);
int x = mc.getWindow().getGuiScaledWidth() - ((Constant.TextureCoordinate.OVERLAY_WIDTH + y) * i);

long amount = 0;
long capacity = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void onInitializeDataGenerator(@NotNull FabricDataGenerator generator) {
pack.addProvider(GCBannerTagProvider::new);
pack.addProvider(GCBiomeTagProvider::new);
pack.addProvider(GCBlockTagProvider::new);
pack.addProvider(GCDamageTypeTagProvider::new);
pack.addProvider(GCDimensionTagProvider::new);
pack.addProvider(GCEntityTypeTagProvider::new);
pack.addProvider(GCFluidTagProvider::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2019-2024 Team Galacticraft
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package dev.galacticraft.mod.data.tag;

import dev.galacticraft.mod.content.entity.damage.GCDamageTypes;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.tags.DamageTypeTags;
import net.minecraft.world.damagesource.DamageType;

import java.util.concurrent.CompletableFuture;

public class GCDamageTypeTagProvider extends FabricTagProvider<DamageType> {
public GCDamageTypeTagProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> completableFuture) {
super(output, Registries.DAMAGE_TYPE, completableFuture);
}

@Override
protected void addTags(HolderLookup.Provider arg) {
this.tag(DamageTypeTags.BYPASSES_ARMOR)
.add(GCDamageTypes.SUFFOCATION);

this.tag(DamageTypeTags.BYPASSES_WOLF_ARMOR)
.add(GCDamageTypes.SUFFOCATION);

this.tag(DamageTypeTags.IS_DROWNING)
.add(GCDamageTypes.SUFFOCATION);

this.tag(DamageTypeTags.NO_IMPACT)
.add(GCDamageTypes.VINE_POISON)
.add(GCDamageTypes.SUFFOCATION)
.add(GCDamageTypes.SULFURIC_ACID);

this.tag(DamageTypeTags.NO_KNOCKBACK)
.add(GCDamageTypes.VINE_POISON)
.add(GCDamageTypes.SUFFOCATION)
.add(GCDamageTypes.SULFURIC_ACID);

this.tag(DamageTypeTags.PANIC_ENVIRONMENTAL_CAUSES)
.add(GCDamageTypes.VINE_POISON)
.add(GCDamageTypes.SULFURIC_ACID);

this.tag(DamageTypeTags.WITHER_IMMUNE_TO)
.add(GCDamageTypes.VINE_POISON)
.add(GCDamageTypes.SUFFOCATION)
.add(GCDamageTypes.SULFURIC_ACID);
}
}
4 changes: 2 additions & 2 deletions src/main/java/dev/galacticraft/mod/util/DrawableUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public static void drawOxygenBuffer(PoseStack matrices, int x, int y, double sca
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShaderTexture(0, Constant.ScreenTexture.OVERLAY);
drawProgressTexture(matrices, x, y, 0, Constant.TextureCoordinate.OXYGEN_DARK_X, Constant.TextureCoordinate.OXYGEN_DARK_Y, Constant.TextureCoordinate.OVERLAY_WIDTH, Constant.TextureCoordinate.OVERLAY_HEIGHT, 256, 256);
drawProgressTexture(matrices, x, (int) (y + Constant.TextureCoordinate.OVERLAY_HEIGHT - (Constant.TextureCoordinate.OVERLAY_HEIGHT * scale)), 0, Constant.TextureCoordinate.OXYGEN_LIGHT_X, Constant.TextureCoordinate.OXYGEN_LIGHT_Y, Constant.TextureCoordinate.OVERLAY_WIDTH, (float) (Constant.TextureCoordinate.OVERLAY_HEIGHT * scale), 256, 256);
drawProgressTexture(matrices, x, y, 0, Constant.TextureCoordinate.OXYGEN_LIGHT_X, Constant.TextureCoordinate.OXYGEN_LIGHT_Y, Constant.TextureCoordinate.OVERLAY_WIDTH, Constant.TextureCoordinate.OVERLAY_HEIGHT, 256, 256);
drawProgressTexture(matrices, x, y, 0, Constant.TextureCoordinate.OXYGEN_DARK_X, Constant.TextureCoordinate.OXYGEN_DARK_Y, Constant.TextureCoordinate.OVERLAY_WIDTH, (float) (Constant.TextureCoordinate.OVERLAY_HEIGHT * (1 - scale)), 256, 256);
}

public static boolean isWithin(double mouseX, double mouseY, int x, int y, int width, int height) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.