use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class GCPlayerHandler method checkOxygen.
protected void checkOxygen(EntityPlayerMP player, GCPlayerStats stats) {
if ((player.dimension == 0 || player.world.provider instanceof IGalacticraftWorldProvider) && (!(player.dimension == 0 || ((IGalacticraftWorldProvider) player.world.provider).hasBreathableAtmosphere()) || player.posY > GCPlayerHandler.OXYGENHEIGHTLIMIT) && !player.capabilities.isCreativeMode && !(player.getRidingEntity() instanceof EntityLanderBase) && !(player.getRidingEntity() instanceof EntityAutoRocket) && !(player.getRidingEntity() instanceof EntityCelestialFake) && !CompatibilityManager.isAndroid(player)) {
final ItemStack tankInSlot = stats.getExtendedInventory().getStackInSlot(2);
final ItemStack tankInSlot2 = stats.getExtendedInventory().getStackInSlot(3);
final int drainSpacing = OxygenUtil.getDrainSpacing(tankInSlot, tankInSlot2);
if (tankInSlot.isEmpty()) {
stats.setAirRemaining(0);
} else {
stats.setAirRemaining(tankInSlot.getMaxDamage() - tankInSlot.getItemDamage());
}
if (tankInSlot2.isEmpty()) {
stats.setAirRemaining2(0);
} else {
stats.setAirRemaining2(tankInSlot2.getMaxDamage() - tankInSlot2.getItemDamage());
}
if (drainSpacing > 0) {
if ((player.ticksExisted - 1) % drainSpacing == 0 && !OxygenUtil.isAABBInBreathableAirBlock(player) && !stats.isUsingPlanetSelectionGui()) {
int toTake = 1;
// Take 1 oxygen from Tank 1
if (stats.getAirRemaining() > 0) {
tankInSlot.damageItem(1, player);
stats.setAirRemaining(stats.getAirRemaining() - 1);
toTake = 0;
}
// Alternatively, take 1 oxygen from Tank 2
if (toTake > 0 && stats.getAirRemaining2() > 0) {
tankInSlot2.damageItem(1, player);
stats.setAirRemaining2(stats.getAirRemaining2() - 1);
toTake = 0;
}
}
} else {
if ((player.ticksExisted - 1) % 60 == 0) {
if (OxygenUtil.isAABBInBreathableAirBlock(player)) {
if (stats.getAirRemaining() < 90 && !tankInSlot.isEmpty()) {
stats.setAirRemaining(Math.min(stats.getAirRemaining() + 1, tankInSlot.getMaxDamage() - tankInSlot.getItemDamage()));
}
if (stats.getAirRemaining2() < 90 && !tankInSlot2.isEmpty()) {
stats.setAirRemaining2(Math.min(stats.getAirRemaining2() + 1, tankInSlot2.getMaxDamage() - tankInSlot2.getItemDamage()));
}
} else {
if (stats.getAirRemaining() > 0) {
stats.setAirRemaining(stats.getAirRemaining() - 1);
}
if (stats.getAirRemaining2() > 0) {
stats.setAirRemaining2(stats.getAirRemaining2() - 1);
}
}
}
}
final boolean airEmpty = stats.getAirRemaining() <= 0 && stats.getAirRemaining2() <= 0;
if (player.isOnLadder()) {
stats.setOxygenSetupValid(stats.isLastOxygenSetupValid());
} else {
stats.setOxygenSetupValid(!((!OxygenUtil.hasValidOxygenSetup(player) || airEmpty) && !OxygenUtil.isAABBInBreathableAirBlock(player)));
}
if (!player.world.isRemote && player.isEntityAlive()) {
if (!stats.isOxygenSetupValid()) {
GCCoreOxygenSuffocationEvent suffocationEvent = new GCCoreOxygenSuffocationEvent.Pre(player);
MinecraftForge.EVENT_BUS.post(suffocationEvent);
if (!suffocationEvent.isCanceled()) {
if (stats.getDamageCounter() == 0) {
stats.setDamageCounter(ConfigManagerCore.suffocationCooldown);
player.attackEntityFrom(DamageSourceGC.oxygenSuffocation, ConfigManagerCore.suffocationDamage * (2 + stats.getIncrementalDamage()) / 2);
if (ConfigManagerCore.hardMode)
stats.setIncrementalDamage(stats.getIncrementalDamage() + 1);
GCCoreOxygenSuffocationEvent suffocationEventPost = new GCCoreOxygenSuffocationEvent.Post(player);
MinecraftForge.EVENT_BUS.post(suffocationEventPost);
}
} else
stats.setOxygenSetupValid(true);
} else
stats.setIncrementalDamage(0);
}
} else if ((player.ticksExisted - 1) % 20 == 0 && !player.capabilities.isCreativeMode && stats.getAirRemaining() < 90) {
stats.setAirRemaining(stats.getAirRemaining() + 1);
stats.setAirRemaining2(stats.getAirRemaining2() + 1);
} else if (player.capabilities.isCreativeMode) {
stats.setAirRemaining(90);
stats.setAirRemaining2(90);
} else {
stats.setOxygenSetupValid(true);
}
}
use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class GCPlayerHandler method onPlayerCloned.
// @SubscribeEvent
// public void onPlayerLogout(PlayerLoggedOutEvent event)
// {
// if (event.player instanceof EntityPlayerMP)
// {
// this.onPlayerLogout((EntityPlayerMP) event.player);
// }
// }
//
// @SubscribeEvent
// public void onPlayerRespawn(PlayerRespawnEvent event)
// {
// if (event.player instanceof EntityPlayerMP)
// {
// this.onPlayerRespawn((EntityPlayerMP) event.player);
// }
// }
@SubscribeEvent
public void onPlayerCloned(PlayerEvent.Clone event) {
GCPlayerStats oldStats = GCPlayerStats.get(event.getOriginal());
GCPlayerStats newStats = GCPlayerStats.get(event.getEntityPlayer());
newStats.copyFrom(oldStats, !event.isWasDeath() || event.getOriginal().world.getGameRules().getBoolean("keepInventory"));
if (event.getOriginal() instanceof EntityPlayerMP && event.getEntityPlayer() instanceof EntityPlayerMP) {
TileEntityTelemetry.updateLinkedPlayer((EntityPlayerMP) event.getOriginal(), (EntityPlayerMP) event.getEntityPlayer());
}
if (event.isWasDeath() && event.getOriginal() instanceof EntityPlayerMP) {
UUID uu = event.getOriginal().getPersistentID();
if (event.getOriginal().world.provider instanceof IGalacticraftWorldProvider) {
Integer timeA = deathTimes.get(uu);
int bb = ((EntityPlayerMP) event.getOriginal()).mcServer.getTickCounter();
if (timeA != null && (bb - timeA) < 1500) {
String msg = EnumColor.YELLOW + GCCoreUtil.translate("commands.gchouston.help.1") + " " + EnumColor.WHITE + GCCoreUtil.translate("commands.gchouston.help.2");
event.getOriginal().sendMessage(new TextComponentString(msg));
}
deathTimes.put(uu, bb);
} else {
deathTimes.remove(uu);
}
}
}
use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class GCPlayerHandler method checkShield.
protected void checkShield(EntityPlayerMP playerMP, GCPlayerStats playerStats) {
if (playerMP.ticksExisted % 20 == 0 && playerMP.world.provider instanceof IGalacticraftWorldProvider) {
if (((IGalacticraftWorldProvider) playerMP.world.provider).shouldCorrodeArmor()) {
ItemStack shieldController = playerStats.getExtendedInventory().getStackInSlot(10);
boolean valid = false;
if (!shieldController.isEmpty()) {
int gearID = GalacticraftRegistry.findMatchingGearID(shieldController, EnumExtendedInventorySlot.SHIELD_CONTROLLER);
if (gearID != -1) {
valid = true;
}
}
if (!valid) {
for (ItemStack armor : playerMP.getArmorInventoryList()) {
if (!armor.isEmpty() && armor.getItem() instanceof ItemArmor && !(armor.getItem() instanceof IArmorCorrosionResistant)) {
armor.damageItem(1, playerMP);
}
}
}
}
}
}
use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class EventHandlerGC method overrideSkyColor.
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void overrideSkyColor(EntityViewRenderEvent.FogColors event) {
// Disable any night vision effects on the sky, if the planet has no atmosphere
if (event.getEntity() instanceof EntityLivingBase && ((EntityLivingBase) event.getEntity()).isPotionActive(MobEffects.NIGHT_VISION)) {
WorldClient worldclient = Minecraft.getMinecraft().world;
if (worldclient.provider instanceof IGalacticraftWorldProvider && ((IGalacticraftWorldProvider) worldclient.provider).hasNoAtmosphere() && event.getState().getMaterial() == Material.AIR && !((IGalacticraftWorldProvider) worldclient.provider).hasBreathableAtmosphere()) {
Vec3d vec = worldclient.getFogColor(1.0F);
event.setRed((float) vec.x);
event.setGreen((float) vec.y);
event.setBlue((float) vec.z);
return;
}
if (worldclient.provider.getSkyRenderer() instanceof SkyProviderOverworld && event.getEntity().posY > Constants.OVERWORLD_SKYPROVIDER_STARTHEIGHT) {
Vec3d vec = TransformerHooks.getFogColorHook(event.getEntity().world);
event.setRed((float) vec.x);
event.setGreen((float) vec.y);
event.setBlue((float) vec.z);
return;
}
}
}
use of micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider in project Galacticraft by micdoodle8.
the class EventHandlerGC method onEntityFall.
@SubscribeEvent
public void onEntityFall(LivingFallEvent event) {
if (event.getEntityLiving() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.getEntityLiving();
if (player.getRidingEntity() instanceof EntityAutoRocket || player.getRidingEntity() instanceof EntityLanderBase) {
event.setDistance(0.0F);
event.setCanceled(true);
return;
}
}
if (event.getEntityLiving().world.provider instanceof IGalacticraftWorldProvider) {
event.setDistance(event.getDistance() * ((IGalacticraftWorldProvider) event.getEntityLiving().world.provider).getFallDamageModifier());
}
}
Aggregations