Improved breathing alarm when inside air fields

This commit is contained in:
LemADEC 2017-07-29 19:06:41 +02:00
parent 1c8f66f494
commit 726ce4f860
2 changed files with 29 additions and 10 deletions

View file

@ -42,17 +42,20 @@ public class BreathingManager {
private static final HashMap<UUID, Integer> player_airTank = new HashMap<>();
public static boolean hasAirBlock(final EntityLivingBase entityLivingBase, final int x, final int y, final int z) {
Block block;
for (final VectorI vOffset : vAirOffsets) {
final VectorI vPosition = new VectorI(x + vOffset.x, y + vOffset.y, z + vOffset.z);
block = entityLivingBase.worldObj.getBlock(vPosition.x, vPosition.y, vPosition.z);
if (block == WarpDrive.blockAir || block == WarpDrive.blockAirSource || block == WarpDrive.blockAirFlow) {
final Block block = entityLivingBase.worldObj.getBlock(vPosition.x, vPosition.y, vPosition.z);
if (isAirBlock(block)) {
return true;
}
}
return false;
}
public static boolean isAirBlock(final Block block) {
return block == WarpDrive.blockAir || block == WarpDrive.blockAirSource || block == WarpDrive.blockAirFlow;
}
public static boolean onLivingJoinEvent(final EntityLivingBase entityLivingBase, final int x, final int y, final int z) {
// skip living entities who don't need air
final String idEntity = EntityList.getEntityString(entityLivingBase);

View file

@ -4,10 +4,12 @@ import cr0s.warpdrive.BreathingManager;
import cr0s.warpdrive.data.CelestialObjectManager;
import cr0s.warpdrive.data.CelestialObject;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@ -20,6 +22,8 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
@SideOnly(Side.CLIENT)
public class RenderOverlayAir {
private static final int WARNING_ON_JOIN_TICKS = 20 * 20;
private static Minecraft minecraft = Minecraft.getMinecraft();
private static float ratioPreviousAir = 1.0F;
@ -32,6 +36,7 @@ public class RenderOverlayAir {
return;
}
final int x = MathHelper.floor_double(entityPlayer.posX);
final int y = MathHelper.floor_double(entityPlayer.posY);
final int z = MathHelper.floor_double(entityPlayer.posZ);
// get celestial object
@ -41,7 +46,11 @@ public class RenderOverlayAir {
}
// get air stats
// final boolean hasAirBlock = BreathingManager.hasAirBlock(entityPlayer, x, y, z);
final boolean hasVoidNearby = isVoid(entityPlayer.worldObj, x, y, z)
|| isVoid(entityPlayer.worldObj, x - 2, y, z)
|| isVoid(entityPlayer.worldObj, x + 2, y, z)
|| isVoid(entityPlayer.worldObj, x, y, z - 2)
|| isVoid(entityPlayer.worldObj, x, y, z + 2);
final boolean hasValidSetup = BreathingManager.hasValidSetup(entityPlayer);
final float ratioAirReserve = BreathingManager.getAirReserveRatio(entityPlayer);
@ -51,12 +60,14 @@ public class RenderOverlayAir {
// show splash message
int alpha = 255;
if (!hasValidSetup) {
alpha = RenderCommons.drawSplashAlarm(width, height, "warpdrive.breathing.alarm", "warpdrive.breathing.invalid_setup");
} else if (ratioAirReserve <= 0.0F) {
alpha = RenderCommons.drawSplashAlarm(width, height, "warpdrive.breathing.alarm", "warpdrive.breathing.no_air");
} else if (ratioAirReserve < 0.15F) {
alpha = RenderCommons.drawSplashAlarm(width, height, "warpdrive.breathing.alarm", "warpdrive.breathing.low_reserve");
if (hasVoidNearby || entityPlayer.ticksExisted < WARNING_ON_JOIN_TICKS) {
if (!hasValidSetup) {
alpha = RenderCommons.drawSplashAlarm(width, height, "warpdrive.breathing.alarm", "warpdrive.breathing.invalid_setup");
} else if (ratioAirReserve <= 0.0F) {
alpha = RenderCommons.drawSplashAlarm(width, height, "warpdrive.breathing.alarm", "warpdrive.breathing.no_air");
} else if (ratioAirReserve < 0.15F) {
alpha = RenderCommons.drawSplashAlarm(width, height, "warpdrive.breathing.alarm", "warpdrive.breathing.low_reserve");
}
}
// restore texture
@ -96,6 +107,11 @@ public class RenderOverlayAir {
GL11.glDisable(GL11.GL_BLEND);
}
private boolean isVoid(final IBlockAccess blockAccess, final int x, final int y, final int z) {
final Block block = blockAccess.getBlock(x, y, z);
return block.isAir(blockAccess, x, y, z) && !BreathingManager.isAirBlock(block);
}
@SubscribeEvent
public void onRender(RenderGameOverlayEvent.Pre event) {
if (event.type == ElementType.AIR) {