From 2db8e30b1d2151fdde5d08a6c06aef55f0c397d2 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Fri, 27 Jan 2017 11:32:28 +0300 Subject: License, readme and stuff --- ihl/utils/ChunkAndWorldLoadEventHandler.java | 63 ---- ihl/utils/EntityIHLExplosion.java | 187 ----------- ihl/utils/ExplosionVector.java | 453 --------------------------- ihl/utils/FluidDictionary.java | 6 +- ihl/utils/IHLFluidTank.java | 8 +- ihl/utils/IHLItemRenderer.java | 4 +- ihl/utils/IHLMathUtils.java | 108 ++++++- ihl/utils/IHLRenderUtils.java | 40 ++- ihl/utils/IHLUtils.java | 172 ++++++++-- ihl/utils/IHLXMLParser.java | 51 +-- ihl/utils/WorldSavedDataBlastWave.java | 92 ------ 11 files changed, 286 insertions(+), 898 deletions(-) delete mode 100644 ihl/utils/ChunkAndWorldLoadEventHandler.java delete mode 100644 ihl/utils/EntityIHLExplosion.java delete mode 100644 ihl/utils/ExplosionVector.java delete mode 100644 ihl/utils/WorldSavedDataBlastWave.java (limited to 'ihl/utils') diff --git a/ihl/utils/ChunkAndWorldLoadEventHandler.java b/ihl/utils/ChunkAndWorldLoadEventHandler.java deleted file mode 100644 index 3fb51f7..0000000 --- a/ihl/utils/ChunkAndWorldLoadEventHandler.java +++ /dev/null @@ -1,63 +0,0 @@ -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 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/EntityIHLExplosion.java b/ihl/utils/EntityIHLExplosion.java deleted file mode 100644 index df0dc18..0000000 --- a/ihl/utils/EntityIHLExplosion.java +++ /dev/null @@ -1,187 +0,0 @@ -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 effectBorderBlocks; - public Set effectBorderBlocksWithLowPosition; - public Set blocksConnectedWithBedrock; - public Set blocksNotConnectedWithBedrock; - public int explosionPower; - public int x; - public int y; - public int z; - private Map 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 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 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 path = new HashSet(); - Iterator pathi = path.iterator(); - Set 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 deleted file mode 100644 index d341fd3..0000000 --- a/ihl/utils/ExplosionVector.java +++ /dev/null @@ -1,453 +0,0 @@ -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 startVectors = new HashSet(); - private Set sv; - private Set chunksToUpdate=new HashSet(64); - public Map> vectors = new HashMap(32786); - public Map explosions = new HashMap(); - public Map explosionPower = new HashMap(); - public Map explosionPowerDampingFactor = new HashMap(32786); - public Map cachedEBS = new HashMap(128); - public Map cachedEBSHardness = new HashMap(128); - public Map> cachedEBSDrops = new HashMap(128); - public Map> cachedEBSEntity = new HashMap(128); - public Map blastWaveByDimensionId = new HashMap(); - - private Random random = new Random(); - - public ExplosionVector() - { - this.precalculateExplosion(); - } - - public void precalculateExplosion() - { - int maxExplosionRadius=32; - for(int levelRadius=1; levelRadiusMath.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 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 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=0;ix=xyz[0]>0?ix+1:ix-1) - { - for(int iy=xyz[1]>0?0:multiplier-1;iy=0;iy=xyz[1]>0?iy+1:iy-1) - { - for(int iz=xyz[2]>0?0:multiplier-1;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=0;iy=xyz[1]>0?iy+1:iy-1) - { - for(int ix=xyz[0]>0?0:multiplier-1;ix=0;ix=xyz[0]>0?ix+1:ix-1) - { - for(int iz=xyz[2]>0?0:multiplier-1;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=0;iz=xyz[2]>0?iz+1:iz-1) - { - for(int ix=xyz[0]>0?0:multiplier-1;ix=0;ix=xyz[0]>0?ix+1:ix-1) - { - for(int iy=xyz[1]>0?0:multiplier-1;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 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 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 drops = new HashMap(); - for(int i4=0;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 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 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 sv2=new HashSet(); - if(sv==null) - { - sv = startVectors1; - } - for(long ev:sv) - { - Set 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 index fa5b96a..8dcd18f 100644 --- a/ihl/utils/FluidDictionary.java +++ b/ihl/utils/FluidDictionary.java @@ -10,8 +10,8 @@ import net.minecraftforge.fluids.FluidStack; public class FluidDictionary { - private Map> nameToStack = new HashMap(); - private Map fluidToName = new HashMap(); + private Map> nameToStack = new HashMap>(); + private Map fluidToName = new HashMap(); public FluidDictionary(){} public List getFluids(String fdName) @@ -27,7 +27,7 @@ public class FluidDictionary } else { - List list = new ArrayList(); + List list = new ArrayList(); list.add(fstack); nameToStack.put(fdName, list); } diff --git a/ihl/utils/IHLFluidTank.java b/ihl/utils/IHLFluidTank.java index aef2b46..21eb5b7 100644 --- a/ihl/utils/IHLFluidTank.java +++ b/ihl/utils/IHLFluidTank.java @@ -20,7 +20,6 @@ public class IHLFluidTank implements IFluidTank { private final List fluidList = new ArrayList(); private final int capacity; - private boolean isOpenVessel=false; private int temperature=293; public IHLFluidTank(int capacity) @@ -30,7 +29,6 @@ public class IHLFluidTank implements IFluidTank public IHLFluidTank(int capacity, boolean isOpenVessel1) { - this.isOpenVessel=isOpenVessel1; this.capacity = capacity; } @@ -295,7 +293,7 @@ public class IHLFluidTank implements IFluidTank public void sortFluidsByDensity() { - Map sortMap = new HashMap(); + Map sortMap = new HashMap(); int[] keysArray = new int[fluidList.size()]; Iterator fli = fluidList.iterator(); while(fli.hasNext()) @@ -357,11 +355,11 @@ public class IHLFluidTank implements IFluidTank return this.fluidList; } - public void drain(List fluidInputs, boolean doDrain) + public void drain(List fluidInputs, boolean doDrain) { if(fluidInputs!=null && !fluidInputs.isEmpty()) { - Iterator fsi = fluidInputs.iterator(); + Iterator fsi = fluidInputs.iterator(); while(fsi.hasNext()) { this.drain(fsi.next(), doDrain); diff --git a/ihl/utils/IHLItemRenderer.java b/ihl/utils/IHLItemRenderer.java index caed0a3..38e98b2 100644 --- a/ihl/utils/IHLItemRenderer.java +++ b/ihl/utils/IHLItemRenderer.java @@ -30,9 +30,9 @@ public class IHLItemRenderer { public IHLItemRenderer(){} - public IHLItemRenderer(boolean b) + public IHLItemRenderer(boolean noRotation1) { - noRotation=b; + noRotation=noRotation1; } public void doRender(RenderManager renderManager, ItemStack stack, double x, double y, double z) diff --git a/ihl/utils/IHLMathUtils.java b/ihl/utils/IHLMathUtils.java index cfd6931..1200fd5 100644 --- a/ihl/utils/IHLMathUtils.java +++ b/ihl/utils/IHLMathUtils.java @@ -3,8 +3,9 @@ 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[] sin_table=new float[accuracy_level]; + private final static float[] atan_table=new float[accuracy_level]; + private final static float[] sqrt_table=new float[accuracy_level]; private final static float PI=(float)Math.PI; public static float sin(float angle) @@ -17,6 +18,18 @@ public class IHLMathUtils return sin_table[(int)(angle1*accuracy_level/2/PI)]; } + public static float sqrt(float value) + { + float value1 = value; + int multiplier = 2; + while(value1 >= 1.0f) + { + multiplier*=multiplier; + value1 /=multiplier*multiplier; + } + return ((multiplier>2)?multiplier:1)*sqrt_table[(int)(value1*accuracy_level)]; + } + public static float atan(float tan_value) { if(tan_value<-32f) @@ -32,7 +45,54 @@ public class IHLMathUtils return atan_table[(int)((tan_value+32f)*accuracy_level/64f)]; } } + + public static float[] vector_vector_multiply(float[] v1, float[] v2) + { + float c_x = v1[1]*v2[2] - v2[1]*v1[2]; + float c_y = v2[0]*v1[2] - v1[0]*v2[2]; + float c_z = v1[0]*v2[1] - v2[0]*v1[1]; + return new float[] {c_x,c_y,c_z}; + } + + public static void normalize_vector(float[] v1) + { + float d = (float)Math.sqrt(v1[0]*v1[0]+v1[1]*v1[1]+v1[2]*v1[2]); + if(d == 0) + { // Nothing can we do. Create new vector towards up direction. + v1[0]=0; + v1[1]=1; + v1[2]=0; + } + else + { + v1[0]/=d; + v1[1]/=d; + v1[2]/=d; + } + } + public static void scale_vector_to_value(float[] v1, float v2) + { + float d = (float)Math.sqrt(v1[0]*v1[0]+v1[1]*v1[1]+v1[2]*v1[2]); + if(d == 0) + { // Nothing can we do. Create new vector towards up direction. + v1[0]=0; + v1[1]=v2; + v1[2]=0; + } + else + { + v1[0]=v1[0]*v2/d; + v1[1]=v1[1]*v2/d; + v1[2]=v1[2]*v2/d; + } + } + + public static void vector_add(float[] fs, float x, float y, float z) { + fs[0]+=x; + fs[1]+=y; + fs[2]+=z; + } static { @@ -44,5 +104,49 @@ public class IHLMathUtils { atan_table[i]=(float) Math.atan(-32d+64d*i/accuracy_level); } + for(int i=0;i(); } public void renderIHLFluidTank(IHLFluidTank fluidTank, int x1, int y1, int x2, int y2, float zLevel, int par1, int par2, int xOffset, int yOffset) @@ -323,9 +320,6 @@ public class IHLRenderUtils { 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) @@ -539,7 +533,6 @@ public class IHLRenderUtils 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); @@ -554,16 +547,23 @@ public class IHLRenderUtils v2 = icon.getMinV(); v1 = icon.getMaxV(); } + this.drawSquare(xPos, yPos, zPos, u1, u2, v1, v2, vertexes); + } + + + public void drawSquare(double xPos, double yPos, double zPos, double u1, double u2, double v1, double v2, double[][] vertexes) + { + Tessellator var9 = Tessellator.instance; 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; + int endTo=vertexes.length-1; if(this.renderFromInside) { - startFrom=3; + startFrom=vertexes.length-1; endTo=0; } for(int i=startFrom;(i<=endTo&&!this.renderFromInside)||(i>=endTo&&this.renderFromInside);i+=(endTo-startFrom)/3) @@ -617,6 +617,7 @@ public class IHLRenderUtils 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) { @@ -735,9 +736,6 @@ public class IHLRenderUtils { this.rotationZ=rotationZ1; } -// this.rotationX=rotationX1; - // this.rotationY=rotationY1; - //this.rotationZ=rotationZ1; } public void reset() @@ -762,10 +760,9 @@ public class IHLRenderUtils public List splitStringByWidth(String string, int stringWidth) { - List output = new ArrayList(); + List 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) ihlItemStackRegistry = new HashMap(); + private static Map ihlItemStackRegistry = new HashMap(); private static final String Digits = "(\\p{Digit}+)"; private static final String HexDigits = "(\\p{XDigit}+)"; private static final String Exp = "[eE][+-]?"+Digits; @@ -159,10 +166,10 @@ public class IHLUtils } } - public static ItemStack getOtherModItemStackWithDamage(String modname, String name,int damage) { + public static ItemStack getOtherModItemStackWithDamage(String modname, String name, int damage, int quantity) { if(GameRegistry.findItem(modname, name)!=null) { - return new ItemStack(GameRegistry.findItem(modname, name),1,damage); + return new ItemStack(GameRegistry.findItem(modname, name),quantity,damage); } else if(GameRegistry.findBlock(modname, name)==null) { @@ -170,7 +177,7 @@ public class IHLUtils } else { - return new ItemStack(GameRegistry.findBlock(modname, name),1,damage); + return new ItemStack(GameRegistry.findBlock(modname, name),quantity,damage); } } @@ -477,6 +484,20 @@ public class IHLUtils //IHLMod.log.info("IC2 metal former (rolling) recipe for "+input+" already exist. Skipped."); } } + + public static void addIC2ExtrudingRecipe(ItemStack input, ItemStack output) + { + if(Recipes.metalformerExtruding.getOutputFor(input, false)==null) + { + NBTTagCompound tag = new NBTTagCompound(); + Recipes.metalformerExtruding.addRecipe(new RecipeInputItemStack(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) { @@ -536,7 +557,7 @@ public class IHLUtils public static int getDamageValueViaNBTTag(ItemStack stack) { NBTTagCompound gtTagCompound = null; - if(stack!=null && stack.stackTagCompound.hasKey("GT.ToolStats")) + if(stack!=null && stack.stackTagCompound!=null && stack.stackTagCompound.hasKey("GT.ToolStats")) { gtTagCompound = stack.stackTagCompound.getCompoundTag("GT.ToolStats"); } @@ -557,7 +578,7 @@ public class IHLUtils public static int getMaxDamageValueViaNBTTag(ItemStack stack) { NBTTagCompound gtTagCompound = null; - if(stack!=null && stack.stackTagCompound.hasKey("GT.ToolStats")) + if(stack!=null && stack.stackTagCompound!=null && stack.stackTagCompound.hasKey("GT.ToolStats")) { gtTagCompound = stack.stackTagCompound.getCompoundTag("GT.ToolStats"); } @@ -641,28 +662,28 @@ public class IHLUtils public static void handleFluidSlotsBehaviour(InvSlotConsumableLiquidIHL fillInputSlot, InvSlotConsumableLiquidIHL drainInputSlot, InvSlotOutput emptyFluidItemsSlot, IFluidTank fluidTank) { - MutableObject output; + 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()))) + output = new MutableObject(); + if(fluidTank.fill(drainInputSlot.drain(null, fluidTank.getCapacity()-fluidTank.getFluidAmount(), output, true),false)>0 && (output.getValue() == null || emptyFluidItemsSlot.canAdd(output.getValue()))) { fluidTank.fill(drainInputSlot.drain(null, fluidTank.getCapacity()-fluidTank.getFluidAmount(), output, false),true); if(output.getValue()!=null) { - emptyFluidItemsSlot.add((ItemStack)output.getValue()); + emptyFluidItemsSlot.add(output.getValue()); } } } if (fillInputSlot!=null && !fillInputSlot.isEmpty()) { - output = new MutableObject(); - if (fillInputSlot.transferFromTank(fluidTank, output, true) && (output.getValue() == null || emptyFluidItemsSlot.canAdd((ItemStack)output.getValue()))) + output = new MutableObject(); + if (fillInputSlot.transferFromTank(fluidTank, output, true) && (output.getValue() == null || emptyFluidItemsSlot.canAdd(output.getValue()))) { fillInputSlot.transferFromTank(fluidTank, output, false); if(output.getValue()!=null) { - emptyFluidItemsSlot.add((ItemStack)output.getValue()); + emptyFluidItemsSlot.add(output.getValue()); } } } @@ -788,7 +809,7 @@ public class IHLUtils public static List convertRecipeInputToItemStackList(List input) { Iterator irii=input.iterator(); - List output = new ArrayList(); + List output = new ArrayList(); while(irii.hasNext()) { IRecipeInput iri = irii.next(); @@ -801,7 +822,7 @@ public class IHLUtils public static List convertRecipeInputToFluidStackList(List input) { Iterator irii=input.iterator(); - List output = new ArrayList(); + List output = new ArrayList(); while(irii.hasNext()) { IRecipeInputFluid iri = irii.next(); @@ -840,7 +861,8 @@ public class IHLUtils public static long getXYZHash(int x,int y,int z) { - return ((x&0x1FFFFF)<<42)|((y&0x1FFFFF)<<21)|(z&0x1FFFFF); + int sign_bits = (x & 0x80000000) >> 29 | (y & 0x80000000) >> 30 | (z & 0x80000000) >> 31; + return (long)x<<31 ^ (long)y<<17 ^ (long)z<<3 ^ sign_bits; } public static String trim(String str) @@ -1105,6 +1127,118 @@ public class IHLUtils else { return useSafeValue; } + } + + public static int parseIntSafe(String string, int useSafeValue) + { + if (Pattern.matches(fpRegex, string)) + return Integer.valueOf(string); + else { + return useSafeValue; + } + } + + public static boolean isBlockRegisteredInOreDictionaryAs(Block block, String string) { + Iterator isoi = OreDictionary.getOres(string).iterator(); + while(isoi.hasNext()) + { + if(Block.getBlockFromItem(isoi.next().getItem())==block) + { + return true; + } + } + return false; + } + + public static void setBlockAndTileEntityRaw(World world, int x, int y, int z, Block block, TileEntity te) + { + Chunk chunk = world.getChunkProvider().provideChunk(x>>4, z>>4); + ExtendedBlockStorage[] ebsA = chunk.getBlockStorageArray(); + ExtendedBlockStorage ebs = ebsA[y>>4]; + if(ebs==null) + { + ebs = new ExtendedBlockStorage(y, true); + ebsA[y>>4] = ebs; + } + setBlockRaw(ebs,x & 15,y & 15,z & 15,block); + te.xCoord=x; + te.yCoord=y; + te.zCoord=z; + te.setWorldObj(world); + chunk.addTileEntity(te); } + + public static void setBlockRaw(ExtendedBlockStorage ebs, int x, int y, int z, Block block) + { + int l = ebs.blockLSBArray[y << 8 | z << 4 | x] & 255; + + if (ebs.blockMSBArray != null) + { + l |= ebs.blockMSBArray.get(x, y, z) << 8; + } + + Block block1 = Block.getBlockById(l); + + if (block1 != Blocks.air) + { + --ebs.blockRefCount; + + if (block1.getTickRandomly()) + { + --ebs.tickRefCount; + } + } + + if (block != Blocks.air) + { + ++ebs.blockRefCount; + + if (block.getTickRandomly()) + { + ++ebs.tickRefCount; + } + } + + int i1 = Block.getIdFromBlock(block); + ebs.blockLSBArray[y << 8 | z << 4 | x] = (byte)(i1 & 255); + + if (i1 > 255) + { + if (ebs.blockMSBArray == null) + { + ebs.blockMSBArray = new NibbleArray(ebs.blockLSBArray.length, 4); + } + + ebs.blockMSBArray.set(x, y, z, (i1 & 3840) >> 8); + } + else if (ebs.blockMSBArray != null) + { + ebs.blockMSBArray.set(x, y, z, 0); + } + } + + public static void dumpToFile(Set unlocalisedNames, String filename) { + try { + OutputStreamWriter osWriter = new OutputStreamWriter(new FileOutputStream(getFile(filename)), "UTF-8"); + BufferedWriter writer = new BufferedWriter(osWriter); + for(String string:unlocalisedNames) + { + writer.append(string); + writer.newLine(); + } + writer.close(); + osWriter.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static File getFile(String filename) + { + File folder = new File(IHLMod.proxy.getMinecraftDir(), "logs"); + folder.mkdirs(); + return new File(folder, filename); + } + } diff --git a/ihl/utils/IHLXMLParser.java b/ihl/utils/IHLXMLParser.java index 67d246b..8073542 100644 --- a/ihl/utils/IHLXMLParser.java +++ b/ihl/utils/IHLXMLParser.java @@ -3,15 +3,7 @@ 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; @@ -20,9 +12,6 @@ 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; @@ -55,7 +44,7 @@ public class IHLXMLParser { 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")))); + ihlGuidebookGui.addItemStack(IHLUtils.getOtherModItemStackWithDamage(innername[0], innername[1], Integer.parseInt(e.getAttribute("damage")),1)); } else if(e.getTagName().equals("text")) { @@ -100,42 +89,4 @@ public class IHLXMLParser { 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/WorldSavedDataBlastWave.java b/ihl/utils/WorldSavedDataBlastWave.java deleted file mode 100644 index 06e1b41..0000000 --- a/ihl/utils/WorldSavedDataBlastWave.java +++ /dev/null @@ -1,92 +0,0 @@ -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 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> dataESI = data.entrySet().iterator(); - while(dataESI.hasNext()) - { - Entry 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; - } -} -- cgit v1.2.3