summaryrefslogtreecommitdiff
path: root/ihl/utils
diff options
context:
space:
mode:
authorFoghrye4 <foghrye4@gmail.com>2016-04-11 19:44:54 +0300
committerFoghrye4 <foghrye4@gmail.com>2016-04-11 19:44:54 +0300
commit05c78126859231a68e199dc34613689bd0978e2f (patch)
tree050bea104a18c72905095d29f31bec2935a27a24 /ihl/utils
Initial commit
Diffstat (limited to 'ihl/utils')
-rw-r--r--ihl/utils/ChunkAndWorldLoadEventHandler.java63
-rw-r--r--ihl/utils/EntityDropEventHandler.java16
-rw-r--r--ihl/utils/EntityIHLExplosion.java187
-rw-r--r--ihl/utils/ExplosionVector.java453
-rw-r--r--ihl/utils/FluidDictionary.java42
-rw-r--r--ihl/utils/IHLFluidTank.java439
-rw-r--r--ihl/utils/IHLInvSlotDischarge.java83
-rw-r--r--ihl/utils/IHLItemRenderer.java294
-rw-r--r--ihl/utils/IHLMathUtils.java48
-rw-r--r--ihl/utils/IHLRenderUtils.java820
-rw-r--r--ihl/utils/IHLUtils.java1110
-rw-r--r--ihl/utils/IHLXMLParser.java141
-rw-r--r--ihl/utils/PlayerWakeUpEventHandler.java17
-rw-r--r--ihl/utils/WorldSavedDataBlastWave.java92
14 files changed, 3805 insertions, 0 deletions
diff --git a/ihl/utils/ChunkAndWorldLoadEventHandler.java b/ihl/utils/ChunkAndWorldLoadEventHandler.java
new file mode 100644
index 0000000..3fb51f7
--- /dev/null
+++ b/ihl/utils/ChunkAndWorldLoadEventHandler.java
@@ -0,0 +1,63 @@
+package ihl.utils;
+
+import ihl.IHLMod;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import net.minecraft.world.ChunkCoordIntPair;
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+
+public class ChunkAndWorldLoadEventHandler
+{
+ public static ChunkAndWorldLoadEventHandler instance;
+ public ChunkAndWorldLoadEventHandler()
+ {
+ instance=this;
+ }
+
+ @SubscribeEvent
+ public void onChunkLoadEvent(net.minecraftforge.event.world.ChunkEvent.Load event)
+ {
+ if(event.getChunk().isChunkLoaded && IHLMod.explosionHandler.blastWaveByDimensionId.containsKey(event.world.provider.dimensionId))
+ {
+ WorldSavedDataBlastWave bwdata = IHLMod.explosionHandler.blastWaveByDimensionId.get(event.world.provider.dimensionId);
+ long cc = ChunkCoordIntPair.chunkXZ2Int(event.getChunk().xPosition, event.getChunk().zPosition);
+ if(bwdata.data.containsKey(cc))
+ {
+ Long[][] bwArray = bwdata.data.remove(cc);
+ Set<Long> svset = new HashSet(16);
+ int sourceIndex=0;
+ for(int i1=0;i1<16;i1++)
+ {
+ if(bwArray[i1][0]!=null && !bwArray[i1][0].equals(0))
+ {
+ sourceIndex=i1;
+ svset.add(bwArray[i1][0]);
+ IHLMod.explosionHandler.setPower(bwArray[i1][0], bwArray[i1][4].intValue());
+ }
+ }
+ IHLMod.explosionHandler.doExplosion(event.world, bwArray[sourceIndex][1].intValue(), bwArray[sourceIndex][2].intValue(), bwArray[sourceIndex][3].intValue(), svset);
+ }
+ }
+ }
+
+ @SubscribeEvent
+ public void onWorldLoadEvent(net.minecraftforge.event.world.WorldEvent.Load event)
+ {
+ WorldSavedDataBlastWave blastWave = (WorldSavedDataBlastWave) event.world.mapStorage.loadData(WorldSavedDataBlastWave.class, "blastWave");
+ if(blastWave!=null)
+ {
+ IHLMod.explosionHandler.blastWaveByDimensionId.put(event.world.provider.dimensionId,blastWave);
+ }
+ }
+
+ @SubscribeEvent
+ public void onWorldSaveEvent(net.minecraftforge.event.world.WorldEvent.Save event)
+ {
+ if(IHLMod.explosionHandler.blastWaveByDimensionId.containsKey(event.world.provider.dimensionId))
+ {
+ event.world.mapStorage.setData("blastWave",IHLMod.explosionHandler.blastWaveByDimensionId.get(event.world.provider.dimensionId));
+ }
+ }
+}
diff --git a/ihl/utils/EntityDropEventHandler.java b/ihl/utils/EntityDropEventHandler.java
new file mode 100644
index 0000000..f4021ef
--- /dev/null
+++ b/ihl/utils/EntityDropEventHandler.java
@@ -0,0 +1,16 @@
+package ihl.utils;
+
+import net.minecraft.entity.passive.EntitySheep;
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+
+public class EntityDropEventHandler
+{
+ @SubscribeEvent
+ public void onEntityDropEvent(net.minecraftforge.event.entity.living.LivingDropsEvent event)
+ {
+ if(event.entityLiving instanceof EntitySheep && !event.entityLiving.isChild())
+ {
+ event.entityLiving.entityDropItem(IHLUtils.getThisModItemStackWithSize("muttonLard", event.entityLiving.worldObj.rand.nextInt(1)+1), 1f);
+ }
+ }
+}
diff --git a/ihl/utils/EntityIHLExplosion.java b/ihl/utils/EntityIHLExplosion.java
new file mode 100644
index 0000000..df0dc18
--- /dev/null
+++ b/ihl/utils/EntityIHLExplosion.java
@@ -0,0 +1,187 @@
+package ihl.utils;
+
+import ihl.IHLMod;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import net.minecraft.block.Block;
+import net.minecraft.entity.Entity;
+import net.minecraft.init.Blocks;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.world.Explosion;
+import net.minecraft.world.World;
+
+public class EntityIHLExplosion extends Entity {
+ private Explosion explosion;
+ private boolean explosionDone=false;
+ public Set<Long> effectBorderBlocks;
+ public Set<Long> effectBorderBlocksWithLowPosition;
+ public Set<Long> blocksConnectedWithBedrock;
+ public Set<Long> blocksNotConnectedWithBedrock;
+ public int explosionPower;
+ public int x;
+ public int y;
+ public int z;
+ private Map<Long,Entity> entityCache = new HashMap();
+
+ public EntityIHLExplosion(World world,int x1,int y1,int z1, int explosionPower1) {
+ super(world);
+ this.effectBorderBlocks=new HashSet();
+ this.effectBorderBlocksWithLowPosition=new HashSet();
+ this.blocksConnectedWithBedrock=new HashSet();
+ this.blocksNotConnectedWithBedrock=new HashSet();
+ this.isImmuneToFire=true;
+ this.noClip=true;
+ this.setSize(0F, 0F);
+ this.x=x1;
+ this.y=y1;
+ this.z=z1;
+ this.setPosition(x+0.5d, y+0.5d, z+0.5d);
+ this.explosionPower = explosionPower1;
+ }
+
+
+
+ @Override
+ public void onUpdate()
+ {
+ if(!worldObj.isRemote)
+ {
+ if(!effectBorderBlocks.isEmpty())
+ {
+ boolean hasSomeBlocksStickedToAir=false;
+ Iterator<Long> ebbi = effectBorderBlocks.iterator();
+ while(ebbi.hasNext())
+ {
+ long longNumber = ebbi.next();
+ int[] xyz = IHLUtils.decodeXYZ(longNumber);
+ Block block = worldObj.getBlock(x+xyz[0], y+xyz[1], z+xyz[2]);
+ if(block!=Blocks.air && !block.isAir(worldObj, x+xyz[0], y+xyz[1], z+xyz[2]))
+ {
+ if(block.getMaterial().isLiquid())
+ {
+ block.onNeighborBlockChange(worldObj, x+xyz[0], y+xyz[1], z+xyz[2], block);
+ }
+ else if(!this.isBlockConnectedWithBedrock(longNumber))
+ {
+ hasSomeBlocksStickedToAir=true;
+ }
+ }
+ }
+ Iterator<Long> bnctbi = this.blocksNotConnectedWithBedrock.iterator();
+ while(bnctbi.hasNext())
+ {
+ long longNumber5 = bnctbi.next();
+ int[] xyz = IHLUtils.decodeXYZ(longNumber5);
+ Block block = worldObj.getBlock(x+xyz[0], y+xyz[1], z+xyz[2]);
+ float bh = block.getBlockHardness(worldObj, x+xyz[0], y+xyz[1], z+xyz[2]);
+ if(bh>=0f && bh<Float.MAX_VALUE)
+ {
+ block.onBlockDestroyedByExplosion(worldObj, x+xyz[0], y+xyz[1], z+xyz[2], explosion);
+ }
+ }
+ }
+ if(!this.explosionDone)
+ {
+ IHLMod.explosionHandler.setPower(IHLMod.explosionHandler.startVectors, explosionPower);
+ IHLMod.explosionHandler.doExplosion(worldObj, x, y, z, IHLMod.explosionHandler.startVectors);
+ this.explosionDone=true;
+ }
+ }
+ }
+
+ private boolean isBlockConnectedWithBedrock(long longNumber)
+ {
+ if(this.blocksNotConnectedWithBedrock.contains(longNumber))
+ {
+ return false;
+ }
+ Set<Long> path = new HashSet();
+ Iterator<Long> pathi = path.iterator();
+ Set<Long> deadlockBlocks = new HashSet();
+ int[] xyz = IHLUtils.decodeXYZ(longNumber);
+ int absX=x+xyz[0];
+ int absY=y+xyz[1];
+ int absZ=z+xyz[2];
+ path.add(longNumber);
+ while(absY>4)
+ {
+ int xyzi[] = {0,0,-1,0,0,1,0,0};
+ Block block;
+ int x2,y2,z2;
+ boolean deadlock = true;
+ for(int i=0;i<=5;i++)
+ {
+ x2=absX+xyzi[i];
+ y2=absY+xyzi[i+2];
+ z2=absZ+xyzi[i+1];
+ long longNumber2 = IHLUtils.encodeXYZ(x2-x, y2-y, z2-z);
+ if(this.blocksConnectedWithBedrock.contains(longNumber2))
+ {
+ this.blocksConnectedWithBedrock.addAll(path);
+ return true;
+ }
+ if(!path.contains(longNumber2))
+ {
+ block = worldObj.getBlock(x2,y2,z2);
+ if(block!=Blocks.air && !block.isAir(worldObj, x2,y2,z2) && !block.getMaterial().isLiquid())
+ {
+ absX=x2;
+ absY=y2;
+ absZ=z2;
+ path.add(longNumber2);
+ if(absY<=4)
+ {
+ this.blocksConnectedWithBedrock.addAll(path);
+ return true;
+ }
+ deadlock = false;
+ break;
+ }
+ }
+ }
+ if(deadlock)
+ {
+ long longNumber3 = IHLUtils.encodeXYZ(absX-x, absY-y, absZ-z);
+ deadlockBlocks.add(longNumber3);
+ boolean deadEnd=true;
+ while(pathi.hasNext())
+ {
+ long longNumber4 = pathi.next();
+ if(!deadlockBlocks.contains(longNumber4))
+ {
+ int[] xyz2 = IHLUtils.decodeXYZ(longNumber4);
+ absX=x+xyz2[0];
+ absY=y+xyz2[1];
+ absZ=z+xyz2[2];
+ deadEnd=false;
+ break;
+ }
+ }
+ if(deadEnd)
+ {
+ this.blocksNotConnectedWithBedrock.addAll(path);
+ return false;
+ }
+ }
+ }
+ this.blocksConnectedWithBedrock.addAll(path);
+ return true;
+ }
+
+
+ @Override
+ protected void entityInit() {}
+
+ @Override
+ protected void readEntityFromNBT(NBTTagCompound arg0) {}
+
+ @Override
+ protected void writeEntityToNBT(NBTTagCompound arg0) {}
+
+
+}
diff --git a/ihl/utils/ExplosionVector.java b/ihl/utils/ExplosionVector.java
new file mode 100644
index 0000000..d341fd3
--- /dev/null
+++ b/ihl/utils/ExplosionVector.java
@@ -0,0 +1,453 @@
+package ihl.utils;
+
+import ihl.IHLMod;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+
+import net.minecraft.block.Block;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.network.play.server.S26PacketMapChunkBulk;
+import net.minecraft.util.DamageSource;
+import net.minecraft.world.ChunkCoordIntPair;
+import net.minecraft.world.Explosion;
+import net.minecraft.world.World;
+import net.minecraft.world.chunk.Chunk;
+import net.minecraft.world.chunk.NibbleArray;
+import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
+
+public class ExplosionVector
+{
+ public Set<Long> startVectors = new HashSet();
+ private Set<Long> sv;
+ private Set<Chunk> chunksToUpdate=new HashSet(64);
+ public Map<Long,Set<Long>> vectors = new HashMap(32786);
+ public Map<Long,Explosion> explosions = new HashMap();
+ public Map<Long,Integer> explosionPower = new HashMap();
+ public Map<Long,Float> explosionPowerDampingFactor = new HashMap(32786);
+ public Map<Long,ExtendedBlockStorage> cachedEBS = new HashMap(128);
+ public Map<Long,Integer> cachedEBSHardness = new HashMap(128);
+ public Map<Long,Map<Long,Integer>> cachedEBSDrops = new HashMap(128);
+ public Map<Long,List<Entity>> cachedEBSEntity = new HashMap(128);
+ public Map<Integer,WorldSavedDataBlastWave> blastWaveByDimensionId = new HashMap();
+
+ private Random random = new Random();
+
+ public ExplosionVector()
+ {
+ this.precalculateExplosion();
+ }
+
+ public void precalculateExplosion()
+ {
+ int maxExplosionRadius=32;
+ for(int levelRadius=1; levelRadius<maxExplosionRadius; levelRadius++)
+ {
+ for(int ix=-levelRadius;ix<=levelRadius;ix++)
+ {
+ for(int iy=-levelRadius;iy<=levelRadius;iy++)
+ {
+ for(int iz=-levelRadius;iz<=levelRadius;iz++)
+ {
+ {
+ long coordinateKey = IHLUtils.encodeXYZ(ix,iy,iz);
+ if(!vectors.containsKey(coordinateKey))
+ {
+ int prevX=ix;
+ int prevY=iy;
+ int prevZ=iz;
+ if(Math.abs(ix)+Math.abs(iy)+Math.abs(iz)>Math.round(levelRadius*1.8f))
+ {
+ prevX=IHLUtils.reduceVariableByAbsoluteValue(prevX);
+ prevY=IHLUtils.reduceVariableByAbsoluteValue(prevY);
+ prevZ=IHLUtils.reduceVariableByAbsoluteValue(prevZ);
+ }
+ else if(Math.abs(ix)<=Math.abs(iy) && Math.abs(ix)<=Math.abs(iz))
+ {
+ prevY=IHLUtils.reduceVariableByAbsoluteValue(prevY);
+ prevZ=IHLUtils.reduceVariableByAbsoluteValue(prevZ);
+ }
+ else if(Math.abs(iy)<=Math.abs(ix) && Math.abs(iy)<=Math.abs(iz))
+ {
+ prevX=IHLUtils.reduceVariableByAbsoluteValue(prevX);
+ prevZ=IHLUtils.reduceVariableByAbsoluteValue(prevZ);
+ }
+ else if(Math.abs(iz)<=Math.abs(ix) && Math.abs(iz)<=Math.abs(iy))
+ {
+ prevY=IHLUtils.reduceVariableByAbsoluteValue(prevY);
+ prevX=IHLUtils.reduceVariableByAbsoluteValue(prevX);
+ }
+ long prevKey = IHLUtils.encodeXYZ(prevX,prevY,prevZ);
+ if(prevX==ix && prevY==iy && prevZ==iz && levelRadius>1)
+ {
+ IHLMod.log.error("Was:"+ix+"/" +iy+"/" +iz+"/");
+ IHLMod.log.error("Now:"+prevX+"/" +prevY+"/" +prevZ+"/");
+ throw new ArithmeticException("Variables are out of expected range. \n Expected are not equal: "+ix+"="+prevX+" "+iy+"="+prevY+" "+iz+"="+prevZ);
+ }
+ if(levelRadius==1)
+ {
+ startVectors.add(coordinateKey);
+ this.addElement(coordinateKey, prevX, prevY, prevZ, ix, iy, iz);
+ }
+ else if(vectors.containsKey(prevKey))
+ {
+ //prevKey=this.getParentWithLowestDescendantsRate(prevKey, prevX, prevY, prevZ, levelRadius);
+ vectors.get(prevKey).add(coordinateKey);
+ this.addElement(coordinateKey, prevX, prevY, prevZ, ix, iy, iz);
+ }
+ else
+ {
+ IHLMod.log.error("Was:"+ix+"/" +iy+"/" +iz+"/");
+ IHLMod.log.error("Now:"+prevX+"/" +prevY+"/" +prevZ+"/");
+ IHLMod.log.info("ExplosionVector is missing parent! Help him!");
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void addElement(long coordinateKey, int prevX, int prevY, int prevZ, int ix, int iy, int iz)
+ {
+ vectors.put(coordinateKey, new HashSet());
+ float df = (float)(prevX*prevX+prevY*prevY+prevZ*prevZ+1)/(float)(ix*ix+iy*iy+iz*iz+1);
+ explosionPowerDampingFactor.put(coordinateKey,df);
+ }
+
+ public void setPower(Set<Long> sv2, int power1)
+ {
+ for(long ev:sv2)
+ {
+ this.setPower(ev, power1);
+ }
+ }
+
+ public void setPower(Long ev, int power1) {
+ this.explosionPower.put(ev, power1);
+ }
+/*
+ public Set<Long> breakBlocksAndGetDescendants(World world, EntityIHLExplosion exploder, Explosion explosion, long longNumber)
+ {
+ int multiplier = exploder.multiplier;
+ int[] xyz = IHLUtils.decodeXYZ(longNumber);
+ int power1 = explosionPower.get(longNumber);
+ int repeat=0;
+ //System.out.println("Power before " + power1);
+ if(Math.abs(xyz[0])>=Math.abs(xyz[1]) && Math.abs(xyz[0])>=Math.abs(xyz[2]))
+ {
+ for(int ix=xyz[0]>0?0:multiplier-1;ix<multiplier && ix>=0;ix=xyz[0]>0?ix+1:ix-1)
+ {
+ for(int iy=xyz[1]>0?0:multiplier-1;iy<multiplier && iy>=0;iy=xyz[1]>0?iy+1:iy-1)
+ {
+ for(int iz=xyz[2]>0?0:multiplier-1;iz<multiplier && iz>=0;iz=xyz[2]>0?iz+1:iz-1)
+ {
+ power1 = this.getNewPowerAndProcessBlocks(world, exploder, explosion, xyz, multiplier, ix, iy, iz, power1);
+ }
+ }
+ }
+ }
+ else if(Math.abs(xyz[1])>=Math.abs(xyz[0]) && Math.abs(xyz[1])>=Math.abs(xyz[2]))
+ {
+ for(int iy=xyz[1]>0?0:multiplier-1;iy<multiplier && iy>=0;iy=xyz[1]>0?iy+1:iy-1)
+ {
+ for(int ix=xyz[0]>0?0:multiplier-1;ix<multiplier && ix>=0;ix=xyz[0]>0?ix+1:ix-1)
+ {
+ for(int iz=xyz[2]>0?0:multiplier-1;iz<multiplier && iz>=0;iz=xyz[2]>0?iz+1:iz-1)
+ {
+ power1 = this.getNewPowerAndProcessBlocks(world, exploder, explosion, xyz, multiplier, ix, iy, iz, power1);
+ }
+ }
+ }
+ }
+ else
+ {
+ for(int iz=xyz[2]>0?0:multiplier-1;iz<multiplier && iz>=0;iz=xyz[2]>0?iz+1:iz-1)
+ {
+ for(int ix=xyz[0]>0?0:multiplier-1;ix<multiplier && ix>=0;ix=xyz[0]>0?ix+1:ix-1)
+ {
+ for(int iy=xyz[1]>0?0:multiplier-1;iy<multiplier && iy>=0;iy=xyz[1]>0?iy+1:iy-1)
+ {
+ power1 = this.getNewPowerAndProcessBlocks(world, exploder, explosion, xyz, multiplier, ix, iy, iz, power1);
+ }
+ }
+ }
+ }
+ power1=Math.round(power1*explosionPowerDampingFactor.get(longNumber)-0.5f);
+ //System.out.println("Power after " + power1 + " \n repeats "+repeat);
+ if(power1<=1 || !vectors.containsKey(longNumber)|| vectors.get(longNumber).isEmpty())
+ {
+ exploder.effectBorderBlocks.add(longNumber);
+ if(xyz[1]<0 || (exploder.y<=6 && xyz[1]<=6))
+ {
+ exploder.effectBorderBlocksWithLowPosition.add(longNumber);
+ }
+ return null;
+ }
+ else
+ {
+ for(long d1:vectors.get(longNumber))
+ {
+ explosionPower.put(d1, power1);
+ }
+ return vectors.get(longNumber);
+ }
+ }
+ */
+
+ public Set<Long> breakBlocksAndGetDescendantsForEBS(World world, int sourceX,int sourceY,int sourceZ, Explosion explosion, long longNumber)
+ {
+ int[] xyz = IHLUtils.decodeXYZ(longNumber);
+ int power1 = explosionPower.remove(longNumber);
+ power1 = this.getNewPowerAndProcessBlocksEBS(world, longNumber, sourceX, sourceY, sourceZ, explosion, xyz, power1);
+ power1=Math.round(power1*explosionPowerDampingFactor.get(longNumber)-0.5f);
+ if(power1<=1 || !vectors.containsKey(longNumber)|| vectors.get(longNumber).isEmpty())
+ {
+ return null;
+ }
+ else
+ {
+ for(long d1:vectors.get(longNumber))
+ {
+ explosionPower.put(d1, power1);
+ }
+ return vectors.get(longNumber);
+ }
+
+ }
+/*
+ private int getNewPowerAndProcessBlocks(World world, EntityIHLExplosion exploder, Explosion explosion, int xyz[], int multiplier, int ix, int iy, int iz, int power2)
+ {
+ int power1=power2;
+ int x = exploder.x+xyz[0]*multiplier+ix;
+ int y = exploder.y+xyz[1]*multiplier+iy;
+ int z = exploder.z+xyz[2]*multiplier+iz;
+ if(y<=4 || y>256)
+ {
+ return 0;
+ }
+ Block block = exploder.getBlock(x, y, z);
+ int explosionResistance = Math.round(block.getExplosionResistance(exploder, world, x, y, z, exploder.x, exploder.y, exploder.z)*10f);
+ if(explosionResistance>=power1)
+ {
+ power1=0;
+ }
+ else
+ {
+ power1-=Math.round(block.getExplosionResistance(exploder, world, x, y, z, exploder.x, exploder.y, exploder.z)*10f);
+ Entity entity = exploder.getEntity(x, y, z);
+ if(entity!=null)
+ {
+ entity.attackEntityFrom(exploder.damageSource, power1/10f);
+ }
+ block.onBlockDestroyedByExplosion(world, x, y, z, explosion);
+ exploder.setBlockToAir(x, y, z);
+ }
+ return power1;
+ }
+ */
+ private int getNewPowerAndProcessBlocksEBS(World world, long longNumber, int sourceX, int sourceY, int sourceZ, Explosion explosion, int xyz[], int power2)
+ {
+ int power1=power2;
+ int absEBSX = xyz[0] + (sourceX>>4);
+ int absEBSY = xyz[1] + (sourceY>>4);
+ int absEBSZ = xyz[2] + (sourceZ>>4);
+ long chunkXZKey = ChunkCoordIntPair.chunkXZ2Int(absEBSX, absEBSZ);
+ if(absEBSY<0 || absEBSY>=16)
+ {
+ return 0;
+ }
+ if(world.getChunkProvider().chunkExists(absEBSX, absEBSZ))
+ {
+ long absEBShash = IHLUtils.getXYZHash(absEBSX, absEBSY, absEBSZ);
+ int explosionResistance = this.getEBSResistance(world, absEBShash, absEBSX, absEBSY, absEBSZ, sourceX, sourceY, sourceZ);
+ if(explosionResistance>=power1)
+ {
+ power1=0;
+ }
+ else
+ {
+ power1-=explosionResistance;
+ if(this.cachedEBSEntity.containsKey(absEBShash))
+ {
+ List<Entity> entityList = this.cachedEBSEntity.get(absEBShash);
+ for(Object entity:entityList.toArray())
+ {
+ if(entity!=null)
+ {
+ ((Entity) entity).attackEntityFrom(DamageSource.setExplosionSource(explosion), power1/10f);
+ }
+ }
+ }
+ this.onEBSDestroy(world, absEBShash, absEBSX, absEBSY, absEBSZ);
+ }
+ }
+ else
+ {
+ WorldSavedDataBlastWave blastWave = null;
+ int dimensionId = world.provider.dimensionId;
+ if(this.blastWaveByDimensionId.containsKey(dimensionId))
+ {
+ blastWave=this.blastWaveByDimensionId.get(dimensionId);
+ }
+ else
+ {
+ blastWave=new WorldSavedDataBlastWave("blastWave");
+ this.blastWaveByDimensionId.put(dimensionId, blastWave);
+ }
+ blastWave.scheduleExplosionEffectsOnChunkLoad(chunkXZKey, longNumber, sourceX, sourceY, sourceZ, power1, absEBSY);
+ }
+ return power1;
+ }
+
+ public int getEBSResistance(World world, long absEBShash, int absEBSX, int absEBSY, int absEBSZ, int sourceX, int sourceY, int sourceZ)
+ {
+
+ if(this.cachedEBSHardness.containsKey(absEBShash))
+ {
+ return this.cachedEBSHardness.get(absEBShash);
+ }
+ else
+ {
+ this.precacheChunk(world, absEBSX,absEBSZ, sourceX, sourceY, sourceZ);
+ return this.cachedEBSHardness.containsKey(absEBShash)?this.cachedEBSHardness.get(absEBShash):0;
+ }
+ }
+
+ public void precacheChunk(World world, int absEBSX, int absEBSZ, int sourceX, int sourceY, int sourceZ)
+ {
+ Chunk chunk = world.getChunkProvider().provideChunk(absEBSX, absEBSZ);
+ ExtendedBlockStorage[] ebsA = chunk.getBlockStorageArray();
+ for(int y3=0;y3<ebsA.length;y3++)
+ {
+ ExtendedBlockStorage ebs = ebsA[y3];
+ int ebsHardness = 0;
+ long absEBShash1 = IHLUtils.getXYZHash(absEBSX, y3, absEBSZ);
+ if(ebs!=null && !ebs.isEmpty())
+ {
+ byte[] lbsArray = ebs.getBlockLSBArray();
+ Map<Long,Integer> drops = new HashMap();
+ for(int i4=0;i4<lbsArray.length;i4++)
+ {
+ int var4 = lbsArray[i4] & 255;
+ if (ebs.getBlockMSBArray() != null)
+ {
+ var4 |= ebs.getBlockMSBArray().get(i4 & 15, (i4>>8) & 15, (i4>>4) & 15) << 8;
+ }
+ int blockWorldX = (i4 & 15)+(absEBSX<<4);
+ int blockWorldY = ((i4>>8) & 15)+(y3<<4);
+ int blockWorldZ = ((i4>>4) & 15)+(absEBSZ<<4);
+ Block block = Block.getBlockById(var4);
+ List<ItemStack> dropsList = (block.getDrops(world, blockWorldX, blockWorldY, blockWorldZ, ebs.getExtBlockMetadata(i4 & 15, (i4>>8) & 15, (i4>>4) & 15), 0));
+ if(dropsList!=null)
+ {
+ for(ItemStack drop:dropsList)
+ {
+ long key = (Item.getIdFromItem(drop.getItem())<<16)|drop.getItemDamage();
+ if(drops.containsKey(key))
+ {
+ int ss = drops.get(key);
+ drops.put(key, drop.stackSize+ss);
+ }
+ else
+ {
+ drops.put(key, drop.stackSize);
+ }
+ }
+ }
+ if(block.getBlockHardness(world, blockWorldX, blockWorldY, blockWorldZ)<0)
+ {
+ ebsHardness=Integer.MAX_VALUE;
+ break;
+ }
+ else
+ {
+ ebsHardness+=Math.round(block.getExplosionResistance(null, world, blockWorldX, blockWorldY, blockWorldZ, sourceX, sourceY, sourceZ)*10f);
+ }
+ }
+ this.cachedEBSDrops.put(absEBShash1, drops);
+ this.cachedEBSEntity.put(absEBShash1, chunk.entityLists[y3]);
+ this.cachedEBSHardness.put(absEBShash1, ebsHardness);
+ this.cachedEBS.put(absEBShash1, ebs);
+ }
+ }
+ }
+
+ public void onEBSDestroy(World world,long absEBShash,int absEBSX,int absEBSY,int absEBSZ)
+ {
+ if(this.cachedEBS.containsKey(absEBShash))
+ {
+ ExtendedBlockStorage ebs = this.cachedEBS.get(absEBShash);
+ ebs.setBlockMSBArray(new NibbleArray(4096, 4));
+ ebs.setBlockLSBArray(new byte[4096]);
+ this.cachedEBS.remove(absEBShash);
+ this.cachedEBSDrops.remove(absEBShash);
+ this.cachedEBSEntity.remove(absEBShash);
+ this.cachedEBSHardness.remove(absEBShash);
+ this.chunksToUpdate.add(world.getChunkProvider().provideChunk(absEBSX, absEBSZ));
+ }
+ }
+
+ public void sendChunkUpdateToPlayersInExplosionAffectedZone(World world)
+ {
+ for(Object player:world.playerEntities)
+ {
+ if(player instanceof EntityPlayerMP)
+ {
+ EntityPlayerMP playerMP = (EntityPlayerMP)player;
+ List chunks = new ArrayList();
+ chunks.addAll(this.chunksToUpdate);
+ playerMP.playerNetServerHandler.sendPacket(new S26PacketMapChunkBulk(chunks));
+ this.chunksToUpdate.clear();
+ }
+ }
+ }
+
+ public void doExplosion(World world, int sourceX, int sourceY, int sourceZ, Set<Long> startVectors1)
+ {
+ boolean doExplosion=true;
+ long sourceHash = IHLUtils.getXYZHash(sourceX, sourceY, sourceZ);
+ Explosion explosion = new Explosion(world, null, sourceX, sourceY, sourceZ, 100f);
+ explosions.put(sourceHash, explosion);
+ while(doExplosion)
+ {
+ Set<Long> sv2=new HashSet();
+ if(sv==null)
+ {
+ sv = startVectors1;
+ }
+ for(long ev:sv)
+ {
+ Set<Long> sv3 = this.breakBlocksAndGetDescendantsForEBS(world, sourceX, sourceY, sourceZ, explosion, ev);
+ if(sv3!=null)
+ {
+ sv2.addAll(sv3);
+ }
+ }
+ if(sv2.isEmpty())
+ {
+ doExplosion=false;
+ sv = null;
+ sendChunkUpdateToPlayersInExplosionAffectedZone(world);
+ break;
+ }
+ else
+ {
+ sv=sv2;
+ }
+ }
+
+
+ }
+
+
+}
diff --git a/ihl/utils/FluidDictionary.java b/ihl/utils/FluidDictionary.java
new file mode 100644
index 0000000..fa5b96a
--- /dev/null
+++ b/ihl/utils/FluidDictionary.java
@@ -0,0 +1,42 @@
+package ihl.utils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import net.minecraftforge.fluids.Fluid;
+import net.minecraftforge.fluids.FluidStack;
+
+public class FluidDictionary
+{
+ private Map<String,List<FluidStack>> nameToStack = new HashMap();
+ private Map<Fluid,String> fluidToName = new HashMap();
+ public FluidDictionary(){}
+
+ public List<FluidStack> getFluids(String fdName)
+ {
+ return nameToStack.get(fdName);
+ }
+
+ public void registerFluidStack(String fdName, FluidStack fstack)
+ {
+ if(nameToStack.containsKey(fdName))
+ {
+ nameToStack.get(fdName).add(fstack);
+ }
+ else
+ {
+ List<FluidStack> list = new ArrayList();
+ list.add(fstack);
+ nameToStack.put(fdName, list);
+ }
+ fluidToName.put(fstack.getFluid(), fdName);
+ }
+
+ public String getFluidName(Fluid f)
+ {
+ return fluidToName.get(f);
+ }
+
+}
diff --git a/ihl/utils/IHLFluidTank.java b/ihl/utils/IHLFluidTank.java
new file mode 100644
index 0000000..aef2b46
--- /dev/null
+++ b/ihl/utils/IHLFluidTank.java
@@ -0,0 +1,439 @@
+package ihl.utils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import ihl.recipes.IRecipeInputFluid;
+import ihl.worldgen.ores.IHLFluid;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraftforge.fluids.FluidRegistry;
+import net.minecraftforge.fluids.FluidStack;
+import net.minecraftforge.fluids.FluidTankInfo;
+import net.minecraftforge.fluids.IFluidTank;
+
+public class IHLFluidTank implements IFluidTank
+{
+ private final List<FluidStack> fluidList = new ArrayList<FluidStack>();
+ private final int capacity;
+ private boolean isOpenVessel=false;
+ private int temperature=293;
+
+ public IHLFluidTank(int capacity)
+ {
+ this.capacity = capacity;
+ }
+
+ public IHLFluidTank(int capacity, boolean isOpenVessel1)
+ {
+ this.isOpenVessel=isOpenVessel1;
+ this.capacity = capacity;
+ }
+
+ public IHLFluidTank readFromNBT(NBTTagCompound nbt)
+ {
+ if (!nbt.hasKey("Empty"))
+ {
+ NBTTagList fluidList1 = nbt.getTagList("fluids", 10);
+ for(int i=0;i<fluidList1.tagCount();i++)
+ {
+ NBTTagCompound fluidNBT1 = fluidList1.getCompoundTagAt(i);
+ FluidStack fluid = FluidStack.loadFluidStackFromNBT(fluidNBT1);
+ if (fluid != null)
+ {
+ fluidList.add(fluid);
+ }
+ }
+ temperature=nbt.getInteger("temperature");
+ }
+ return this;
+ }
+
+ public NBTTagCompound writeToNBT(NBTTagCompound nbt)
+ {
+ if (!fluidList.isEmpty())
+ {
+ NBTTagList fluids = new NBTTagList();
+ Iterator<FluidStack> fli = fluidList.iterator();
+ while(fli.hasNext())
+ {
+ FluidStack fluid=fli.next();
+ if(fluid!=null)
+ {
+ NBTTagCompound fluidNBT1 = new NBTTagCompound();
+ fluid.writeToNBT(fluidNBT1);
+ fluids.appendTag(fluidNBT1);
+ }
+ }
+ nbt.setTag("fluids", fluids);
+ nbt.setInteger("temperature", temperature);
+ }
+ else
+ {
+ nbt.setString("Empty", "");
+ }
+ return nbt;
+ }
+
+ /* IFluidTank */
+ @Override
+ public FluidStack getFluid()
+ {
+ if(this.fluidList.isEmpty())
+ {
+ return null;
+ }
+ return this.fluidList.get(0);
+ }
+
+ public FluidStack getLigthestFluid()
+ {
+ if(this.fluidList.isEmpty())
+ {
+ return null;
+ }
+ return this.fluidList.get(this.fluidList.size()-1);
+ }
+
+ @Override
+ public int getFluidAmount()
+ {
+ int amount=0;
+ Iterator<FluidStack> fli = fluidList.iterator();
+ while(fli.hasNext())
+ {
+ FluidStack fluid=fli.next();
+ if(fluid!=null)
+ {
+ amount+=fluid.amount;
+ }
+ }
+ return amount;
+ }
+
+ @Override
+ public int getCapacity()
+ {
+ return capacity;
+ }
+
+ @Override
+ public FluidTankInfo getInfo()
+ {
+ return new FluidTankInfo(this);
+ }
+
+ @Override
+ public int fill(FluidStack resource, boolean doFill)
+ {
+ if (resource == null || resource.getFluid() == null || resource.amount<=0)
+ {
+ return 0;
+ }
+ if (!doFill)
+ {
+ if (fluidList.isEmpty())
+ {
+ return Math.min(capacity, resource.amount);
+ }
+ return Math.min(capacity - this.getFluidAmount(), resource.amount);
+ }
+ if (fluidList.isEmpty())
+ {
+ FluidStack fluid = copyWithSize(resource,Math.min(capacity, resource.amount));
+ fluidList.add(fluid);
+ this.temperature=fluid.getFluid().getTemperature();
+ return fluid.amount;
+ }
+ this.temperature=alignTemperatures(resource);
+ FluidStack fluid = getFluidStackWithSameFluid(resource);
+ if(fluid!=null)
+ {
+ int amount1=Math.min(capacity - this.getFluidAmount(), resource.amount);
+ fluid.amount+=amount1;
+ return amount1;
+ }
+ fluid = copyWithSize(resource,Math.min(capacity, resource.amount));
+ fluidList.add(fluid);
+ this.sortFluidsByDensity();
+ return fluid.amount;
+ }
+
+ private int alignTemperatures(FluidStack resource)
+ {
+ int amountOfFluidInTank = this.getFluidAmount();
+ int averageT=(this.temperature*amountOfFluidInTank+resource.getFluid().getTemperature()*resource.amount)/(amountOfFluidInTank+resource.amount);
+ return averageT;
+ }
+
+ @Override
+ public FluidStack drain(int maxDrain, boolean doDrain)
+ {
+ if (fluidList.isEmpty())
+ {
+ return null;
+ }
+ FluidStack fstack = this.getFluid().copy();
+ fstack.amount=maxDrain;
+ return this.drain(fstack, doDrain);
+ }
+
+
+ public FluidStack drainLightest(int maxDrain, boolean doDrain)
+ {
+ if (fluidList.isEmpty())
+ {
+ return null;
+ }
+ FluidStack fstack = this.getLigthestFluid().copy();
+ fstack.amount=maxDrain;
+ return this.drain(fstack, doDrain);
+ }
+
+ public FluidStack drain(Object fluidStack, boolean doDrain)
+ {
+ if (fluidList.isEmpty())
+ {
+ return null;
+ }
+ int drained = 0;
+ if(fluidStack instanceof FluidStack)
+ {
+ drained = ((FluidStack)fluidStack).amount;
+ }
+ else
+ {
+ drained = ((IRecipeInputFluid)fluidStack).getAmount();
+ }
+ FluidStack fluid = this.getFluidStackWithSameFluid(fluidStack);
+ if (fluid==null)
+ {
+ return null;
+ }
+ if (fluid.amount < drained)
+ {
+ drained = fluid.amount;
+ }
+ FluidStack stack = copyWithSize(fluid,drained);
+ if (doDrain)
+ {
+ fluid.amount -= drained;
+ if (fluid.amount <= 0)
+ {
+ this.fluidList.remove(fluid);
+ fluid = null;
+ }
+ }
+ return stack;
+ }
+
+ public FluidStack getFluidStackWithSameFluid(Object fluidStack)
+ {
+ Iterator<FluidStack> fli = fluidList.iterator();
+ while(fli.hasNext())
+ {
+ FluidStack fluid=fli.next();
+ if(fluid!=null)
+ {
+ if(fluidStack instanceof FluidStack)
+ {
+ if(fluid.isFluidEqual((FluidStack)fluidStack))
+ {
+ return fluid;
+ }
+ }
+ else
+ {
+ if(((IRecipeInputFluid)fluidStack).matches(fluid))
+ {
+ return fluid;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public int getNumberOfFluids()
+ {
+ return this.fluidList.size();
+ }
+
+ public void setFluidAmount(int amount1, int index)
+ {
+ if(this.fluidList.size()<=index)
+ {
+ while(this.fluidList.size()<=index)
+ {
+ this.fluidList.add(new FluidStack(FluidRegistry.WATER,1));
+ }
+ }
+ this.fluidList.get(index).amount=amount1;
+ }
+
+ public int getFluidAmount(int index)
+ {
+ if(this.fluidList.size()<=index || this.fluidList.get(index)==null)
+ {
+ return 0;
+ }
+ return this.fluidList.get(index).amount;
+ }
+
+ public int getFluidID(int i)
+ {
+ if(this.fluidList.get(i)==null)
+ {
+ return -1;
+ }
+ return this.fluidList.get(i).getFluid().getID();
+ }
+
+ public void sortFluidsByDensity()
+ {
+ Map<Integer, FluidStack> sortMap = new HashMap();
+ int[] keysArray = new int[fluidList.size()];
+ Iterator<FluidStack> fli = fluidList.iterator();
+ while(fli.hasNext())
+ {
+ FluidStack fluid=fli.next();
+ if(fluid==null)
+ {
+ return;
+ }
+ int key = Math.round(IHLFluid.getRealDensity(fluid.getFluid())*100F);
+ while(sortMap.containsKey(key))
+ {
+ key++;
+ }
+ sortMap.put(key, fluid);
+ keysArray[fluidList.indexOf(fluid)]=key;
+ }
+ Arrays.sort(keysArray);
+ ArrayList<FluidStack> newFluidList = new ArrayList<FluidStack>();
+ for(int i=keysArray.length-1;i>=0;i--)
+ {
+ newFluidList.add(sortMap.get(keysArray[i]));
+ }
+ this.fluidList.clear();
+ this.fluidList.addAll(newFluidList);
+ }
+
+ public FluidStack getFluid(int i)
+ {
+ return this.fluidList.get(i);
+ }
+
+ public void setTag(String string, int t1_1)
+ {
+ if(this.getFluid().tag==null)
+ {
+ this.getFluid().tag=new NBTTagCompound();
+ }
+ this.getFluid().tag.setInteger(string, t1_1);
+ }
+
+ public void setEmpty()
+ {
+ this.fluidList.clear();
+ }
+
+ public int getTemperature()
+ {
+ return this.temperature;
+ }
+
+ public void setTemperature(int t1)
+ {
+ this.temperature=t1;
+ }
+
+ public List<FluidStack> getFluidList()
+ {
+ return this.fluidList;
+ }
+
+ public void drain(List fluidInputs, boolean doDrain)
+ {
+ if(fluidInputs!=null && !fluidInputs.isEmpty())
+ {
+ Iterator fsi = fluidInputs.iterator();
+ while(fsi.hasNext())
+ {
+ this.drain(fsi.next(), doDrain);
+ }
+ }
+ }
+
+ public void fill(List<FluidStack> fluidOutputs, boolean doFill)
+ {
+ if(fluidOutputs!=null && !fluidOutputs.isEmpty())
+ {
+ Iterator<FluidStack> fsi = fluidOutputs.iterator();
+ while(fsi.hasNext())
+ {
+ this.fill(fsi.next(), doFill);
+ }
+ }
+ }
+
+ private FluidStack copyWithSize(FluidStack resource, int amount1)
+ {
+ FluidStack fluid = resource.copy();
+ fluid.amount=amount1;
+ if(resource.tag!=null)
+ {
+ fluid.tag=(NBTTagCompound) resource.tag.copy();
+ }
+ return fluid;
+ }
+
+ public FluidStack drain(IRecipeInputFluid fluidStack, int amount, boolean doDrain)
+ {
+ if (fluidList.isEmpty())
+ {
+ return null;
+ }
+ int drained = amount;
+ FluidStack fluid = this.getFluidStackWithSameFluid(fluidStack);
+ if (fluid==null)
+ {
+ return null;
+ }
+ if (fluid.amount < drained)
+ {
+ drained = fluid.amount;
+ }
+ FluidStack stack = copyWithSize(fluid,drained);
+ if (doDrain)
+ {
+ fluid.amount -= drained;
+ if (fluid.amount <= 0)
+ {
+ this.fluidList.remove(fluid);
+ fluid = null;
+ }
+ }
+ return stack;
+ }
+
+ public void checkCorrectState()
+ {
+ if(!this.fluidList.isEmpty())
+ {
+ Iterator<FluidStack> fsi=this.fluidList.iterator();
+ while(fsi.hasNext())
+ {
+ FluidStack fs = fsi.next();
+ if(fs.amount<=0)
+ {
+ fsi.remove();
+ }
+ }
+ }
+ }
+}
diff --git a/ihl/utils/IHLInvSlotDischarge.java b/ihl/utils/IHLInvSlotDischarge.java
new file mode 100644
index 0000000..4ebb488
--- /dev/null
+++ b/ihl/utils/IHLInvSlotDischarge.java
@@ -0,0 +1,83 @@
+package ihl.utils;
+
+import net.minecraft.init.Items;
+import net.minecraft.item.ItemStack;
+import ic2.api.info.Info;
+import ic2.api.item.ElectricItem;
+import ic2.core.block.TileEntityInventory;
+import ic2.core.block.invslot.InvSlot;
+
+public class IHLInvSlotDischarge extends InvSlot
+{
+ public int tier;
+ public boolean allowRedstoneDust;
+
+ public IHLInvSlotDischarge(TileEntityInventory base, int oldStartIndex, InvSlot.Access access, int tier)
+ {
+ this(base, oldStartIndex, access, tier, InvSlot.InvSide.ANY);
+ }
+
+ public IHLInvSlotDischarge(TileEntityInventory base, int oldStartIndex, InvSlot.Access access, int tier, InvSlot.InvSide preferredSide)
+ {
+ this(base, oldStartIndex, access, tier, true, preferredSide);
+ }
+
+ public IHLInvSlotDischarge(TileEntityInventory base, int oldStartIndex, InvSlot.Access access, int tier, boolean allowRedstoneDust, InvSlot.InvSide preferredSide)
+ {
+ super(base, "discharge", oldStartIndex, access, 1, preferredSide);
+ this.allowRedstoneDust = true;
+ this.tier = tier;
+ this.allowRedstoneDust = allowRedstoneDust;
+ }
+
+ @Override
+ public boolean accepts(ItemStack stack)
+ {
+ return stack == null ? false : (stack.getItem() == Items.redstone && !this.allowRedstoneDust ? false : Info.itemEnergy.getEnergyValue(stack) > 0.0D || ElectricItem.manager.discharge(stack, Double.POSITIVE_INFINITY, this.tier, true, true, true) > 0.0D);
+ }
+
+ public double discharge(double amount, boolean ignoreLimit)
+ {
+ if (amount <= 0.0D)
+ {
+ throw new IllegalArgumentException("Amount must be > 0.");
+ }
+ else
+ {
+ ItemStack stack = this.get(0);
+
+ if (stack == null)
+ {
+ return 0.0D;
+ }
+ else
+ {
+ double realAmount = ElectricItem.manager.discharge(stack, amount, this.tier, ignoreLimit, true, false);
+
+ if (realAmount <= 0.0D)
+ {
+ realAmount = Info.itemEnergy.getEnergyValue(stack);
+
+ if (realAmount <= 0.0D)
+ {
+ return 0.0D;
+ }
+
+ --stack.stackSize;
+
+ if (stack.stackSize <= 0)
+ {
+ this.put(0, (ItemStack)null);
+ }
+ }
+
+ return realAmount;
+ }
+ }
+ }
+
+ public void setTier(int tier1)
+ {
+ this.tier = tier1;
+ }
+} \ No newline at end of file
diff --git a/ihl/utils/IHLItemRenderer.java b/ihl/utils/IHLItemRenderer.java
new file mode 100644
index 0000000..caed0a3
--- /dev/null
+++ b/ihl/utils/IHLItemRenderer.java
@@ -0,0 +1,294 @@
+package ihl.utils;
+
+import java.util.Random;
+
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.opengl.GL12;
+
+import net.minecraft.block.Block;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.renderer.ItemRenderer;
+import net.minecraft.client.renderer.OpenGlHelper;
+import net.minecraft.client.renderer.RenderBlocks;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.client.renderer.entity.RenderManager;
+import net.minecraft.client.renderer.texture.TextureManager;
+import net.minecraft.client.renderer.texture.TextureMap;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemCloth;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.IIcon;
+import net.minecraft.util.ResourceLocation;
+import net.minecraftforge.client.IItemRenderer;
+import net.minecraftforge.client.MinecraftForgeClient;
+import net.minecraftforge.client.IItemRenderer.ItemRenderType;
+
+public class IHLItemRenderer {
+ private Random random = new Random();
+ private RenderBlocks renderBlocks = new RenderBlocks();
+ private boolean noRotation=false;
+
+ public IHLItemRenderer(){}
+
+ public IHLItemRenderer(boolean b)
+ {
+ noRotation=b;
+ }
+
+ public void doRender(RenderManager renderManager, ItemStack stack, double x, double y, double z)
+ {
+ if(stack!=null)
+ {
+ if(stack.getItem().isFull3D())
+ {
+ ItemRenderType type = ItemRenderType.ENTITY;
+ IItemRenderer itemRenderer = MinecraftForgeClient.getItemRenderer(stack, type);
+ if(itemRenderer!=null)
+ {
+ GL11.glPushMatrix();
+ GL11.glTranslatef((float)x, (float)y-0.5F, (float)z);
+ GL11.glScalef(0.5F, 0.5F, 0.5F);
+ Object[] data={null,null};
+ itemRenderer.renderItem(type, stack, data);
+ GL11.glPopMatrix();
+ }
+ else
+ {
+ this.doRenderNative(renderManager, stack, x, y-0.1F, z);
+ }
+ }
+ else
+ {
+ this.doRenderNative(renderManager, stack, x, y-0.1F, z);
+ }
+ }
+ }
+
+ public void doRenderNative(RenderManager renderManager, ItemStack var10, double par2, double par4, double par6)
+ {
+ float scale=0.8F;
+ if (var10.getItem() != null)
+ {
+ renderManager.renderEngine.bindTexture(renderManager.renderEngine.getResourceLocation(var10.getItemSpriteNumber()));
+ this.random.setSeed(187L);
+ GL11.glPushMatrix();
+ byte var13 = 1;
+
+ if (var10.stackSize > 1)
+ {
+ var13 = 2;
+ }
+
+ if (var10.stackSize > 5)
+ {
+ var13 = 3;
+ }
+
+ if (var10.stackSize > 20)
+ {
+ var13 = 4;
+ }
+
+ if (var10.stackSize > 40)
+ {
+ var13 = 5;
+ }
+
+ GL11.glTranslatef((float)par2, (float)par4, (float)par6);
+
+ GL11.glEnable(GL12.GL_RESCALE_NORMAL);
+ float var19;
+ float var18;
+ int var24;
+
+ if (var10.getItemSpriteNumber() == 0 && var10.getItem() instanceof ItemBlock && RenderBlocks.renderItemIn3d(Block.getBlockFromItem(var10.getItem()).getRenderType()))
+ {
+ Block var21 = Block.getBlockFromItem(var10.getItem());
+
+ float var25 = 0.25F*scale;
+ var24 = var21.getRenderType();
+
+ if (var24 == 1 || var24 == 19 || var24 == 12 || var24 == 2)
+ {
+ var25 = 0.5F*scale;
+ }
+
+ if (var21.getRenderBlockPass() > 0)
+ {
+ GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
+ GL11.glEnable(GL11.GL_BLEND);
+ OpenGlHelper.glBlendFunc(770, 771, 1, 0);
+ }
+
+ GL11.glScalef(var25, var25, var25);
+
+ for (int var26 = 0; var26 < var13; ++var26)
+ {
+ GL11.glPushMatrix();
+
+ if (var26 > 0)
+ {
+ var18 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.2F / var25;
+ var19 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.2F / var25;
+ float var20 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.2F / var25;
+ GL11.glTranslatef(var18, var19, var20);
+ }
+
+ this.renderBlocks.renderBlockAsItem(var21, var10.getItemDamage(), 1.0F);
+ GL11.glPopMatrix();
+ }
+
+ if (var21.getRenderBlockPass() > 0)
+ {
+ GL11.glDisable(GL11.GL_BLEND);
+ }
+ }
+ else
+ {
+ float var17;
+
+ if (var10.getItemSpriteNumber() == 1 && var10.getItem().requiresMultipleRenderPasses())
+ {
+ GL11.glScalef(0.5F*scale, 0.5F*scale, 0.5F*scale);
+
+ for (int var23 = 0; var23 <= 1; ++var23)
+ {
+ this.random.setSeed(187L);
+ IIcon var22 = var10.getItem().getIconFromDamageForRenderPass(var10.getItemDamage(), var23);
+ var24 = var10.getItem().getColorFromItemStack(var10, var23);
+ var17 = (var24 >> 16 & 255) / 255.0F;
+ var18 = (var24 >> 8 & 255) / 255.0F;
+ var19 = (var24 & 255) / 255.0F;
+ GL11.glColor4f(var17, var18, var19, 1.0F);
+ this.renderDroppedItem(renderManager, var10, var22, var13, var17, var18, var19);
+
+ }
+ }
+ else
+ {
+ if (var10 != null && var10.getItem() instanceof ItemCloth)
+ {
+ GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
+ GL11.glEnable(GL11.GL_BLEND);
+ OpenGlHelper.glBlendFunc(770, 771, 1, 0);
+ }
+ GL11.glScalef(0.5F*scale, 0.5F*scale, 0.5F*scale);
+ IIcon var14 = var10.getIconIndex();
+ int var15 = var10.getItem().getColorFromItemStack(var10, 0);
+ float var16 = (var15 >> 16 & 255) / 255.0F;
+ var17 = (var15 >> 8 & 255) / 255.0F;
+ var18 = (var15 & 255) / 255.0F;
+ this.renderDroppedItem(renderManager, var10, var14, var13, var16, var17, var18);
+ if (var10 != null && var10.getItem() instanceof ItemCloth)
+ {
+ GL11.glDisable(GL11.GL_BLEND);
+ }
+ }
+ }
+
+ GL11.glDisable(GL12.GL_RESCALE_NORMAL);
+ GL11.glPopMatrix();
+ }
+ }
+
+ private void renderDroppedItem(RenderManager renderManager, ItemStack stack, IIcon par2Icon, int par3, float par5, float par6, float par7)
+ {
+ Tessellator var8 = Tessellator.instance;
+
+ if (par2Icon == null)
+ {
+ TextureManager var9 = Minecraft.getMinecraft().getTextureManager();
+ ResourceLocation var10 = var9.getResourceLocation(stack.getItemSpriteNumber());
+ par2Icon = ((TextureMap)var9.getTexture(var10)).getAtlasSprite("missingno");
+ }
+
+ float var25 = par2Icon.getMinU();
+ float var26 = par2Icon.getMaxU();
+ float var11 = par2Icon.getMinV();
+ float var12 = par2Icon.getMaxV();
+ float var13 = 1.0F;
+ float var14 = 0.5F;
+ float var15 = 0.25F;
+ float var17;
+
+ if (renderManager.options.fancyGraphics)
+ {
+ GL11.glPushMatrix();
+
+ //GL11.glRotatef((this.random .nextFloat() * 2.0F - 1.0F) * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
+
+ float var16 = 0.0625F;
+ var17 = 0.021875F;
+ ItemStack var18 = stack;
+ int var19 = var18.stackSize;
+ byte var24;
+
+ if (var19 < 2)
+ {
+ var24 = 1;
+ }
+ else if (var19 < 16)
+ {
+ var24 = 2;
+ }
+ else if (var19 < 32)
+ {
+ var24 = 3;
+ }
+ else
+ {
+ var24 = 4;
+ }
+
+ GL11.glTranslatef(-var14, -var15, -((var16 + var17) * var24 / 2.0F));
+
+ for (int var20 = 0; var20 < var24; ++var20)
+ {
+ GL11.glTranslatef(0.0F, 0.0F, var16 + var17);
+
+ if (var18.getItemSpriteNumber() == 0)
+ {
+ renderManager.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
+ }
+ else
+ {
+ renderManager.renderEngine.bindTexture(TextureMap.locationItemsTexture);
+ }
+
+ GL11.glColor4f(par5, par6, par7, 1.0F);
+ ItemRenderer.renderItemIn2D(var8, var26, var11, var25, var12, par2Icon.getIconWidth(), par2Icon.getIconHeight(), var16);
+ }
+
+ GL11.glPopMatrix();
+ }
+ else
+ {
+ for (int var27 = 0; var27 < par3; ++var27)
+ {
+ GL11.glPushMatrix();
+
+ if (var27 > 0)
+ {
+ var17 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F;
+ float var29 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F;
+ float var28 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F;
+ GL11.glTranslatef(var17, var29, var28);
+ }
+ if(!noRotation)
+ {
+ GL11.glRotatef(180.0F - renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
+ }
+ GL11.glColor4f(par5, par6, par7, 1.0F);
+ var8.startDrawingQuads();
+ var8.setNormal(0.0F, 1.0F, 0.0F);
+ var8.addVertexWithUV(0.0F - var14, 0.0F - var15, 0.0D, var25, var12);
+ var8.addVertexWithUV(var13 - var14, 0.0F - var15, 0.0D, var26, var12);
+ var8.addVertexWithUV(var13 - var14, 1.0F - var15, 0.0D, var26, var11);
+ var8.addVertexWithUV(0.0F - var14, 1.0F - var15, 0.0D, var25, var11);
+ var8.draw();
+ GL11.glPopMatrix();
+ }
+ }
+ }
+
+}
diff --git a/ihl/utils/IHLMathUtils.java b/ihl/utils/IHLMathUtils.java
new file mode 100644
index 0000000..cfd6931
--- /dev/null
+++ b/ihl/utils/IHLMathUtils.java
@@ -0,0 +1,48 @@
+package ihl.utils;
+
+public class IHLMathUtils
+{
+ private final static int accuracy_level=65536;
+ private static float[] sin_table=new float[accuracy_level];
+ private static float[] atan_table=new float[accuracy_level];
+ private final static float PI=(float)Math.PI;
+
+ public static float sin(float angle)
+ {
+ float angle1 = angle % (2*PI);
+ if(angle1<0)
+ {
+ angle1+=2*PI;
+ }
+ return sin_table[(int)(angle1*accuracy_level/2/PI)];
+ }
+
+ public static float atan(float tan_value)
+ {
+ if(tan_value<-32f)
+ {
+ return -1.54f;
+ }
+ else if(tan_value>32f)
+ {
+ return 1.54f;
+ }
+ else
+ {
+ return atan_table[(int)((tan_value+32f)*accuracy_level/64f)];
+ }
+ }
+
+
+ static
+ {
+ for(int i=0;i<accuracy_level;i++)
+ {
+ sin_table[i]=(float) Math.sin(2d*Math.PI*i/accuracy_level);
+ }
+ for(int i=0;i<accuracy_level;i++)
+ {
+ atan_table[i]=(float) Math.atan(-32d+64d*i/accuracy_level);
+ }
+ }
+}
diff --git a/ihl/utils/IHLRenderUtils.java b/ihl/utils/IHLRenderUtils.java
new file mode 100644
index 0000000..6cf8fa8
--- /dev/null
+++ b/ihl/utils/IHLRenderUtils.java
@@ -0,0 +1,820 @@
+package ihl.utils;
+
+import java.nio.FloatBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.lwjgl.opengl.GL11;
+
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import ic2.core.util.DrawUtil;
+import ihl.IHLMod;
+import net.minecraft.block.Block;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.ScaledResolution;
+import net.minecraft.client.gui.inventory.GuiContainer;
+import net.minecraft.client.multiplayer.WorldClient;
+import net.minecraft.client.renderer.GLAllocation;
+import net.minecraft.client.renderer.RenderBlocks;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.client.renderer.texture.TextureMap;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.IIcon;
+import net.minecraft.util.MovingObjectPosition;
+import net.minecraft.util.StatCollector;
+import net.minecraftforge.client.event.DrawBlockHighlightEvent;
+import net.minecraftforge.common.util.ForgeDirection;
+import net.minecraftforge.fluids.Fluid;
+import net.minecraftforge.fluids.FluidStack;
+
+public class IHLRenderUtils
+{
+ private FloatBuffer colorBuffer;
+ private Map<Long, Integer> frameTooltipMap;
+ private int displayScaledWidth=-1;
+ private int displayScaledHeight=-1;
+ private int guiXPos=-1;
+ private int guiYPos=-1;
+ private int prevDisplayWidth=-1;
+ private int prevDisplayHeight=-1;
+ private final int guiContainerWidth = 166;
+ private final int guiContainerHeight = 176;
+ private float lastPlayerYaw;
+ private float lastPlayerPitch;
+ private double lastPlayerPosY;
+ private double lastPlayerPosZ;
+ private double lastPlayerPosX;
+ private double renderMinX=0d;
+ private double renderMaxX=1d;
+ private double renderMinY=0d;
+ private double renderMaxY=1d;
+ private double renderMinZ=0d;
+ private double renderMaxZ=1d;
+ public boolean renderFromInside=false;
+ private float rotationPointX;
+ private float rotationPointY;
+ private float rotationPointZ;
+ private double renderPositionX;
+ private double renderPositionY;
+ private double renderPositionZ;
+ private float rotationX;
+ private float rotationY;
+ private float rotationZ;
+ private float scale=1/16f;
+ public boolean swapXandZ=false;
+ public boolean swapXandY=false;
+ public boolean swapYandZ=false;
+ public boolean swapRenderBoundsX=false;
+ public boolean swapRenderBoundsY=false;
+ public boolean swapRenderBoundsZ=false;
+ public int scaleFactor=1;
+ public static IHLRenderUtils instance;
+
+ public IHLRenderUtils()
+ {
+ instance=this;
+ colorBuffer = GLAllocation.createDirectFloatBuffer(16);
+ frameTooltipMap = new HashMap();
+ }
+
+ public void renderIHLFluidTank(IHLFluidTank fluidTank, int x1, int y1, int x2, int y2, float zLevel, int par1, int par2, int xOffset, int yOffset)
+ {
+ int liquidHeight = 0;
+ int prevLiquidHeight = 0;
+ int i = y2-y1;
+ Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
+ GL11.glEnable(GL11.GL_BLEND);
+ GL11.glColor4f(1f, 1f, 1f, 1f);
+ for(int i2 = 0;i2<fluidTank.getNumberOfFluids();i2++)
+ {
+ FluidStack fluidStack = fluidTank.getFluid(i2);
+ if(fluidStack!=null)
+ {
+ Fluid fluid = fluidStack.getFluid();
+ if(fluid!=null)
+ {
+ IIcon fluidIcon = fluid.getIcon();
+ if (fluidIcon != null)
+ {
+ liquidHeight = fluidTank.getFluidAmount(i2) * i /fluidTank.getCapacity();
+ DrawUtil.drawRepeated(fluidIcon, x1, y2 - liquidHeight-prevLiquidHeight, x2-x1, liquidHeight, zLevel);
+ prevLiquidHeight+=liquidHeight;
+ }
+ }
+ }
+ }
+ drawIHLFluidTankTooltip(par1, par2, x1+guiXPos-6, y1+guiYPos+6, x2+guiXPos-6, y2+guiYPos+6, fluidTank);
+ }
+
+ public void drawMissingEngineTooltip(GuiContainer gui, int par1, int par2, int xPos, int yPos, int xOffset, int yOffset)
+ {
+ gui.drawTexturedModalRect(xPos, yPos, 194, 0, 3, 14);
+ drawTooltip(par1,par2,3,14,xPos+xOffset,yPos+yOffset,StatCollector.translateToLocal("ihl.gui.missing.engine"));
+ }
+
+ public void drawWorkspaceElementTooltip(int par1, int par2, int xPos, int yPos, ItemStack workSpaceElement)
+ {
+ drawTooltip(par1,par2,16,16,xPos,yPos,StatCollector.translateToLocal(workSpaceElement.getUnlocalizedName()+".tooltip"));
+ }
+
+ public void drawIHLFluidTankTooltip(int par1, int par2, int x1, int y1, int x2, int y2, IHLFluidTank fluidTank)
+ {
+ String fluidListNames="";
+ List<FluidStack> fli = fluidTank.getFluidList();
+ for(int i=fli.size()-1;i>=0;i--)
+ {
+ FluidStack fluidStack = fli.get(i);
+ fluidListNames+=StatCollector.translateToLocal(fluidStack.getUnlocalizedName())+": "+fluidStack.amount+"mB /n ";
+ }
+ drawTooltip(par1,par2,x2-x1,y2-y1,x1,y1,fluidListNames);
+ }
+
+ public boolean drawTooltip(int cursorPosX, int cursorPosY, int width, int height, int xPos, int yPos, String text)
+ {
+ updateScreenSize();
+ long key = xPos+yPos*1024;
+ Integer frame=0;
+ if(frameTooltipMap.containsKey(key))
+ {
+ frame=frameTooltipMap.get(key);
+ }
+ boolean showString=true;
+ if(cursorPosX<xPos || cursorPosX>xPos+width||
+ cursorPosY<yPos || cursorPosY>yPos+height)
+ {
+ if(frame>0)
+ {
+ frame-=20;
+ frameTooltipMap.put(key, frame);
+ }
+ showString=false;
+ }
+ else
+ {
+ frame+=10;
+ frameTooltipMap.put(key, frame);
+ }
+ if(frame>0)
+ {
+ int strokeHeight=15;
+ int i,x1,x2,y1,y2,tooltipWidth,tooltipHeight;
+ tooltipWidth=tooltipHeight=0;
+ String[] splittedText = text.split(" /n ");
+ for(i=0;i<splittedText.length;i++)
+ {
+ if(Minecraft.getMinecraft().fontRenderer.getStringWidth(splittedText[i])+8>tooltipWidth)
+ {
+ tooltipWidth=Math.min(frame,Minecraft.getMinecraft().fontRenderer.getStringWidth(splittedText[i])+8);
+ }
+ }
+ tooltipHeight=Math.min(Math.max(frame-tooltipWidth,strokeHeight),strokeHeight*splittedText.length);
+ x1=cursorPosX-xPos;
+ x2=x1+tooltipWidth;
+ y1=cursorPosY-guiYPos+18;
+ y2=y1+tooltipHeight;
+ GL11.glPushAttrib(16704);
+ GL11.glDisable(GL11.GL_DEPTH_TEST);
+ GL11.glDisable(GL11.GL_TEXTURE_2D);
+ GL11.glEnable(GL11.GL_BLEND);
+ GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
+ if(showString)
+ {
+ drawRectangle(Tessellator.instance, x1,y1,x2,y2,128);
+ GL11.glEnable(GL11.GL_TEXTURE_2D);
+ for(i=0;i<splittedText.length;i++)
+ {
+ if(i<tooltipHeight/strokeHeight)
+ {
+ Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(splittedText[i], x1+4, y1+i*strokeHeight+4, 16768125);
+ }
+ }
+ }
+ else
+ {
+ drawRectangle(Tessellator.instance, x1,y1,x2,y2,Math.min(128,frame/2));
+ GL11.glEnable(GL11.GL_TEXTURE_2D);
+ }
+ GL11.glPopAttrib();
+ frame=Math.min(tooltipWidth+tooltipHeight,frame);
+ frameTooltipMap.put(key, frame);
+ return true;
+ }
+ return false;
+ }
+
+ public void enableAmbientLighting()
+ {
+ GL11.glDisable(GL11.GL_LIGHT0);
+ GL11.glDisable(GL11.GL_LIGHT1);
+ GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, setColorBuffer(1.0f, 1.0f, 1.0f, 1.0F));
+ }
+
+ public void disableAmbientLighting()
+ {
+ GL11.glEnable(GL11.GL_LIGHT0);
+ GL11.glEnable(GL11.GL_LIGHT1);
+ GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, setColorBuffer(0.0f, 0.0f, 0.0f, 1.0F));
+ }
+
+ /**
+ * Update and return colorBuffer with the RGBA values passed as arguments
+ */
+ private FloatBuffer setColorBuffer(float par0, float par1, float par2, float par3)
+ {
+ colorBuffer.clear();
+ colorBuffer.put(par0).put(par1).put(par2).put(par3);
+ colorBuffer.flip();
+ return colorBuffer;
+ }
+
+ private void drawRectangle(Tessellator tessellator, int x1, int y1, int x2, int y2, int color)
+ {
+ tessellator.startDrawingQuads();
+ tessellator.setColorRGBA(color >>> 24 & 255, color >>> 16 & 255, color >>> 8 & 255, color & 255);
+ tessellator.addVertex(x2, y1, 300.0D);
+ tessellator.addVertex(x1, y1, 300.0D);
+ tessellator.addVertex(x1, y2, 300.0D);
+ tessellator.addVertex(x2, y2, 300.0D);
+ tessellator.draw();
+ }
+
+ public void drawThermometerTemperature(long temperature, boolean show)
+ {
+ updateScreenSize();
+ long key = 0;
+ int frame=0;
+ if(frameTooltipMap.containsKey(key))
+ {
+ frame=frameTooltipMap.get(key);
+ }
+ if(frame<=0)
+ {
+ updatePlayerView();
+ }
+ boolean showString=true;
+ if(show && frame<=122)
+ {
+ frame+=1;
+ frameTooltipMap.put(key, frame);
+ }
+ else
+ {
+ if(frame>0)
+ {
+ frame-=2;
+ frameTooltipMap.put(key, frame);
+ }
+ showString=false;
+ }
+ if(frame>0)
+ {
+ int width=Math.min(frame, 122);
+ int height=Math.min(frame, 48);
+ int xShift = Math.round(displayScaledWidth/100*(lastPlayerYaw - Minecraft.getMinecraft().renderViewEntity.prevRotationYaw));
+ int yShift = Math.round(displayScaledHeight/64*(lastPlayerPitch - Minecraft.getMinecraft().renderViewEntity.prevRotationPitch));
+ int xPos = displayScaledWidth/2+xShift;
+ int yPos = displayScaledHeight/2-48+yShift;
+ GL11.glEnable(GL11.GL_BLEND);
+ GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
+ drawTexturedModalRect(xPos,yPos,0,0,width,height);
+ GL11.glDisable(GL11.GL_DEPTH_TEST);
+ if(showString)
+ {
+ Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(temperature+"\u00B0K", xPos+35, yPos+3, 16768125);
+ }
+ GL11.glEnable(GL11.GL_DEPTH_TEST);
+ GL11.glDisable(GL11.GL_BLEND);
+ }
+ }
+
+ public void drawTexturedModalRect(int x1, int y1, int u, int v, int x2, int y2) {
+ float f = 0.00390625F;
+ float f1 = 0.00390625F;
+ Tessellator tessellator = Tessellator.instance;
+ tessellator.startDrawingQuads();
+ tessellator.setColorRGBA_F(1f, 1f, 1f, 0.5f);
+ tessellator.addVertexWithUV(x1 + 0, y1 + y2, 300D, (u + 0) * f, (v + y2) * f1);
+ tessellator.addVertexWithUV(x1 + x2, y1 + y2, 300D, (u + x2) * f, (v + y2) * f1);
+ tessellator.addVertexWithUV(x1 + x2, y1 + 0, 300D, (u + x2) * f, (v + 0) * f1);
+ tessellator.addVertexWithUV(x1 + 0, y1 + 0, 300D, (u + 0) * f, (v + 0) * f1);
+ tessellator.draw();
+ }
+
+
+ public void updateScreenSize()
+ {
+ if(prevDisplayHeight!=Minecraft.getMinecraft().displayHeight || prevDisplayWidth!=Minecraft.getMinecraft().displayWidth)
+ {
+ ScaledResolution var2 = new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
+ displayScaledWidth = var2.getScaledWidth();
+ displayScaledHeight = var2.getScaledHeight();
+ scaleFactor=var2.getScaleFactor();
+ guiXPos = (displayScaledWidth - guiContainerWidth)/2;
+ guiYPos = (displayScaledHeight - guiContainerHeight)/2;
+ prevDisplayWidth=Minecraft.getMinecraft().displayWidth;
+ prevDisplayHeight=Minecraft.getMinecraft().displayHeight;
+ }
+ }
+
+ public void updatePlayerView()
+ {
+ lastPlayerYaw = Minecraft.getMinecraft().renderViewEntity.prevRotationYaw;
+ lastPlayerPitch = Minecraft.getMinecraft().renderViewEntity.prevRotationPitch;
+ lastPlayerPosX = Minecraft.getMinecraft().renderViewEntity.prevPosX;
+ lastPlayerPosY = Minecraft.getMinecraft().renderViewEntity.prevPosY;
+ lastPlayerPosZ = Minecraft.getMinecraft().renderViewEntity.prevPosZ;
+ }
+
+ public void drawKnee(double xPos, double yPos, double zPos, ForgeDirection direction12, ForgeDirection direction22, double radius1, double radius2, IIcon icon)
+ {
+ ForgeDirection direction1=direction12;
+ ForgeDirection direction2=direction22;
+ if(this.swapRenderBoundsX)
+ {
+ if(direction1.offsetX!=0)
+ {
+ direction1=direction1.getOpposite();
+ }
+ if(direction2.offsetX!=0)
+ {
+ direction2=direction2.getOpposite();
+ }
+ }
+ if(this.swapRenderBoundsY)
+ {
+ if(direction1.offsetY!=0)
+ {
+ direction1=direction1.getOpposite();
+ }
+ if(direction2.offsetY!=0)
+ {
+ direction2=direction2.getOpposite();
+ }
+ }
+ if(this.swapRenderBoundsZ)
+ {
+ if(direction1.offsetZ!=0)
+ {
+ direction1=direction1.getOpposite();
+ }
+ if(direction2.offsetZ!=0)
+ {
+ direction2=direction2.getOpposite();
+ }
+ }
+ double[][] outervertexes1 = new double[8][3];
+ double[][] innervertexes1 = new double[8][3];
+ double[][] outervertexes2 = new double[8][3];
+ double[][] innervertexes2 = new double[8][3];
+ int i=0;
+ for(i=0;i<8;i++)
+ {
+ if(direction1.equals(direction2))
+ {
+ switch(direction1)
+ {
+ case UP:
+ outervertexes1[i] = new double[] {0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i)};
+ innervertexes1[i] = new double[] {0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i)};
+ outervertexes2[i] = new double[] {0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i)};
+ innervertexes2[i] = new double[] {0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*radius1*(float)Math.sin(2D*Math.PI/8D*i)};
+ break;
+ case DOWN:
+ outervertexes1[i] = new double[] {0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i)};
+ innervertexes1[i] = new double[] {0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.5F*radius1*radius2*(float)Math.sin(2D*Math.PI/8D*i)};
+ outervertexes2[i] = new double[] {0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i)};
+ innervertexes2[i] = new double[] {0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i)};
+ break;
+ case SOUTH:
+ outervertexes1[i] = new double[] {0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i), 1d};
+ innervertexes1[i] = new double[] {0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 1d};
+ outervertexes2[i] = new double[] {0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i), 0d};
+ innervertexes2[i] = new double[] {0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*radius1*radius2*(float)Math.sin(2D*Math.PI/8D*i), 0d};
+ break;
+ case NORTH:
+ outervertexes1[i] = new double[] {0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i), 1d};
+ innervertexes1[i] = new double[] {0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*radius1*radius2*(float)Math.sin(2D*Math.PI/8D*i), 1d};
+ outervertexes2[i] = new double[] {0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i), 0d};
+ innervertexes2[i] = new double[] {0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0d};
+ break;
+ case EAST:
+ outervertexes1[i] = new double[] {0d, 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i)};
+ innervertexes1[i] = new double[] {0d, 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i)};
+ outervertexes2[i] = new double[] {1d, 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i)};
+ innervertexes2[i] = new double[] {1d, 0.5F+0.5F*radius1*radius2*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i)};
+ break;
+ case WEST:
+ outervertexes1[i] = new double[] {0d, 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i)};
+ innervertexes1[i] = new double[] {0d, 0.5F+0.5F*radius2*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+radius1*0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i)};
+ outervertexes2[i] = new double[] {1d, 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i)};
+ innervertexes2[i] = new double[] {1d, 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i)};
+ break;
+ default:
+ outervertexes1[i] = new double[] {0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i)};
+ innervertexes1[i] = new double[] {0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i)};
+ outervertexes2[i] = new double[] {0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i)};
+ innervertexes2[i] = new double[] {0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*radius1*(float)Math.sin(2D*Math.PI/8D*i)};
+ break;
+ }
+
+ }
+ else
+ {
+ switch(direction1)
+ {
+ case UP:
+ outervertexes1[i] = new double[] {0.5F+0.25F*radius2*(float)Math.cos(2D*Math.PI/8D*i+Math.PI), 1d, 0.5F-0.25F*radius2*(float)Math.sin(2D*Math.PI/8D*i+Math.PI)};
+ innervertexes1[i] = new double[] {0.5F+radius1*radius2*0.25F*(float)Math.cos(2D*Math.PI/8D*i+Math.PI), 1d, 0.5F-0.25F*radius1*radius2*(float)Math.sin(2D*Math.PI/8D*i+Math.PI)};
+ break;
+ case DOWN:
+ outervertexes1[i] = new double[] {0.5F+0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.25F*(float)Math.sin(2D*Math.PI/8D*i)};
+ innervertexes1[i] = new double[] {0.5F+radius1*0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.25F*radius1*(float)Math.sin(2D*Math.PI/8D*i)};
+ break;
+ case SOUTH:
+ outervertexes1[i] = new double[] {0.5F+0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*(float)Math.sin(2D*Math.PI/8D*i), 1d};
+ innervertexes1[i] = new double[] {0.5F+radius1*0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 1d};
+ break;
+ case NORTH:
+ outervertexes1[i] = new double[] {0.5F+0.25F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*radius2*(float)Math.sin(2D*Math.PI/8D*i), 1d};
+ innervertexes1[i] = new double[] {0.5F+radius1*radius2*0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*radius1*radius2*(float)Math.sin(2D*Math.PI/8D*i), 1d};
+ break;
+ case EAST:
+ outervertexes1[i] = new double[] {0d, 0.5F+0.25F*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+0.25F*(float)Math.cos(2D*Math.PI/8D*i)};
+ innervertexes1[i] = new double[] {0d, 0.5F+0.25F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+radius1*0.25F*(float)Math.cos(2D*Math.PI/8D*i)};
+ break;
+ case WEST:
+ outervertexes1[i] = new double[] {0d, 0.5F+0.25F*radius2*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+0.52F*radius2*(float)Math.cos(2D*Math.PI/8D*i)};
+ innervertexes1[i] = new double[] {0d, 0.5F+0.25F*radius2*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+radius1*0.25F*radius2*(float)Math.cos(2D*Math.PI/8D*i)};
+ break;
+ default:
+ outervertexes1[i] = new double[] {0d, 0.5F+0.25F*radius2*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+0.52F*radius2*(float)Math.cos(2D*Math.PI/8D*i)};
+ innervertexes1[i] = new double[] {0d, 0.5F+0.25F*radius2*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+radius1*0.25F*radius2*(float)Math.cos(2D*Math.PI/8D*i)};
+ break;
+ }
+
+ switch(direction2)
+ {
+ case UP:
+ outervertexes2[i] = new double[] {0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i)};
+ innervertexes2[i] = new double[] {0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*radius1*(float)Math.sin(2D*Math.PI/8D*i)};
+ break;
+ case DOWN:
+ outervertexes2[i] = new double[] {0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i)};
+ innervertexes2[i] = new double[] {0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i)};
+ break;
+ case WEST:
+ outervertexes2[i] = new double[] {1d, 0.5F+0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F-0.25F*(float)Math.sin(2D*Math.PI/8D*i)};
+ innervertexes2[i] = new double[] {1d, 0.5F+radius1*0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F-0.25F*radius1*(float)Math.sin(2D*Math.PI/8D*i)};
+ break;
+ case EAST:
+ outervertexes2[i] = new double[] {0d, 0.5F+0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*(float)Math.sin(2D*Math.PI/8D*i)};
+ innervertexes2[i] = new double[] {0d, 0.5F+radius1*0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*radius1*(float)Math.sin(2D*Math.PI/8D*i)};
+ break;
+ case NORTH:
+ outervertexes2[i] = new double[] {0.5F+0.25F*(float)Math.cos(2D*Math.PI/8D*i), 1d-0.5F-0.25F*(float)Math.sin(2D*Math.PI/8D*i), 1d};
+ innervertexes2[i] = new double[] {0.5F+radius1*0.25F*(float)Math.cos(2D*Math.PI/8D*i), 1d-0.5F-0.25F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 1d};
+ break;
+ case SOUTH:
+ outervertexes2[i] = new double[] {0.5F+0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*(float)Math.sin(2D*Math.PI/8D*i), 0d};
+ innervertexes2[i] = new double[] {0.5F+radius1*0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0d};
+ break;
+ default:
+ outervertexes2[i] = new double[] {0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i)};
+ innervertexes2[i] = new double[] {0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*radius1*(float)Math.sin(2D*Math.PI/8D*i)};
+ break;
+ }
+
+ }
+ }
+ double[][][] quadList = new double[32][4][3];
+ for(i=0;i<32;i++)
+ {
+ if(i<7)
+ {
+ quadList[i]=new double[][] {outervertexes1[i],outervertexes1[i+1],innervertexes1[i+1],innervertexes1[i]};
+ }
+ else if(i==7)
+ {
+ quadList[i]=new double[][] {outervertexes1[i],outervertexes1[0],innervertexes1[0],innervertexes1[i]};
+ }
+ else if(i<15)
+ {
+ quadList[i]=new double[][] {innervertexes2[i-8],innervertexes2[i+1-8],outervertexes2[i+1-8],outervertexes2[i-8]};
+ }
+ else if(i==15)
+ {
+ quadList[i]=new double[][] {innervertexes2[i-8],innervertexes2[0],outervertexes2[0],outervertexes2[i-8]};
+ }
+ else if(i<23)
+ {
+ quadList[i]=new double[][] {outervertexes1[i-16],outervertexes2[i-16],outervertexes2[i-16+1],outervertexes1[i-16+1]};
+ }
+ else if(i==23)
+ {
+ quadList[i]=new double[][] {outervertexes1[i-16],outervertexes2[i-16],outervertexes2[0],outervertexes1[0]};
+ }
+ else if(i<31)
+ {
+ quadList[i]=new double[][] {innervertexes1[i-24+1],innervertexes2[i-24+1], innervertexes2[i-24], innervertexes1[i-24]};
+ }
+ else if(i==31)
+ {
+ quadList[i]=new double[][] {innervertexes1[0],innervertexes2[0],innervertexes2[i-24],innervertexes1[i-24]};
+ }
+ }
+ for(i=0;i<32;i++)
+ {
+ this.drawSquare(xPos, yPos, zPos, quadList[i], icon);
+ }
+
+
+ }
+ public void drawPipe(double xPos, double yPos, double zPos, ForgeDirection direction1, double radius1, double radius2, IIcon icon)
+ {
+ this.drawKnee(xPos, yPos, zPos, direction1, direction1, radius1, radius2, icon);
+ }
+
+ public void drawSquare(double xPos, double yPos, double zPos, double[][] vertexes, IIcon icon)
+ {
+ Tessellator var9 = Tessellator.instance;
+ double u1 = icon.getInterpolatedU(this.renderMinZ * 16.0D);
+ double u2 = icon.getInterpolatedU(this.renderMaxZ * 16.0D);
+ double v2 = icon.getInterpolatedV(16.0D - this.renderMaxY * 16.0D);
+ double v1 = icon.getInterpolatedV(16.0D - this.renderMinY * 16.0D);
+ if (this.renderMinZ < 0.0D || this.renderMaxZ > 1.0D)
+ {
+ u1 = icon.getMinU();
+ u2 = icon.getMaxU();
+ }
+ if (this.renderMinY < 0.0D || this.renderMaxY > 1.0D)
+ {
+ v2 = icon.getMinV();
+ v1 = icon.getMaxV();
+ }
+ double[] us = new double[]{u1,u1,u2,u2};
+ double[] vs = new double[]{v1,v2,v2,v1};
+ double xDelta=this.renderMaxX-this.renderMinX;
+ double yDelta=this.renderMaxY-this.renderMinY;
+ double zDelta=this.renderMaxZ-this.renderMinZ;
+ int startFrom=0;
+ int endTo=3;
+ if(this.renderFromInside)
+ {
+ startFrom=3;
+ endTo=0;
+ }
+ for(int i=startFrom;(i<=endTo&&!this.renderFromInside)||(i>=endTo&&this.renderFromInside);i+=(endTo-startFrom)/3)
+ {
+ double vX=vertexes[i][0]*xDelta+this.renderMinX;
+ double vY=vertexes[i][1]*yDelta+this.renderMinY;
+ double vZ=vertexes[i][2]*zDelta+this.renderMinZ;
+ double[] vYZ=null;
+ double[] vXZ=null;
+ double[] vXY=null;
+ if(this.rotationX!=0)
+ {
+ vYZ = this.rotateCoordinateByAngle(vY-(this.rotationPointY-8f)*scale, vZ-(this.rotationPointZ+8f)*scale, this.rotationX);
+ vY=vYZ[0]+(this.rotationPointY-8f)*scale;
+ vZ=vYZ[1]+(this.rotationPointZ+8f)*scale;
+ }
+ if(this.rotationY!=0)
+ {
+ vXZ = this.rotateCoordinateByAngle(vX-(this.rotationPointX+8f)*scale, vZ-(this.rotationPointZ+8f)*scale, this.rotationY);
+ vX=vXZ[0]+(this.rotationPointX+8f)*scale;
+ vZ=vXZ[1]-(this.rotationPointZ+8f)*scale;
+ }
+ if(this.rotationZ!=0)
+ {
+ vXY = this.rotateCoordinateByAngle(vX-(this.rotationPointX+8f)*scale, vY-(this.rotationPointY-8f)*scale, this.rotationZ);
+ vX=vXY[0]+(this.rotationPointX+8f)*scale;
+ vY=vXY[1]+(this.rotationPointY-8f)*scale;
+ if(swappingAxisOrBoundsAffectRotationOnAxisZ())
+ {
+ vY-=(this.renderMaxZ-(this.rotationPointZ+8f))*scale*Math.sin(this.rotationZ);
+ }
+ }
+ if(this.swapXandY)
+ {
+ double var0 = vX;
+ vX=vY;
+ vY=var0;
+ }
+ if(this.swapXandZ)
+ {
+ double var0 = vX;
+ vX=vZ;
+ vZ=var0;
+ }
+ if(this.swapYandZ)
+ {
+ double var0 = vY;
+ vY=vZ;
+ vZ=var0;
+ }
+ var9.addVertexWithUV(xPos+vX, yPos+vY, zPos+vZ, us[i], vs[i]);
+ }
+ }
+
+ public void setRenderBounds(double minX, double minY, double minZ, double maxX, double maxY, double maxZ)
+ {
+ if(this.swapRenderBoundsX)
+ {
+ this.renderMinX = 1-maxX;
+ this.renderMaxX = 1-minX;
+ }
+ else
+ {
+ this.renderMinX = minX;
+ this.renderMaxX = maxX;
+ }
+ if(this.swapRenderBoundsY)
+ {
+ this.renderMinY = 1-maxY;
+ this.renderMaxY = 1-minY;
+ }
+ else
+ {
+ this.renderMinY = minY;
+ this.renderMaxY = maxY;
+ }
+ if(this.swapRenderBoundsZ)
+ {
+ this.renderMinZ = 1-maxZ;
+ this.renderMaxZ = 1-minZ;
+ }
+ else
+ {
+ this.renderMinZ = minZ;
+ this.renderMaxZ = maxZ;
+ }
+ }
+
+ public void setRotationPoint(float rX, float rY, float rZ)
+ {
+ this.rotationPointX=rX;
+ this.rotationPointY=rY;
+ this.rotationPointZ=rZ;
+ }
+
+ public void setPosition(double xPos, double yPos, double zPos)
+ {
+ this.renderPositionX=xPos;
+ this.renderPositionY=yPos;
+ this.renderPositionZ=zPos;
+ }
+
+ public void drawPipe(float fx,float fy,float fz, int xSize,int ySize,int zSize, float radius1, float radius2, ForgeDirection direction, IIcon icon)
+ {
+ this.setRenderBoundsFromModel(fx, fy, fz, xSize, ySize, zSize);
+ this.drawPipe(renderPositionX,renderPositionY, renderPositionZ, direction, radius1, radius2, icon);
+ }
+
+ public void drawKnee(float fx,float fy,float fz, int xSize,int ySize,int zSize, float radius1, float radius2, ForgeDirection direction1, ForgeDirection direction2, IIcon icon)
+ {
+ this.setRenderBoundsFromModel(fx, fy, fz, xSize, ySize, zSize);
+ this.drawKnee(renderPositionX,renderPositionY, renderPositionZ, direction1, direction2, radius1, radius2, icon);
+ }
+
+ public void drawBox(float fx,float fy,float fz, int xSize,int ySize,int zSize, Block block, int meta, RenderBlocks blockRenderer)
+ {
+ this.setRenderBoundsFromModel(fx, fy, fz, xSize, ySize, zSize);
+ blockRenderer.renderStandardBlock(block, (int)this.renderPositionX, (int)this.renderPositionY, (int)this.renderPositionZ);
+ }
+
+ public void setRenderBoundsFromModel(float fx,float fy,float fz, int xSize,int ySize,int zSize)
+ {
+ float boundMinX=(-this.rotationPointX+8f-fx-xSize)*scale;
+ float boundMaxX=(-this.rotationPointX+8f-fx)*scale;
+ float boundMinZ=(-this.rotationPointZ+8f-fz-zSize)*scale;
+ float boundMaxZ=(-this.rotationPointZ+8f-fz)*scale;
+ float boundMinY=(this.rotationPointY-8f-fy-ySize)*scale;
+ float boundMaxY=(this.rotationPointY-8f-fy)*scale;
+ this.setRenderBounds(boundMinX, boundMinY, boundMinZ, boundMaxX, boundMaxY, boundMaxZ);
+ }
+
+ public double[] rotateCoordinateByAngle(double coord1, double coord2, double angle)
+ {
+ double r = Math.sqrt(coord2*coord2+coord1*coord1);
+ double alpha0=Math.asin(coord2/r);
+ if(coord1<0d)
+ {
+ alpha0=Math.PI-Math.asin(coord2/r);
+ }
+ double alpha2=alpha0+angle;
+ double coord21=Math.sin(alpha2)*r;
+ double coord11=Math.cos(alpha2)*r;
+ return new double[]{coord11,coord21};
+ }
+
+ public void setRotation(float rotationX1, float rotationY1, float rotationZ1)
+ {
+ if(this.swapRenderBoundsX)
+ {
+ this.rotationX=-rotationX1;
+ }
+ else
+ {
+ this.rotationX=rotationX1;
+ }
+ if(this.swapRenderBoundsY)
+ {
+ this.rotationY=-rotationY1;
+ }
+ else
+ {
+ this.rotationY=rotationY1;
+ }
+ if(swappingAxisOrBoundsAffectRotationOnAxisZ())
+ {
+ this.rotationZ=-rotationZ1;
+ }
+ else
+ {
+ this.rotationZ=rotationZ1;
+ }
+// this.rotationX=rotationX1;
+ // this.rotationY=rotationY1;
+ //this.rotationZ=rotationZ1;
+ }
+
+ public void reset()
+ {
+ this.renderFromInside=false;
+ this.swapXandZ=false;
+ this.swapXandY=false;
+ this.swapYandZ=false;
+ this.swapRenderBoundsX=false;
+ this.swapRenderBoundsY=false;
+ this.swapRenderBoundsZ=false;
+ this.setRotation(0f, 0f, 0f);
+ this.setRotationPoint(0f, 0f, 0f);
+ }
+
+ private boolean swappingAxisOrBoundsAffectRotationOnAxisZ()
+ {
+ return (this.swapRenderBoundsZ && !this.swapXandZ && !this.swapYandZ)||
+ (this.swapRenderBoundsX && this.swapXandZ) ||
+ (this.swapRenderBoundsY && this.swapYandZ);
+ }
+
+ public List<String> splitStringByWidth(String string, int stringWidth)
+ {
+ List<String> output = new ArrayList();
+ StringBuffer sb = new StringBuffer();
+ String[] splittedBySpaces = string.split(" ");
+ int arrayIndex=0;
+ for(String word:splittedBySpaces)
+ {
+ if(!word.contains("/n") && getStringWidth(sb)+getStringWidth(word)<stringWidth)
+ {
+ sb.append(word);
+ sb.append(" ");
+ }
+ else
+ {
+ output.add(sb.toString());
+ sb.delete(0, sb.length());
+ arrayIndex++;
+ if(!word.contains("/n"))
+ {
+ sb.append(word);
+ sb.append(" ");
+ }
+ else
+ {
+ sb.append(" ");
+ }
+ }
+ }
+ output.add(sb.toString());
+ return output;
+ }
+
+ public int getStringWidth(StringBuffer sb)
+ {
+ return getStringWidth(sb.toString());
+ }
+
+ public int getStringWidth(String sb)
+ {
+ return Minecraft.getMinecraft().fontRenderer.getStringWidth(sb);
+ }
+
+ @SubscribeEvent
+ public void drawBlockSelectionBox(DrawBlockHighlightEvent event)
+ {
+ if(event.target!=null && event.target.typeOfHit.equals(MovingObjectPosition.MovingObjectType.BLOCK))
+ {
+ WorldClient world = Minecraft.getMinecraft().theWorld;
+ TileEntity te = world.getTileEntity(event.target.blockX, event.target.blockY, event.target.blockZ);
+ if(te!=null)
+ {
+ IHLMod.proxy.renderTESpecialSelectionBox(te, event.player,event.currentItem,event.target,event.partialTicks) ;
+ }
+ }
+ }
+
+}
diff --git a/ihl/utils/IHLUtils.java b/ihl/utils/IHLUtils.java
new file mode 100644
index 0000000..b4ec4de
--- /dev/null
+++ b/ihl/utils/IHLUtils.java
@@ -0,0 +1,1110 @@
+package ihl.utils;
+
+import ic2.api.recipe.IRecipeInput;
+import ic2.api.recipe.RecipeInputItemStack;
+import ic2.api.recipe.RecipeInputOreDict;
+import ic2.api.recipe.Recipes;
+import ic2.core.BasicMachineRecipeManager;
+import ic2.core.IC2;
+import ic2.core.block.invslot.InvSlotOutput;
+import ihl.IHLMod;
+import ihl.flexible_cable.AnchorTileEntity;
+import ihl.flexible_cable.SubAnchorEnergyNetNode;
+import ihl.interfaces.ICableHolder;
+import ihl.interfaces.IEnergyNetNode;
+import ihl.interfaces.IMultiPowerCableHolder;
+import ihl.interfaces.IWire;
+import ihl.metallurgy.constants.*;
+import ihl.processing.invslots.InvSlotConsumableLiquidIHL;
+import ihl.recipes.IRecipeInputFluid;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang3.mutable.MutableObject;
+
+import cpw.mods.fml.common.registry.GameRegistry;
+import net.minecraft.block.Block;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.item.EntityItem;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.init.Blocks;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.AxisAlignedBB;
+import net.minecraft.util.MathHelper;
+import net.minecraft.util.MovingObjectPosition;
+import net.minecraft.util.Vec3;
+import net.minecraft.world.World;
+import net.minecraftforge.fluids.FluidRegistry;
+import net.minecraftforge.fluids.FluidStack;
+import net.minecraftforge.fluids.IFluidTank;
+import net.minecraftforge.oredict.OreDictionary;
+
+public class IHLUtils
+{
+ private static Map<String,ItemStack> ihlItemStackRegistry = new HashMap();
+ private static final String Digits = "(\\p{Digit}+)";
+ private static final String HexDigits = "(\\p{XDigit}+)";
+ private static final String Exp = "[eE][+-]?"+Digits;
+ private static final String fpRegex =
+ ("[\\x00-\\x20]*"+ // Optional leading "whitespace"
+ "[+-]?(" + // Optional sign character
+ "NaN|" + // "NaN" string
+ "Infinity|" + // "Infinity" string
+ "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
+ "(\\.("+Digits+")("+Exp+")?)|"+
+ "((" +
+ "(0[xX]" + HexDigits + "(\\.)?)|" +
+ "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
+ ")[pP][+-]?" + Digits + "))" +
+ "[fFdD]?))" +
+ "[\\x00-\\x20]*");// Optional trailing "whitespace"
+
+
+ public static void registerLocally(String name, ItemStack stack)
+ {
+ ihlItemStackRegistry.put(name, stack);
+ }
+
+ public static ItemStack getOreDictItemStack(String name)
+ {
+ ItemStack ore = OreDictionary.getOres(name).get(0);
+ if(ore==null)return null;
+ ItemStack orecopy = ore.copy();
+ orecopy.stackSize=1;
+ return orecopy;
+ }
+
+ public static boolean hasOreDictionaryEntry(String name)
+ {
+ return !OreDictionary.getOres(name).isEmpty();
+ }
+
+ public static Item getOreDictItem(String name)
+ {
+ return OreDictionary.getOres(name).get(0).getItem();
+ }
+
+ public static Block getOreDictBlock(String name)
+ {
+ return Block.getBlockFromItem(OreDictionary.getOres(name).get(0).getItem());
+ }
+
+ public static ItemStack getOreDictItemStackWithSize(String name, int size)
+ {
+ ItemStack ore = OreDictionary.getOres(name).get(0);
+ if(ore==null)return null;
+ ItemStack orecopy = ore.copy();
+ orecopy.stackSize=size;
+ return orecopy;
+ }
+
+ public static String getFirstOreDictName(ItemStack stack)
+ {
+ int[] arrayIDs = OreDictionary.getOreIDs(stack);
+ if(arrayIDs.length>0)
+ {
+ return OreDictionary.getOreName(arrayIDs[0]);
+ }
+ return "";
+ }
+
+ public static ItemStack getThisModItemStack(String name)
+ {
+ if(ihlItemStackRegistry.get(name)!=null)
+ {
+ return ihlItemStackRegistry.get(name).copy();
+ }
+ if(GameRegistry.findItem("ihl", name)!=null)
+ {
+ return new ItemStack(GameRegistry.findItem("ihl", name));
+ }
+ else if(GameRegistry.findBlock("ihl", name)==null)
+ {
+ throw new IllegalArgumentException("No such item in item registry: ihl:"+name);
+ }
+ else
+ {
+ return new ItemStack(GameRegistry.findBlock("ihl", name));
+ }
+ }
+
+ public static ItemStack getThisModItemStackWithSize(String name, int i) {
+ if(ihlItemStackRegistry.get(name)!=null)
+ {
+ ItemStack stack = ihlItemStackRegistry.get(name).copy();
+ stack.stackSize=i;
+ return stack;
+ }
+ if(GameRegistry.findItem("ihl", name)!=null)
+ {
+ return new ItemStack(GameRegistry.findItem("ihl", name),i);
+ }
+ else if(GameRegistry.findBlock("ihl", name)==null)
+ {
+ throw new IllegalArgumentException("No such item in item registry: ihl:"+name);
+ }
+ else
+ {
+ return new ItemStack(GameRegistry.findBlock("ihl", name),i);
+ }
+ }
+
+ public static ItemStack getOtherModItemStackWithDamage(String modname, String name,int damage) {
+ if(GameRegistry.findItem(modname, name)!=null)
+ {
+ return new ItemStack(GameRegistry.findItem(modname, name),1,damage);
+ }
+ else if(GameRegistry.findBlock(modname, name)==null)
+ {
+ return null;
+ }
+ else
+ {
+ return new ItemStack(GameRegistry.findBlock(modname, name),1,damage);
+ }
+ }
+
+ public static Item getThisModItem(String name)
+ {
+ if(GameRegistry.findItem("ihl", name)!=null)
+ {
+ return GameRegistry.findItem("ihl", name);
+ }
+ else if(GameRegistry.findBlock("ihl", name)==null)
+ {
+ throw new IllegalArgumentException("No such item in item registry: ihl:"+name);
+ }
+ else
+ {
+ return Item.getItemFromBlock(GameRegistry.findBlock("ihl", name));
+ }
+ }
+
+ public static FluidStack getFluidStackWithSize(String name, int i) {
+ if(FluidRegistry.isFluidRegistered(name))
+ {
+ return FluidRegistry.getFluidStack(name, i);
+ }
+ else
+ {
+ throw new IllegalArgumentException("No such fluid: "+name);
+ }
+ }
+
+ public static Block getThisModBlock(String name)
+ {
+ if(GameRegistry.findBlock("ihl", name)==null)
+ {
+ throw new IllegalArgumentException("No such block in item registry: ihl:"+name);
+ }
+ else
+ {
+ return GameRegistry.findBlock("ihl", name);
+ }
+ }
+
+ public static ItemStack getThisModItemStackWithDamage(String name,
+ int value)
+ {
+ ItemStack stack = getThisModItemStack(name);
+ stack.setItemDamage(value);
+ return stack;
+ }
+
+ public static boolean adjustWireLength(ItemStack stack, int adjustBy)
+ {
+ int length = getWireLength(stack);
+ if(length<=0)
+ {
+ return true;
+ }
+ else
+ {
+ int newLength = Math.max(length+adjustBy,0);
+ stack.stackTagCompound.setInteger(((IWire)stack.getItem()).getTag(),newLength);
+ stack.stackTagCompound.setInteger(((IWire)stack.getItem()).getTagSecondary(),newLength);
+ if(newLength==0)
+ {
+ return true;
+ }
+ return false;
+ }
+ }
+
+ public static int getWireLength(ItemStack itemStack)
+ {
+ return itemStack.stackTagCompound.getInteger(((IWire)itemStack.getItem()).getTag());
+ }
+
+ public static ItemStack getThisModWireItemStackWithLength(String name, int i) {
+ if(getThisModItemStack(name)!=null)
+ {
+ ItemStack stack = getThisModItemStack(name);
+ if(stack.getItem() instanceof IWire)
+ {
+ stack.stackTagCompound = new NBTTagCompound();
+ stack.stackTagCompound.setInteger(((IWire)stack.getItem()).getTag(),i);
+ stack.stackTagCompound.setInteger(((IWire)stack.getItem()).getTagSecondary(),i);
+ return stack;
+ }
+ else
+ {
+ throw new IllegalArgumentException("ihl:"+name + " is not an instance of IWire.");
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("No such item in item registry: ihl:"+name);
+ }
+ }
+
+ public static ItemStack getThisModWireItemStackWithLength(ItemStack stack1, int i) {
+ ItemStack stack = stack1.copy();
+ if(stack1.getItem() instanceof IWire)
+ {
+ stack.stackTagCompound = new NBTTagCompound();
+ stack.stackTagCompound.setInteger(((IWire)stack.getItem()).getTag(),i);
+ stack.stackTagCompound.setInteger(((IWire)stack.getItem()).getTagSecondary(),i);
+ return stack;
+ }
+ else
+ {
+ throw new IllegalArgumentException(stack1.getUnlocalizedName() + " is not an instance of IWire.");
+ }
+ }
+
+ public static boolean isItemsHaveSameOreDictionaryEntry(ItemStack is, ItemStack is1)
+ {
+ int[] odids1 = OreDictionary.getOreIDs(is);
+ int[] odids2 = OreDictionary.getOreIDs(is1);
+ if(odids1!=null && odids1.length>0 && odids2!=null && odids2.length>0)
+ {
+ for(int i1=0;i1<odids1.length;i1++)
+ {
+ for(int i2=0;i2<odids2.length;i2++)
+ {
+ if(!OreDictionary.getOreName(odids1[i1]).contains("Any") && odids1[i1]==odids2[i2])
+ {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public static List<ItemStack> getEntryListForOre(String name)
+ {
+ ArrayList<ItemStack> outputList = new ArrayList<ItemStack>();
+ ArrayList<ItemStack> oreList = OreDictionary.getOres(name);
+ Iterator<ItemStack> oreListIterator = oreList.iterator();
+ while(oreListIterator.hasNext())
+ {
+ outputList.add(oreListIterator.next().copy());
+ }
+ return outputList;
+ }
+
+ public static ItemStack getItemStackIfExist(String name)
+ {
+ if(hasOreDictionaryEntry(name))
+ {
+ return getOreDictItemStack(name);
+ }
+ else
+ {
+ if(ihlItemStackRegistry.get(name)!=null)
+ {
+ return ihlItemStackRegistry.get(name).copy();
+ }
+ if(GameRegistry.findItem("ihl", name)!=null)
+ {
+ return new ItemStack(GameRegistry.findItem("ihl", name));
+ }
+ else if(GameRegistry.findBlock("ihl", name)==null)
+ {
+ return null;
+ }
+ else
+ {
+ return new ItemStack(GameRegistry.findBlock("ihl", name));
+ }
+ }
+ }
+
+ public static FluidStack getFluidStackIfExist(String string, int meltingFluidAmount)
+ {
+ if(FluidRegistry.isFluidRegistered(string))
+ {
+ return getFluidStackWithSize(string,meltingFluidAmount);
+ }
+ return null;
+ }
+
+ public static boolean addItemStackToInventory(EntityPlayer player, ItemStack stack)
+ {
+ ItemStack[] inv = player.inventory.mainInventory;
+ for (int i=0;i<=35;i++)
+ {
+ if(inv[i]!=null)
+ {
+ if(inv[i].getItem()==stack.getItem())
+ {
+ if(inv[i].getItemDamage()==stack.getItemDamage() && inv[i].stackSize<inv[i].getMaxStackSize())
+ {
+ inv[i].stackSize+=stack.stackSize;
+ if(inv[i].stackSize>inv[i].getMaxStackSize())
+ {
+ stack.stackSize=inv[i].stackSize-inv[i].getMaxStackSize();
+ }
+ else
+ {
+ return true;
+ }
+ }
+ }
+ }
+ else
+ {
+ inv[i]=stack;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static FluidStack getFluidStackWithSizeChemicallyPure(String name, int amount)
+ {
+ FluidStack fstack = getFluidStackWithSize(name, amount);
+ fstack.tag=new NBTTagCompound();
+ fstack.tag.setBoolean("chemicallyPure", true);
+ return fstack;
+ }
+
+ public static void removeItemStackFromOreDictionaryEntry(String orename, ItemStack itemStack)
+ {
+ ArrayList<ItemStack> orelist = OreDictionary.getOres(orename);
+ Iterator<ItemStack> oreListIterator = orelist.iterator();
+ ItemStack odstack = null;
+ while(oreListIterator.hasNext())
+ {
+ odstack = oreListIterator.next();
+ if(odstack.getItem()==itemStack.getItem())
+ {
+ break;
+ }
+ else
+ {
+ odstack = null;
+ }
+ }
+ if(odstack != null)
+ {
+ orelist.remove(odstack);
+ IHLMod.log.debug("Stack "+odstack.getDisplayName()+" ("+odstack.toString()+")"+" removed from ore entry '"+orename+"'");
+ }
+ }
+
+ public static void addIC2MaceratorRecipe(String input, ItemStack output)
+ {
+ if(Recipes.macerator.getOutputFor(getOreDictItemStack(input), false)==null)
+ {
+ ((BasicMachineRecipeManager)Recipes.macerator).addRecipe(new RecipeInputOreDict(input), new NBTTagCompound(), true, output);
+ }
+ else
+ {
+ //IHLMod.log.info("IC2 macerator recipe for "+input+" already exist. Skipped.");
+ }
+ }
+
+ public static void addIC2MaceratorRecipe(String input, int stacksize, ItemStack output)
+ {
+ if(Recipes.macerator.getOutputFor(getOreDictItemStackWithSize(input,stacksize), false)==null)
+ {
+ ((BasicMachineRecipeManager)Recipes.macerator).addRecipe(new RecipeInputOreDict(input,stacksize), new NBTTagCompound(), true, output);
+ }
+ else
+ {
+ //IHLMod.log.info("IC2 macerator recipe for "+input+" already exist. Skipped.");
+ }
+ }
+
+ public static void addIC2MaceratorRecipe(ItemStack input, ItemStack output)
+ {
+ if(Recipes.macerator.getOutputFor(input, false)==null)
+ {
+ NBTTagCompound tag = new NBTTagCompound();
+ Recipes.macerator.addRecipe(new RecipeInputItemStack(input), tag, output);
+ }
+ else
+ {
+ //IHLMod.log.info("IC2 macerator recipe for "+input.getDisplayName()+" already exist. Skipped.");
+ }
+ }
+
+ public static void addIC2RollingRecipe(ItemStack input, ItemStack output)
+ {
+ if(Recipes.metalformerRolling.getOutputFor(input, false)==null)
+ {
+ NBTTagCompound tag = new NBTTagCompound();
+ Recipes.metalformerRolling.addRecipe(new RecipeInputItemStack(input), tag, output);
+ }
+ else
+ {
+ //IHLMod.log.info("IC2 metal former (rolling) recipe for "+input.getDisplayName()+" already exist. Skipped.");
+ }
+ }
+
+ public static void addIC2RollingRecipe(String input, ItemStack output)
+ {
+ if(Recipes.metalformerRolling.getOutputFor(getThisModItemStack(input), false)==null)
+ {
+ NBTTagCompound tag = new NBTTagCompound();
+ Recipes.metalformerRolling.addRecipe(new RecipeInputOreDict(input), tag, output);
+ }
+ else
+ {
+ //IHLMod.log.info("IC2 metal former (rolling) recipe for "+input+" already exist. Skipped.");
+ }
+ }
+
+ public static void addIC2CentrifugeRecipe(String input, ItemStack output, ItemStack output2)
+ {
+ if(Recipes.centrifuge.getOutputFor(getOreDictItemStack(input), false)==null)
+ {
+ NBTTagCompound tag = new NBTTagCompound();
+ tag.setInteger("minHeat", 2000);
+ Recipes.centrifuge.addRecipe(new RecipeInputOreDict(input), tag, new ItemStack[] {output,output2});
+ }
+ else
+ {
+ //IHLMod.log.info("IC2 centrifuge recipe for "+input+" already exist. Skipped.");
+ }
+ }
+
+ public static void damageItemViaNBTTag(ItemStack stack, int amount)
+ {
+ NBTTagCompound gtTagCompound;
+ if(stack.stackTagCompound.hasKey("GT.ToolStats"))
+ {
+ gtTagCompound = stack.stackTagCompound.getCompoundTag("GT.ToolStats");
+ }
+ else
+ {
+ stack.stackSize--;
+ return;
+ }
+ int damage = 0;
+ int maxDamage = 0;
+ if(gtTagCompound.hasKey("MaxDamage"))
+ {
+ maxDamage = gtTagCompound.getInteger("MaxDamage");
+ }
+ else
+ {
+ stack.stackSize--;
+ return;
+ }
+
+ if(gtTagCompound.hasKey("Damage"))
+ {
+ damage = gtTagCompound.getInteger("Damage");
+ }
+ if(damage<maxDamage-amount)
+ {
+ damage+=amount;
+ gtTagCompound.setInteger("Damage",damage);
+ gtTagCompound.setInteger("MaxDamage",maxDamage);
+ stack.stackTagCompound.setTag("GT.ToolStats", gtTagCompound);
+ }
+ else
+ {
+ stack.stackSize--;
+ }
+ }
+
+ public static int getDamageValueViaNBTTag(ItemStack stack)
+ {
+ NBTTagCompound gtTagCompound = null;
+ if(stack!=null && stack.stackTagCompound.hasKey("GT.ToolStats"))
+ {
+ gtTagCompound = stack.stackTagCompound.getCompoundTag("GT.ToolStats");
+ }
+ else
+ {
+ return 0;
+ }
+ if(gtTagCompound!=null && gtTagCompound.hasKey("Damage"))
+ {
+ return gtTagCompound.getInteger("Damage");
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ public static int getMaxDamageValueViaNBTTag(ItemStack stack)
+ {
+ NBTTagCompound gtTagCompound = null;
+ if(stack!=null && stack.stackTagCompound.hasKey("GT.ToolStats"))
+ {
+ gtTagCompound = stack.stackTagCompound.getCompoundTag("GT.ToolStats");
+ }
+ else
+ {
+ return 0;
+ }
+ if(gtTagCompound!=null && gtTagCompound.hasKey("MaxDamage"))
+ {
+ return gtTagCompound.getInteger("MaxDamage");
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ public static boolean isItemStacksIsEqual(ItemStack stack1, ItemStack stack2, boolean useOreDictionary)
+ {
+ if(useOreDictionary && isItemsHaveSameOreDictionaryEntry(stack1,stack2))
+ {
+ return true;
+ }
+ else
+ {
+ if(stack1.getItemDamage()==OreDictionary.WILDCARD_VALUE || stack2.getItemDamage()==OreDictionary.WILDCARD_VALUE)
+ {
+ return stack1.getItem()==stack2.getItem();
+ }
+ else
+ {
+ return stack1.getItem()==stack2.getItem() && stack1.getItemDamage()==stack2.getItemDamage();
+ }
+ }
+ }
+
+ public static boolean isItemStacksIsEqual(ItemStack stack1, String stack2name, boolean useOreDictionary)
+ {
+ return isItemStacksIsEqual(stack1, getThisModItemStack(stack2name),useOreDictionary);
+ }
+
+ public static boolean isIRecipeInputMatchesWithAmount(IRecipeInput input, ItemStack stack)
+ {
+ if(input.matches(stack))
+ {
+ if(stack.getItem() instanceof IWire)
+ {
+ return getWireLength(stack)>=input.getAmount();
+ }
+ else
+ {
+ return stack.stackSize>=input.getAmount();
+ }
+ }
+ return false;
+ }
+
+ public static boolean reduceItemStackAmountUsingIRecipeInput(IRecipeInput input, ItemStack stack) {
+ if(stack.getItem() instanceof IWire)
+ {
+ return adjustWireLength(stack,-input.getAmount());
+ }
+ else
+ {
+ stack.stackSize-=input.getAmount();
+ return stack.stackSize<=0;
+ }
+ }
+
+ public static String getFirstOreDictNameExcludingTagAny(ItemStack stack) {
+ int[] arrayIDs = OreDictionary.getOreIDs(stack);
+ for(int i=0;i<arrayIDs.length;i++)
+ {
+ if(!OreDictionary.getOreName(arrayIDs[i]).contains("Any"))
+ {
+ return OreDictionary.getOreName(arrayIDs[i]);
+ }
+ }
+ return "";
+ }
+
+ public static void handleFluidSlotsBehaviour(InvSlotConsumableLiquidIHL fillInputSlot, InvSlotConsumableLiquidIHL drainInputSlot, InvSlotOutput emptyFluidItemsSlot, IFluidTank fluidTank)
+ {
+ MutableObject output;
+ if (drainInputSlot!=null && !drainInputSlot.isEmpty())
+ {
+ output = new MutableObject();
+ if(fluidTank.fill(drainInputSlot.drain(null, fluidTank.getCapacity()-fluidTank.getFluidAmount(), output, true),false)>0 && (output.getValue() == null || emptyFluidItemsSlot.canAdd((ItemStack)output.getValue())))
+ {
+ fluidTank.fill(drainInputSlot.drain(null, fluidTank.getCapacity()-fluidTank.getFluidAmount(), output, false),true);
+ if(output.getValue()!=null)
+ {
+ emptyFluidItemsSlot.add((ItemStack)output.getValue());
+ }
+ }
+ }
+ if (fillInputSlot!=null && !fillInputSlot.isEmpty())
+ {
+ output = new MutableObject();
+ if (fillInputSlot.transferFromTank(fluidTank, output, true) && (output.getValue() == null || emptyFluidItemsSlot.canAdd((ItemStack)output.getValue())))
+ {
+ fillInputSlot.transferFromTank(fluidTank, output, false);
+ if(output.getValue()!=null)
+ {
+ emptyFluidItemsSlot.add((ItemStack)output.getValue());
+ }
+ }
+ }
+ }
+ public static double[] tracePlayerView(EntityLivingBase player)
+ {
+ float f1 = player.rotationPitch;
+ float f2 = player.rotationYaw;
+ double x = player.posX;
+ double y = player.posY;
+ double z = player.posZ;
+ if(IC2.platform.isSimulating())
+ {
+ y += player.getEyeHeight();
+ }
+ float f3 = MathHelper.cos(-f2 * 0.01745329F - (float)Math.PI);
+ float f4 = MathHelper.sin(-f2 * 0.01745329F - (float)Math.PI);
+ float f5 = -MathHelper.cos(-f1 * 0.01745329F);
+ float f6 = MathHelper.sin(-f1 * 0.01745329F);
+ float f7 = f4 * f5;
+ float f9 = f3 * f5;
+ double d3 = 1.0D;
+ return new double[] {x+f7 * d3, y+f6 * d3, z+f9 * d3};
+ }
+
+ public static MovingObjectPosition returnMOPFromPlayer(EntityPlayer entityplayer, World world)
+ {
+ float f1 = entityplayer.rotationPitch;
+ float f2 = entityplayer.rotationYaw;
+ double x = entityplayer.posX;
+ double y =entityplayer.posY + entityplayer.getEyeHeight();
+
+ if (world.isRemote)
+ {
+ y -= entityplayer.getDefaultEyeHeight();
+ }
+
+ double z = entityplayer.posZ;
+ Vec3 vec3d = Vec3.createVectorHelper(x, y, z);
+ float f3 = MathHelper.cos(-f2 * 0.01745329F - (float)Math.PI);
+ float f4 = MathHelper.sin(-f2 * 0.01745329F - (float)Math.PI);
+ float f5 = -MathHelper.cos(-f1 * 0.01745329F);
+ float f6 = MathHelper.sin(-f1 * 0.01745329F);
+ float f7 = f4 * f5;
+ float f9 = f3 * f5;
+ double d3 = 5.0D;
+ Vec3 vec3d1 = vec3d.addVector(f7 * d3, f6 * d3, f9 * d3);
+ MovingObjectPosition movingobjectposition = world.rayTraceBlocks(vec3d, vec3d1, true);
+
+ if (movingobjectposition == null)
+ {
+ return null;
+ }
+
+ if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
+ {
+ return movingobjectposition;
+ }
+ return null;
+ }
+
+ public static short getFacingFromPlayerView(EntityLivingBase player, boolean ignoreSneaking)
+ {
+ int var6 = MathHelper.floor_double(player.rotationPitch * 4.0F / 360.0F + 0.5D) & 3;
+ int var7 = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
+ {
+ if(var6==1)
+ {
+ return 1;
+ }
+ else if(var6==3)
+ {
+ return 0;
+ }
+ else
+ {
+ if(player.isSneaking() && !ignoreSneaking)
+ {
+ switch(var7)
+ {
+ case 0:
+ return 3;
+ case 1:
+ return 4;
+ case 2:
+ return 2;
+ case 3:
+ return 5;
+ default:
+ break;
+ }
+ }
+ else
+ {
+ switch(var7)
+ {
+ case 0:
+ return 2;
+ case 1:
+ return 5;
+ case 2:
+ return 3;
+ case 3:
+ return 4;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ return 3;
+ }
+
+ public static int getChainID(ItemStack itemStack)
+ {
+ if(itemStack!=null && itemStack.stackTagCompound!=null && itemStack.stackTagCompound.hasKey("chainUID"))
+ {
+ return itemStack.stackTagCompound.getInteger("chainUID");
+ }
+ return -1;
+ }
+
+ public static List<ItemStack> convertRecipeInputToItemStackList(List<IRecipeInput> input)
+ {
+ Iterator<IRecipeInput> irii=input.iterator();
+ List<ItemStack> output = new ArrayList();
+ while(irii.hasNext())
+ {
+ IRecipeInput iri = irii.next();
+ ItemStack stack = iri.getInputs().get(0);
+ stack.stackSize=iri.getAmount();
+ output.add(stack);
+ }
+ return output;
+ }
+
+ public static List<FluidStack> convertRecipeInputToFluidStackList(List<IRecipeInputFluid> input) {
+ Iterator<IRecipeInputFluid> irii=input.iterator();
+ List<FluidStack> output = new ArrayList();
+ while(irii.hasNext())
+ {
+ IRecipeInputFluid iri = irii.next();
+ FluidStack stack = iri.getInputs().get(0);
+ stack.amount=iri.getAmount();
+ output.add(stack);
+ }
+ return output;
+ }
+
+ public static int[] decodeXYZ(long longNumber)
+ {
+ return new int[] {(int) ((longNumber>>30) & 0xfff)-256,(int) ((longNumber>>15) & 0xfff)-256,(int) (longNumber & 0xfff)-256};
+ }
+
+ public static long encodeXYZ(int x,int y,int z)
+ {
+ return (x+256L)<<30|((y+256L)<<15)|(z+256L);
+ }
+
+ public static int reduceVariableByAbsoluteValue(int variable)
+ {
+ if(variable==0)
+ {
+ return 0;
+ }
+ else if(variable<0)
+ {
+ return variable+1;
+ }
+ else
+ {
+ return variable-1;
+ }
+ }
+
+ public static long getXYZHash(int x,int y,int z)
+ {
+ return ((x&0x1FFFFF)<<42)|((y&0x1FFFFF)<<21)|(z&0x1FFFFF);
+ }
+
+ public static String trim(String str)
+ {
+ int len = str.length();
+ int start;
+ char c;
+ for (start = 0; start < len; ++start)
+ {
+ c = str.charAt(start);
+ if (c > 32 && c != 65279)
+ {
+ break;
+ }
+ }
+ int end;
+ for (end = len - 1; end >= start; --end)
+ {
+ c = str.charAt(end);
+ if (c > 32 && c != 65279)
+ {
+ break;
+ }
+ }
+ return start <= 0 && end >= len - 1 ? str : str.substring(start, end + 1);
+ }
+
+ public static int getAmountOf(ItemStack is)
+ {
+ if(is.getItem() instanceof IWire)
+ {
+ return getWireLength(is);
+ }
+ else
+ {
+ return is.stackSize;
+ }
+ }
+
+ public static ItemStack getWireItemStackCopyWithLengthMultiplied(ItemStack stack, int multiplier)
+ {
+ ItemStack out = stack.copy();
+ adjustWireLength(out,getWireLength(stack)*(multiplier-1));
+ return out;
+ }
+
+ public static ItemStack getUninsulatedWire(String material, int length, int transverseSection) {
+ ItemStack is = getThisModItemStack("copperWire");
+ is.stackTagCompound=new NBTTagCompound();
+ is.stackTagCompound.setBoolean("firstConnection",false);
+ is.stackTagCompound.setInteger("fullLength", length);
+ is.stackTagCompound.setInteger("length", length);
+ is.stackTagCompound.setBoolean("firstConnection", false);
+ is.stackTagCompound.setString("material", material);
+ is.stackTagCompound.setInteger("transverseSection",transverseSection);
+ return is;
+ }
+
+ public static ItemStack getInsulatedWire(String material, int length, int transverseSection, String insulationMaterial, int insulationThickness) {
+ ItemStack is = getUninsulatedWire(material, length, transverseSection);
+ is.stackTagCompound.setString("insulationMaterial",insulationMaterial);
+ is.stackTagCompound.setInteger("insulationThickness",insulationThickness);
+ is.stackTagCompound.setInteger("maxVoltage", getInsulationMaxVoltage(insulationMaterial, insulationThickness));
+ return is;
+ }
+
+ public static long getResistance(NBTTagCompound cable)
+ {
+ String material = cable.getString("material");
+ int transverseSection = cable.getInteger("transverseSection");
+ return ElectricConductor.getResistivity(material)*100L/transverseSection;
+ }
+
+ public static int getInsulationMaxVoltage(String insulationMaterial, int insulationThickness)
+ {
+ return Math.min(Insulation.getMaxVoltagePermm(insulationMaterial)*insulationThickness/10,Insulation.getMaxVoltageCap(insulationMaterial));
+ }
+
+ public static ItemStack getItemStackWithTag(String unLocalizedName, String tag, int tagValue) {
+ ItemStack stack = IHLUtils.getThisModItemStack(unLocalizedName);
+ if(stack.stackTagCompound==null)
+ {
+ stack.stackTagCompound=new NBTTagCompound();
+ }
+ stack.stackTagCompound.setInteger(tag, tagValue);
+ return stack;
+ }
+
+ public static boolean isSegmentInsideAABB(AxisAlignedBB collisionBox, double posX, double posY, double posZ, double posX2, double posY2, double posZ2)
+ {
+ if(isInsideofBoundingBox(collisionBox,(float)posX,(float)posY,(float)posZ)||isInsideofBoundingBox(collisionBox,(float)posX2,(float)posY2,(float)posZ2))
+ {
+ return true;
+ }
+ else
+ {
+ double minX=Math.min(posX, posX2);
+ double maxX=Math.max(posX, posX2);
+ double minY=Math.min(posY, posY2);
+ double maxY=Math.max(posY, posY2);
+ double minZ=Math.min(posZ, posZ2);
+ double maxZ=Math.max(posZ, posZ2);
+ return !(maxX<collisionBox.minX || minX>collisionBox.maxX ||
+ maxY<collisionBox.minY || minY>collisionBox.maxY ||
+ maxZ<collisionBox.minZ || minZ>collisionBox.maxZ);
+ }
+ }
+
+ public static boolean isInsideofBoundingBox(AxisAlignedBB bb, float xi, float yi, float zi)
+ {
+ return bb.maxX>xi && bb.minX<xi && bb.maxY>yi && bb.minY<yi && bb.maxZ>zi && bb.minZ<zi;
+ }
+
+ public static boolean isBlockCanBeReplaced(World world, int x, int y, int z)
+ {
+ Block block = world.getBlock(x, y, z);
+ if(block==Blocks.air || block.isAir(world, x, y, z) || block == Blocks.vine || block == Blocks.tallgrass || block == Blocks.deadbush || block == Blocks.snow_layer || block == Blocks.snow)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ public static void removeChains(IEnergyNetNode te, World world)
+ {
+ Set<NBTTagCompound> cableList = te.getCableList();
+ Iterator<NBTTagCompound> cli = cableList.iterator();
+ while(cli.hasNext())
+ {
+ NBTTagCompound c = cli.next();
+ cli.remove();
+ IHLMod.enet.removeCableEntities(c);
+ ItemStack is = IHLUtils.getThisModItemStack("copperWire");
+ is.stackTagCompound=c;
+ double[] pps = te.getPortPos(null);
+ EntityItem eitem = new EntityItem(world, pps[0], pps[1], pps[2], is);
+ world.spawnEntityInWorld(eitem);
+ removeChain(c,null);
+ }
+ if(te.getGridID()!=-1)
+ {
+ IHLMod.enet.splitGrids(te.getGridID(), te);
+ }
+ cableList.clear();
+ }
+
+ public static void removeChain(NBTTagCompound c, IEnergyNetNode excludeNode)
+ {
+ int x = c.getInteger("connectorX1");
+ int y = c.getInteger("connectorY1");
+ int z = c.getInteger("connectorZ1");
+ int t2DimensionId = c.getInteger("connectorDimensionId1");
+ short facing2 = c.getShort("connectorFacing1");
+ TileEntity t2 = MinecraftServer.getServer().worldServerForDimension(t2DimensionId).getTileEntity(x, y, z);
+ IEnergyNetNode te2;
+ if(t2 instanceof IMultiPowerCableHolder)
+ {
+ te2 = ((IMultiPowerCableHolder)t2).getEnergyNetNode(facing2);
+ }
+ else if(t2 instanceof IEnergyNetNode)
+ {
+ te2 = (IEnergyNetNode)t2;
+ }
+ else
+ {
+ return;
+ }
+ if(excludeNode!=te2)
+ {
+ te2.remove(c);
+ }
+ x = c.getInteger("connectorX");
+ y = c.getInteger("connectorY");
+ z = c.getInteger("connectorZ");
+ t2DimensionId = c.getInteger("connectorDimensionId");
+ facing2 = c.getShort("connectorFacing");
+ t2 = MinecraftServer.getServer().worldServerForDimension(t2DimensionId).getTileEntity(x, y, z);
+ if(t2 instanceof IMultiPowerCableHolder)
+ {
+ te2 = ((IMultiPowerCableHolder)t2).getEnergyNetNode(facing2);
+ }
+ else if(t2 instanceof IEnergyNetNode)
+ {
+ te2 = (IEnergyNetNode)t2;
+ }
+ else
+ {
+ return;
+ }
+ if(excludeNode!=te2)
+ {
+ te2.remove(c);
+ }
+ }
+
+ public static boolean isPlayerLookingAt(EntityLivingBase player, AxisAlignedBB aabb)
+ {
+ double[] pView = tracePlayerView(player);
+ double x = player.posX;
+ double y = player.posY;
+ double z = player.posZ;
+ if(IC2.platform.isSimulating())
+ {
+ y += player.getEyeHeight();
+ }
+ if(
+ isLineSegmentInterseptRectangle(x,y,pView[0],pView[1],aabb.minX,aabb.minY,aabb.maxX,aabb.maxY) &&
+ isLineSegmentInterseptRectangle(x,z,pView[0],pView[2],aabb.minX,aabb.minZ,aabb.maxX,aabb.maxZ) &&
+ isLineSegmentInterseptRectangle(z,y,pView[2],pView[1],aabb.minZ,aabb.minY,aabb.maxZ,aabb.maxY))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isLineSegmentInterseptRectangle(double sx0_1,double sy0_1,double sx1_1,double sy1_1,double rx0_1,double ry0_1,double rx1_1,double ry1_1)
+ {
+ double sx0=sx0_1;
+ double sy0=sy0_1;
+ double sx1=sx1_1;
+ double sy1=sy1_1;
+ double rx0=rx0_1;
+ double ry0=ry0_1;
+ double rx1=rx1_1;
+ double ry1=ry1_1;
+ if(sx1_1<sx0_1)
+ {
+ sx0=sx1_1;
+ sy0=sy1_1;
+ sx1=sx0_1;
+ sy1=sy0_1;
+ }
+ if(rx1_1<rx0_1)
+ {
+ rx0=rx1_1;
+ ry0=ry1_1;
+ rx1=rx0_1;
+ ry1=ry0_1;
+ }
+ double ay = (sy1-sy0)/(sx1-sx0);
+ double by = sy1-ay*sx1;
+
+ double ax = (sx1-sx0)/(sy1-sy0);
+ double bx = sx1-ax*sy1;
+
+ double maxx0 = Math.max(sx0, rx0);
+ double minx1 = Math.min(sx1, rx1);
+ double maxy0 = Math.max(sy0, ry0);
+ double miny1 = Math.min(sy1, ry1);
+ double y0 = ay*maxx0+by;
+ double y1 = ay*minx1+by;
+
+ double x0 = ax*maxy0+bx;
+ double x1 = ax*miny1+bx;
+ return (ry0<=y0 && ry1>=y0)||(ry0<=y1 && ry1>=y1)||(rx0<=x0 && rx1>=x0)||(rx0<=x1 && rx1>=x1);
+ }
+
+ public static float parseFloatSafe(String string, float useSafeValue)
+ {
+ if (Pattern.matches(fpRegex, string))
+ return Float.valueOf(string);
+ else {
+ return useSafeValue;
+ }
+
+ }
+}
diff --git a/ihl/utils/IHLXMLParser.java b/ihl/utils/IHLXMLParser.java
new file mode 100644
index 0000000..67d246b
--- /dev/null
+++ b/ihl/utils/IHLXMLParser.java
@@ -0,0 +1,141 @@
+package ihl.utils;
+
+import ihl.IHLMod;
+import ihl.guidebook.IHLGuidebookGui;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.OutputStreamWriter;
+import java.net.URL;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.*;
+import org.xml.sax.SAXException;
+
+import com.google.common.io.Files;
+
+
+public class IHLXMLParser {
+
+ public DocumentBuilderFactory dbf;
+ public DocumentBuilder db;
+
+ public IHLXMLParser() throws ParserConfigurationException
+ {
+ dbf = DocumentBuilderFactory.newInstance();
+ db = dbf.newDocumentBuilder();
+ }
+
+ public void visit(Node node, int level, int sectionNumber1, IHLGuidebookGui ihlGuidebookGui)
+ {
+ IHLMod.log.debug("Visiting node.");
+ IHLMod.log.debug("Current section="+sectionNumber1);
+ IHLMod.log.debug("Node name="+node.getNodeName());
+ int sectionNumber = sectionNumber1;
+ NodeList list = node.getChildNodes();
+ IHLMod.log.debug("child size="+list.getLength());
+ if (node instanceof Element)
+ {
+ IHLMod.log.debug("node instance of Element.");
+ Element e = (Element) node;
+ IHLMod.log.debug("Node tagname="+e.getTagName());
+ IHLMod.log.debug("Node text content="+e.getTextContent());
+ if(e.getTagName().equals("title"))
+ {
+ ihlGuidebookGui.setTitle(IHLUtils.trim(e.getTextContent()));
+ }
+ else if(e.getTagName().equals("itemstack"))
+ {
+ String[] innername = IHLUtils.trim(e.getTextContent()).split(":");
+ ihlGuidebookGui.addItemStack(IHLUtils.getOtherModItemStackWithDamage(innername[0], innername[1], Integer.parseInt(e.getAttribute("damage"))));
+ }
+ else if(e.getTagName().equals("text"))
+ {
+ ihlGuidebookGui.addTextBlock(IHLUtils.trim(e.getTextContent()));
+ }
+ else if(e.getTagName().equals("image"))
+ {
+ ihlGuidebookGui.setPicture(IHLUtils.trim(e.getTextContent()).replace(" ", ""), Integer.parseInt(e.getAttribute("width")),Integer.parseInt(e.getAttribute("height")));
+ }
+ }
+ for (int i = 0; i < list.getLength(); i++)
+ {
+ Node childNode = list.item(i);
+ if(childNode instanceof Element && ((Element) childNode).getTagName().equals("section"))
+ {
+ Element e = (Element) childNode;
+ int id = Integer.parseInt(e.getAttribute("id"));
+ ihlGuidebookGui.setMaxSectionNumber(id);
+ if(sectionNumber==id)
+ {
+ visit(childNode, level + 1, sectionNumber, ihlGuidebookGui);
+ }
+ else
+ {
+ if(sectionNumber > ihlGuidebookGui.getMaxSectionNumber())
+ {
+ sectionNumber=0;
+ ihlGuidebookGui.setSectionNumber(0);
+ visit(childNode, level + 1, sectionNumber, ihlGuidebookGui);
+ }
+ }
+ }
+ else
+ {
+ visit(childNode, level + 1, sectionNumber, ihlGuidebookGui);
+ }
+ }
+ }
+
+ public void setupGuidebookGUI(IHLGuidebookGui ihlGuidebookGui, int sectionNumber) throws SAXException, IOException
+ {
+ Document doc = db.parse(IHLMod.class.getResourceAsStream("/assets/ihl/config/ihl-guidebook.xml"));
+ visit(doc, 0, sectionNumber, ihlGuidebookGui);
+ }
+
+ private File getGuidebookFile() throws IOException
+ {
+ File folder = new File(IHLMod.proxy.getMinecraftDir(), "config");
+ folder.mkdirs();
+ File file = new File(folder, "ihl-guidebook.xml");
+ if(!file.exists())
+ {
+ InputStream in = IHLMod.class.getResourceAsStream("/assets/ihl/config/ihl-guidebook.xml");
+ InputStreamReader isReader = new InputStreamReader(in, "UTF-8");
+ LineNumberReader reader = new LineNumberReader(isReader);
+ OutputStreamWriter osWriter = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
+ BufferedWriter writer = new BufferedWriter(osWriter);
+ String line;
+ while ((line = reader.readLine()) != null)
+ {
+ writer.append(line);
+ writer.newLine();
+ }
+ writer.close();
+ osWriter.close();
+ in = IHLMod.class.getResourceAsStream("/assets/ihl/config/adress.xsd");
+ isReader = new InputStreamReader(in, "UTF-8");
+ reader = new LineNumberReader(isReader);
+ file = new File(folder, "adress.xsd");
+ osWriter = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
+ writer = new BufferedWriter(osWriter);
+ while ((line = reader.readLine()) != null)
+ {
+ writer.append(line);
+ writer.newLine();
+ }
+ writer.close();
+ osWriter.close();
+ }
+ return file;
+ }
+
+}
diff --git a/ihl/utils/PlayerWakeUpEventHandler.java b/ihl/utils/PlayerWakeUpEventHandler.java
new file mode 100644
index 0000000..5b6751f
--- /dev/null
+++ b/ihl/utils/PlayerWakeUpEventHandler.java
@@ -0,0 +1,17 @@
+package ihl.utils;
+
+import net.minecraft.entity.player.EntityPlayer;
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+
+public class PlayerWakeUpEventHandler
+{
+ @SubscribeEvent
+ public void onPlayerWakeUpEvent(net.minecraftforge.event.entity.player.PlayerWakeUpEvent event)
+ {
+ if(event.entityPlayer instanceof EntityPlayer && !event.entityPlayer.worldObj.isRemote && !event.entityLiving.getEntityData().hasKey("ihlGuidebookRecieved"))
+ {
+ event.entityPlayer.entityDropItem(IHLUtils.getThisModItemStack("guidebook"), 1f);
+ event.entityPlayer.getEntityData().setBoolean("ihlGuidebookRecieved", true);
+ }
+ }
+}
diff --git a/ihl/utils/WorldSavedDataBlastWave.java b/ihl/utils/WorldSavedDataBlastWave.java
new file mode 100644
index 0000000..06e1b41
--- /dev/null
+++ b/ihl/utils/WorldSavedDataBlastWave.java
@@ -0,0 +1,92 @@
+package ihl.utils;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraft.world.WorldSavedData;
+
+public class WorldSavedDataBlastWave extends WorldSavedData {
+ Map<Long,Long[][]> data = new HashMap(256);
+ public static long memoryUsage=0L;
+
+ public WorldSavedDataBlastWave(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ public void readFromNBT(NBTTagCompound nbt)
+ {
+ if(nbt.hasKey("entryList"))
+ {
+ NBTTagList entryList=nbt.getTagList("entryList", 10);
+ for(int i=0;i<entryList.tagCount();i++)
+ {
+ NBTTagCompound chunk = entryList.getCompoundTagAt(i);
+ long chunkHash = chunk.getLong("chunkHash");
+ NBTTagList blastWaveList = chunk.getTagList("blastWaveList", 10);
+ Long[][] blastWaveArray= new Long[16][5];
+ for(int i1=0;i1<16 || i1<blastWaveList.tagCount();i1++)
+ {
+ NBTTagCompound blastWave = blastWaveList.getCompoundTagAt(i1);
+ blastWaveArray[i1][0]=blastWave.getLong("longNumber");
+ blastWaveArray[i1][1]=(long) blastWave.getInteger("sourceX");
+ blastWaveArray[i1][2]=(long) blastWave.getInteger("sourceY");
+ blastWaveArray[i1][3]=(long) blastWave.getInteger("sourceZ");
+ blastWaveArray[i1][4]=(long) blastWave.getInteger("power");
+ }
+ data.put(chunkHash, blastWaveArray);
+ }
+ }
+ }
+
+ @Override
+ public void writeToNBT(NBTTagCompound nbt)
+ {
+ NBTTagList entryList = new NBTTagList();
+ Iterator<Entry<Long, Long[][]>> dataESI = data.entrySet().iterator();
+ while(dataESI.hasNext())
+ {
+ Entry<Long, Long[][]> dataEntry = dataESI.next();
+ Long[][] bwArray = dataEntry.getValue();
+ NBTTagCompound chunk = new NBTTagCompound();
+ NBTTagList blastWaveList = new NBTTagList();
+ for(int i1=0;i1<16;i1++)
+ {
+ NBTTagCompound blastWave = new NBTTagCompound();
+ blastWave.setLong("longNumber", bwArray[i1][0]);
+ blastWave.setInteger("sourceX", bwArray[i1][1].intValue());
+ blastWave.setInteger("sourceY", bwArray[i1][2].intValue());
+ blastWave.setInteger("sourceZ", bwArray[i1][3].intValue());
+ blastWave.setInteger("power", bwArray[i1][4].intValue());
+ blastWaveList.appendTag(blastWave);
+ }
+ chunk.setTag("blastWaveList", blastWaveList);
+ chunk.setLong("chunkHash", dataEntry.getKey());
+ entryList.appendTag(chunk);
+ }
+ nbt.setTag("entryList", entryList);
+ }
+
+ public void scheduleExplosionEffectsOnChunkLoad(long chunkXZKey, long longNumber, int sourceX, int sourceY, int sourceZ, int power1, int absEBSY)
+ {
+ Long[][] waves;
+ if(data.containsKey(chunkXZKey))
+ {
+ waves=data.get(chunkXZKey);
+ }
+ else
+ {
+ waves=new Long[16][5];
+ data.put(chunkXZKey, waves);
+ }
+ waves[absEBSY][0]=longNumber;
+ waves[absEBSY][1]=(long)sourceX;
+ waves[absEBSY][2]=(long)sourceY;
+ waves[absEBSY][3]=(long)sourceZ;
+ waves[absEBSY][4]=(long)power1;
+ }
+}