From 7305ba719930ea3fbf8aa987aeec48b33cdbd82e Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Tue, 21 Mar 2017 17:34:07 +0300 Subject: Oregen --- ihl/explosion/ExplosionVectorBlockV2.java | 40 +++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'ihl/explosion/ExplosionVectorBlockV2.java') diff --git a/ihl/explosion/ExplosionVectorBlockV2.java b/ihl/explosion/ExplosionVectorBlockV2.java index 4489e55..daa16ce 100644 --- a/ihl/explosion/ExplosionVectorBlockV2.java +++ b/ihl/explosion/ExplosionVectorBlockV2.java @@ -13,6 +13,7 @@ import java.util.Map; import java.util.Set; import java.util.Map.Entry; +import java.util.Random; import net.minecraft.block.Block; import net.minecraft.entity.Entity; @@ -26,6 +27,8 @@ import net.minecraft.world.Explosion; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.storage.ExtendedBlockStorage; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.ExplosionEvent; public class ExplosionVectorBlockV2 { final Set startVectors = new HashSet(); @@ -39,7 +42,7 @@ public class ExplosionVectorBlockV2 { private final Map cachedDrops = new HashMap(128); final Map blastWaveByDimensionId = new HashMap(); private final Map cachedEntities = new HashMap(); - public boolean isCalculating = false; + private final Random random = new Random(); public ExplosionVectorBlockV2() { this.precalculateExplosion(); @@ -219,11 +222,13 @@ public class ExplosionVectorBlockV2 { } } else { block.onNeighborBlockChange(world, absX, absY, absZ, block); - if ((++absY & 15) != 0) { - int array_index = (absY & 15) << 8 | (absZ & 15) << 4 | (absX & 15); - if (ebs.getBlockLSBArray()[array_index] == 0 && (ebs.getBlockMSBArray() == null - || ebs.getBlockMSBArray().get(absX & 15, absY & 15, absZ & 15) == 0)) { - this.placeDrops(world, absX, absY, absZ); + if (random.nextInt(8) == 0) { + if ((++absY & 15) != 0) { + int array_index = (absY & 15) << 8 | (absZ & 15) << 4 | (absX & 15); + if (ebs.getBlockLSBArray()[array_index] == 0 && (ebs.getBlockMSBArray() == null + || ebs.getBlockMSBArray().get(absX & 15, absY & 15, absZ & 15) == 0)) { + this.placeDrops(world, absX, absY, absZ); + } } } } @@ -275,6 +280,9 @@ public class ExplosionVectorBlockV2 { Iterator> di = this.cachedDrops.entrySet().iterator(); if (di.hasNext()) { Entry cde = di.next(); + while (di.hasNext()) { + cde = di.next(); + } ItemStack stack = cde.getValue(); if (stack != null && stack.getItem() != null && stack.stackSize > 0) { if (stack.stackSize <= stack.getMaxStackSize()) { @@ -328,19 +336,27 @@ public class ExplosionVectorBlockV2 { startPower, directionMask); } // Free and clean resources - this.cachedDrops.clear(); this.cachedEntities.clear(); } public void doExplosion(World world, int sourceX, int sourceY, int sourceZ, final Set startVectors1, int startPower) { IHLMod.log.info("Starting explosion server"); - isCalculating = true; Explosion explosion = new Explosion(world, null, sourceX, sourceY, sourceZ, 100f); - for (int[] directionMask : directionMasks) { - this.doExplosion(world, sourceX, sourceY, sourceZ, startVectors1, startPower, directionMask, explosion); + if (!MinecraftForge.EVENT_BUS.post(new ExplosionEvent.Start(world, explosion))) { + for (int[] directionMask : directionMasks) { + this.doExplosion(world, sourceX, sourceY, sourceZ, startVectors1, startPower, directionMask, explosion); + } + sendChunkUpdateToPlayersInExplosionAffectedZone(world, sourceX, sourceY, sourceZ); + for (Entry entry : this.cachedDrops.entrySet()) { + IHLEntityFallingPile fallingPile = new IHLEntityFallingPile(world); + fallingPile.setPosition(sourceX + 0.5d, sourceY + 0.5d, sourceZ + 0.5d); + fallingPile.setEntityItemStack(entry.getValue()); + fallingPile.setVelocity(random.nextDouble() - 0.5d, random.nextDouble() * 2, + random.nextDouble() - 0.5d); + world.spawnEntityInWorld(fallingPile); + } + this.cachedDrops.clear(); } - sendChunkUpdateToPlayersInExplosionAffectedZone(world, sourceX, sourceY, sourceZ); - isCalculating = false; } } \ No newline at end of file -- cgit v1.2.3