From 4b48c050598768d3b5f0fa3070a6f5d90d8ba5b2 Mon Sep 17 00:00:00 2001 From: ZLOFENIX Date: Mon, 25 Nov 2013 20:44:21 +0400 Subject: [PATCH] O2 Fix --- src/cr0s/WarpDrive/SpaceEventHandler.java | 204 ++++++++++++---------- src/cr0s/WarpDrive/WarpDriveConfig.java | 5 +- 2 files changed, 110 insertions(+), 99 deletions(-) diff --git a/src/cr0s/WarpDrive/SpaceEventHandler.java b/src/cr0s/WarpDrive/SpaceEventHandler.java index 5e2ef2ec..b34ba19d 100644 --- a/src/cr0s/WarpDrive/SpaceEventHandler.java +++ b/src/cr0s/WarpDrive/SpaceEventHandler.java @@ -5,6 +5,7 @@ import java.util.HashMap; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraftforge.common.DimensionManager; @@ -17,115 +18,124 @@ import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; */ public class SpaceEventHandler { - private HashMap vacuumPlayers; + private HashMap vacuumPlayers; - public SpaceEventHandler() - { - vacuumPlayers = new HashMap(); - } + public SpaceEventHandler() + { + vacuumPlayers = new HashMap(); + } - @ForgeSubscribe - public void livingUpdate(LivingUpdateEvent event) - { - EntityLivingBase entity = event.entityLiving; + @ForgeSubscribe + public void livingUpdate(LivingUpdateEvent event) + { + EntityLivingBase entity = event.entityLiving; - if (Math.abs(MathHelper.floor_double(entity.posX)) > WarpDrive.WORLD_LIMIT_BLOCKS || Math.abs(MathHelper.floor_double(entity.posZ)) > WarpDrive.WORLD_LIMIT_BLOCKS) - { - if (entity instanceof EntityPlayerMP) - { - if (((EntityPlayerMP)entity).capabilities.isCreativeMode) - { - return; - } - } + if (Math.abs(MathHelper.floor_double(entity.posX)) > WarpDrive.WORLD_LIMIT_BLOCKS || Math.abs(MathHelper.floor_double(entity.posZ)) > WarpDrive.WORLD_LIMIT_BLOCKS) + { + if (entity instanceof EntityPlayerMP) + { + if (((EntityPlayerMP)entity).capabilities.isCreativeMode) + { + return; + } + } - entity.attackEntityFrom(DamageSource.outOfWorld, 9000); - return; - } + entity.attackEntityFrom(DamageSource.outOfWorld, 9000); + return; + } - // Обновление происходит в космическом или гипер пространстве - if (entity.worldObj.provider.dimensionId == WarpDrive.instance.spaceDimID || entity.worldObj.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID) - { - boolean inVacuum = isEntityInVacuum(entity); + // Обновление происходит в космическом или гипер пространстве + if (entity.worldObj.provider.dimensionId == WarpDrive.instance.spaceDimID || entity.worldObj.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID) + { + boolean inVacuum = isEntityInVacuum(entity); - // Damage entity if in vacuum without protection - if (inVacuum) - { - if (entity instanceof EntityPlayerMP) - { + // Damage entity if in vacuum without protection + if (inVacuum) + { + if (entity instanceof EntityPlayerMP) + { - if (((EntityPlayerMP)entity).getCurrentArmor(3) != null && WarpDriveConfig.i.SpaceHelmets.contains(((EntityPlayerMP)entity).getCurrentArmor(3).itemID)) - { - Integer airValue = vacuumPlayers.get(((EntityPlayerMP)entity).username); + if (((EntityPlayerMP)entity).getCurrentArmor(3) != null && WarpDriveConfig.i.SpaceHelmets.contains(((EntityPlayerMP)entity).getCurrentArmor(3).itemID)) + { + Integer airValue = vacuumPlayers.get(((EntityPlayerMP)entity).username); - if (airValue == null) - { - vacuumPlayers.put(((EntityPlayerMP)entity).username, 300); - airValue = 300; - } + if (airValue == null) + { + vacuumPlayers.put(((EntityPlayerMP)entity).username, 300); + airValue = 300; + } - if (airValue <= 0) - { - if (((EntityPlayerMP)entity).inventory.consumeInventoryItem(WarpDriveConfig.i.IC2_Air)) - { - setPlayerAirValue(entity, 300); - } - else - { - setPlayerAirValue(entity, 0); - entity.attackEntityFrom(DamageSource.drown, 1); - } - } - else - { - setPlayerAirValue(entity, airValue - 1); - } - } - else - { - entity.attackEntityFrom(DamageSource.drown, 1); - } + if (airValue <= 0) + { + if (consumeO2(((EntityPlayerMP)entity).inventory.mainInventory)) + { + setPlayerAirValue(entity, 300); + } + else + { + setPlayerAirValue(entity, 0); + entity.attackEntityFrom(DamageSource.drown, 1); + } + } + else + { + setPlayerAirValue(entity, airValue - 1); + } + } + else + { + entity.attackEntityFrom(DamageSource.drown, 1); + } - // Отправить назад на Землю - if (entity.posY < -10.0D) - { - ((EntityPlayerMP)entity).mcServer.getConfigurationManager().transferPlayerToDimension(((EntityPlayerMP) entity), 0, new SpaceTeleporter(DimensionManager.getWorld(WarpDrive.instance.spaceDimID), 0, MathHelper.floor_double(entity.posX), 250, MathHelper.floor_double(entity.posZ))); - ((EntityPlayerMP)entity).setFire(30); - ((EntityPlayerMP)entity).setPositionAndUpdate(entity.posX, 250D, entity.posZ); - } - } - else - { - entity.attackEntityFrom(DamageSource.drown, 1); - } - } - } - } + // Отправить назад на Землю + if (entity.posY < -10.0D) + { + ((EntityPlayerMP)entity).mcServer.getConfigurationManager().transferPlayerToDimension(((EntityPlayerMP) entity), 0, new SpaceTeleporter(DimensionManager.getWorld(WarpDrive.instance.spaceDimID), 0, MathHelper.floor_double(entity.posX), 250, MathHelper.floor_double(entity.posZ))); + ((EntityPlayerMP)entity).setFire(30); + ((EntityPlayerMP)entity).setPositionAndUpdate(entity.posX, 250D, entity.posZ); + } + } + else + { + entity.attackEntityFrom(DamageSource.drown, 1); + } + } + } + } - private void setPlayerAirValue(EntityLivingBase entity, Integer air) - { - vacuumPlayers.remove(((EntityPlayerMP)entity).username); - vacuumPlayers.put(((EntityPlayerMP)entity).username, air); - } + private void setPlayerAirValue(EntityLivingBase entity, Integer air) + { + vacuumPlayers.remove(((EntityPlayerMP)entity).username); + vacuumPlayers.put(((EntityPlayerMP)entity).username, air); + } - /** - * Проверка, находится ли Entity в открытом космосе - * @param e - * @return - */ - private boolean isEntityInVacuum(Entity e) - { - int x = MathHelper.floor_double(e.posX); - int y = MathHelper.floor_double(e.posY); - int z = MathHelper.floor_double(e.posZ); - int id1 = e.worldObj.getBlockId(x, y, z); - int id2 = e.worldObj.getBlockId(x, y + 1, z); + /** + * Проверка, находится ли Entity в открытом космосе + * @param e + * @return + */ + private boolean isEntityInVacuum(Entity e) + { + int x = MathHelper.floor_double(e.posX); + int y = MathHelper.floor_double(e.posY); + int z = MathHelper.floor_double(e.posZ); + int id1 = e.worldObj.getBlockId(x, y, z); + int id2 = e.worldObj.getBlockId(x, y + 1, z); - if (id1 == WarpDriveConfig.i.airID || id2 == WarpDriveConfig.i.airID) - { - return false; - } + if (id1 == WarpDriveConfig.i.airID || id2 == WarpDriveConfig.i.airID) + return false; + return true; + } - return true; - } + private boolean consumeO2(ItemStack[] i) + { + for (int j = 0; j < i.length; ++j) + if (i[j] != null && i[j].itemID == WarpDriveConfig.i.IC2_Air[0] && i[j].getItemDamage() == WarpDriveConfig.i.IC2_Air[1]) + { + if (--i[j].stackSize <= 0) + i[j] = null; + return true; + } + return false; + } } diff --git a/src/cr0s/WarpDrive/WarpDriveConfig.java b/src/cr0s/WarpDrive/WarpDriveConfig.java index a41dd6e4..051ac427 100644 --- a/src/cr0s/WarpDrive/WarpDriveConfig.java +++ b/src/cr0s/WarpDrive/WarpDriveConfig.java @@ -22,7 +22,8 @@ public class WarpDriveConfig // public boolean isGregLoaded = false, isAELoaded = false, isAdvSolPanelLoaded = false, isASLoaded = false, isICBMLoaded = false, isMFFSLoaded = false, isGraviSuiteLoaded = false; // - public int IC2_Air = 0, CC_Computer = 0, CC_peripheral = 0, CCT_Turtle = 0, CCT_Upgraded = 0, CCT_Advanced = 0, GT_Ores = 0, GT_Granite = 0, GT_Machine = 0, ASP = 0, AS_Turbine = 0, ICBM_Machine = 0, ICBM_Missile = 0, MFFS_Field = 0; + public int[] IC2_Air; + public int CC_Computer = 0, CC_peripheral = 0, CCT_Turtle = 0, CCT_Upgraded = 0, CCT_Advanced = 0, GT_Ores = 0, GT_Granite = 0, GT_Machine = 0, ASP = 0, AS_Turbine = 0, ICBM_Machine = 0, ICBM_Missile = 0, MFFS_Field = 0; public Set SpaceHelmets, Jetpacks, MinerOres; private Class AEBlocks; private Class AEMaterials; @@ -164,7 +165,7 @@ public class WarpDriveConfig SpaceHelmets.add(Items.getItem("quantumHelmet").itemID); Jetpacks.add(Items.getItem("jetpack").itemID); Jetpacks.add(Items.getItem("electricJetpack").itemID); - IC2_Air = Items.getItem("airCell").itemID; + IC2_Air = new int[] {Items.getItem("airCell").itemID, Items.getItem("airCell").getItemDamage()}; CommonWorldGenOres.add(new int[] {Items.getItem("uraniumOre").itemID, Items.getItem("uraniumOre").getItemDamage()}); CommonWorldGenOres.add(new int[] {Items.getItem("copperOre").itemID, Items.getItem("uraniumOre").getItemDamage()}); CommonWorldGenOres.add(new int[] {Items.getItem("tinOre").itemID, Items.getItem("uraniumOre").getItemDamage()});