This commit is contained in:
ZLOFENIX 2013-11-25 20:44:21 +04:00
parent 971514d597
commit 4b48c05059
2 changed files with 110 additions and 99 deletions

View file

@ -5,6 +5,7 @@ import java.util.HashMap;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource; import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.DimensionManager;
@ -17,115 +18,124 @@ import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
*/ */
public class SpaceEventHandler public class SpaceEventHandler
{ {
private HashMap<String, Integer> vacuumPlayers; private HashMap<String, Integer> vacuumPlayers;
public SpaceEventHandler() public SpaceEventHandler()
{ {
vacuumPlayers = new HashMap<String, Integer>(); vacuumPlayers = new HashMap<String, Integer>();
} }
@ForgeSubscribe @ForgeSubscribe
public void livingUpdate(LivingUpdateEvent event) public void livingUpdate(LivingUpdateEvent event)
{ {
EntityLivingBase entity = event.entityLiving; 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 (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 (entity instanceof EntityPlayerMP)
{ {
if (((EntityPlayerMP)entity).capabilities.isCreativeMode) if (((EntityPlayerMP)entity).capabilities.isCreativeMode)
{ {
return; return;
} }
} }
entity.attackEntityFrom(DamageSource.outOfWorld, 9000); entity.attackEntityFrom(DamageSource.outOfWorld, 9000);
return; return;
} }
// Обновление происходит в космическом или гипер пространстве // Обновление происходит в космическом или гипер пространстве
if (entity.worldObj.provider.dimensionId == WarpDrive.instance.spaceDimID || entity.worldObj.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID) if (entity.worldObj.provider.dimensionId == WarpDrive.instance.spaceDimID || entity.worldObj.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID)
{ {
boolean inVacuum = isEntityInVacuum(entity); boolean inVacuum = isEntityInVacuum(entity);
// Damage entity if in vacuum without protection // Damage entity if in vacuum without protection
if (inVacuum) if (inVacuum)
{ {
if (entity instanceof EntityPlayerMP) if (entity instanceof EntityPlayerMP)
{ {
if (((EntityPlayerMP)entity).getCurrentArmor(3) != null && WarpDriveConfig.i.SpaceHelmets.contains(((EntityPlayerMP)entity).getCurrentArmor(3).itemID)) if (((EntityPlayerMP)entity).getCurrentArmor(3) != null && WarpDriveConfig.i.SpaceHelmets.contains(((EntityPlayerMP)entity).getCurrentArmor(3).itemID))
{ {
Integer airValue = vacuumPlayers.get(((EntityPlayerMP)entity).username); Integer airValue = vacuumPlayers.get(((EntityPlayerMP)entity).username);
if (airValue == null) if (airValue == null)
{ {
vacuumPlayers.put(((EntityPlayerMP)entity).username, 300); vacuumPlayers.put(((EntityPlayerMP)entity).username, 300);
airValue = 300; airValue = 300;
} }
if (airValue <= 0) if (airValue <= 0)
{ {
if (((EntityPlayerMP)entity).inventory.consumeInventoryItem(WarpDriveConfig.i.IC2_Air)) if (consumeO2(((EntityPlayerMP)entity).inventory.mainInventory))
{ {
setPlayerAirValue(entity, 300); setPlayerAirValue(entity, 300);
} }
else else
{ {
setPlayerAirValue(entity, 0); setPlayerAirValue(entity, 0);
entity.attackEntityFrom(DamageSource.drown, 1); entity.attackEntityFrom(DamageSource.drown, 1);
} }
} }
else else
{ {
setPlayerAirValue(entity, airValue - 1); setPlayerAirValue(entity, airValue - 1);
} }
} }
else else
{ {
entity.attackEntityFrom(DamageSource.drown, 1); entity.attackEntityFrom(DamageSource.drown, 1);
} }
// Отправить назад на Землю // Отправить назад на Землю
if (entity.posY < -10.0D) 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).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).setFire(30);
((EntityPlayerMP)entity).setPositionAndUpdate(entity.posX, 250D, entity.posZ); ((EntityPlayerMP)entity).setPositionAndUpdate(entity.posX, 250D, entity.posZ);
} }
} }
else else
{ {
entity.attackEntityFrom(DamageSource.drown, 1); entity.attackEntityFrom(DamageSource.drown, 1);
} }
} }
} }
} }
private void setPlayerAirValue(EntityLivingBase entity, Integer air) private void setPlayerAirValue(EntityLivingBase entity, Integer air)
{ {
vacuumPlayers.remove(((EntityPlayerMP)entity).username); vacuumPlayers.remove(((EntityPlayerMP)entity).username);
vacuumPlayers.put(((EntityPlayerMP)entity).username, air); vacuumPlayers.put(((EntityPlayerMP)entity).username, air);
} }
/** /**
* Проверка, находится ли Entity в открытом космосе * Проверка, находится ли Entity в открытом космосе
* @param e * @param e
* @return * @return
*/ */
private boolean isEntityInVacuum(Entity e) private boolean isEntityInVacuum(Entity e)
{ {
int x = MathHelper.floor_double(e.posX); int x = MathHelper.floor_double(e.posX);
int y = MathHelper.floor_double(e.posY); int y = MathHelper.floor_double(e.posY);
int z = MathHelper.floor_double(e.posZ); int z = MathHelper.floor_double(e.posZ);
int id1 = e.worldObj.getBlockId(x, y, z); int id1 = e.worldObj.getBlockId(x, y, z);
int id2 = e.worldObj.getBlockId(x, y + 1, z); int id2 = e.worldObj.getBlockId(x, y + 1, z);
if (id1 == WarpDriveConfig.i.airID || id2 == WarpDriveConfig.i.airID) if (id1 == WarpDriveConfig.i.airID || id2 == WarpDriveConfig.i.airID)
{ return false;
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;
}
} }

View file

@ -22,7 +22,8 @@ public class WarpDriveConfig
// //
public boolean isGregLoaded = false, isAELoaded = false, isAdvSolPanelLoaded = false, isASLoaded = false, isICBMLoaded = false, isMFFSLoaded = false, isGraviSuiteLoaded = false; 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<Integer> SpaceHelmets, Jetpacks, MinerOres; public Set<Integer> SpaceHelmets, Jetpacks, MinerOres;
private Class<?> AEBlocks; private Class<?> AEBlocks;
private Class<?> AEMaterials; private Class<?> AEMaterials;
@ -164,7 +165,7 @@ public class WarpDriveConfig
SpaceHelmets.add(Items.getItem("quantumHelmet").itemID); SpaceHelmets.add(Items.getItem("quantumHelmet").itemID);
Jetpacks.add(Items.getItem("jetpack").itemID); Jetpacks.add(Items.getItem("jetpack").itemID);
Jetpacks.add(Items.getItem("electricJetpack").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("uraniumOre").itemID, Items.getItem("uraniumOre").getItemDamage()});
CommonWorldGenOres.add(new int[] {Items.getItem("copperOre").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()}); CommonWorldGenOres.add(new int[] {Items.getItem("tinOre").itemID, Items.getItem("uraniumOre").getItemDamage()});