Skip to content

Commit

Permalink
feat: show oxygen overlay whenever player is wearing both an oxygen m…
Browse files Browse the repository at this point in the history
…ask and oxygen gear
  • Loading branch information
Roelymole committed Jan 9, 2025
1 parent 423b65d commit 07d8db1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
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 @@ -120,20 +120,20 @@ 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) {
// 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 (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,23 +35,24 @@
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()) {
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;
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);

int outline = 0x99FFFFFF;

long amount = 0;
long capacity = 1;

Expand Down

0 comments on commit 07d8db1

Please sign in to comment.