diff --git a/src/minecraft/biomesoplenty/liquids/BlockLiquidPoisonFlowing.java b/src/minecraft/biomesoplenty/liquids/BlockLiquidPoisonFlowing.java index a1bbb0f15..c77921f46 100644 --- a/src/minecraft/biomesoplenty/liquids/BlockLiquidPoisonFlowing.java +++ b/src/minecraft/biomesoplenty/liquids/BlockLiquidPoisonFlowing.java @@ -1,24 +1,29 @@ package biomesoplenty.liquids; +import java.util.Random; + +import biomesoplenty.api.Liquids; +import net.minecraft.block.Block; import net.minecraft.block.BlockFlowing; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import biomesoplenty.BiomesOPlenty; -import biomesoplenty.api.Potions; -import biomesoplenty.configuration.BOPPotions; +import net.minecraftforge.liquids.ILiquid; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockLiquidPoisonFlowing extends BlockFlowing +public class BlockLiquidPoisonFlowing extends BlockFlowing implements ILiquid { + int numAdjacentSources = 0; + boolean isOptimalFlowDirection[] = new boolean[4]; + int flowCost[] = new int[4]; + public BlockLiquidPoisonFlowing(int id) { super(id, Material.water); @@ -27,6 +32,281 @@ public class BlockLiquidPoisonFlowing extends BlockFlowing this.setLightOpacity(3); } + private void updateFlow(World par1World, int par2, int par3, int par4) + { + int l = par1World.getBlockMetadata(par2, par3, par4); + par1World.setBlock(par2, par3, par4, this.blockID + 1, l, 2); + } + + @Override + public int tickRate(World par1World) + { + return 8; + } + + @Override + public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) + { + int l = this.getFlowDecay(par1World, par2, par3, par4); + byte b0 = 1; + + boolean flag = true; + int i1; + + if (l > 0) + { + byte b1 = -100; + this.numAdjacentSources = 0; + int j1 = this.getSmallestFlowDecay(par1World, par2 - 1, par3, par4, b1); + j1 = this.getSmallestFlowDecay(par1World, par2 + 1, par3, par4, j1); + j1 = this.getSmallestFlowDecay(par1World, par2, par3, par4 - 1, j1); + j1 = this.getSmallestFlowDecay(par1World, par2, par3, par4 + 1, j1); + i1 = j1 + b0; + + if (i1 >= 7 || j1 < 0) + { + i1 = -1; + } + + if (this.getFlowDecay(par1World, par2, par3 + 1, par4) >= 0) + { + int k1 = this.getFlowDecay(par1World, par2, par3 + 1, par4); + + if (k1 >= 7) + { + i1 = k1; + } + else + { + i1 = k1 + 7; + } + } + + if (i1 == l) + { + if (flag) + { + this.updateFlow(par1World, par2, par3, par4); + } + } + else + { + l = i1; + + if (i1 < 0) + { + par1World.setBlockToAir(par2, par3, par4); + } + else + { + par1World.setBlockMetadataWithNotify(par2, par3, par4, i1, 2); + par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate(par1World)); + par1World.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID); + } + } + } + else + { + this.updateFlow(par1World, par2, par3, par4); + } + + if (this.liquidCanDisplaceBlock(par1World, par2, par3 - 1, par4)) + { + if (l >= 7) + { + this.flowIntoBlock(par1World, par2, par3 - 1, par4, l); + } + else + { + this.flowIntoBlock(par1World, par2, par3 - 1, par4, l + 7); + } + } + else if (l >= 0 && (l == 0 || this.blockBlocksFlow(par1World, par2, par3 - 1, par4))) + { + boolean[] aboolean = this.getOptimalFlowDirections(par1World, par2, par3, par4); + i1 = l + b0; + + if (l >= 7) + { + i1 = 1; + } + + if (i1 >= 7) + { + return; + } + + if (aboolean[0]) + { + this.flowIntoBlock(par1World, par2 - 1, par3, par4, i1); + } + + if (aboolean[1]) + { + this.flowIntoBlock(par1World, par2 + 1, par3, par4, i1); + } + + if (aboolean[2]) + { + this.flowIntoBlock(par1World, par2, par3, par4 - 1, i1); + } + + if (aboolean[3]) + { + this.flowIntoBlock(par1World, par2, par3, par4 + 1, i1); + } + } + } + + private void flowIntoBlock(World world, int i, int j, int k, int l) + { + if (liquidCanDisplaceBlock(world, i, j, k)) + { + int blockId = world.getBlockId(i, j, k); + if (blockId > 0) + { + Block.blocksList[blockId].dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k), 0); + } + world.setBlock(i, j, k, blockID, l, 3); + } + } + + private int calculateFlowCost(World world, int i, int j, int k, int l, int i1) + { + int j1 = 1000; + for (int k1 = 0; k1 < 4; k1++) + { + if (k1 == 0 && i1 == 1 || k1 == 1 && i1 == 0 || k1 == 2 && i1 == 3 || k1 == 3 && i1 == 2) + { + continue; + } + int l1 = i; + int i2 = j; + int j2 = k; + if (k1 == 0) + { + l1--; + } + if (k1 == 1) + { + l1++; + } + if (k1 == 2) + { + j2--; + } + if (k1 == 3) + { + j2++; + } + if (blockBlocksFlow(world, l1, i2, j2) || world.getBlockMaterial(l1, i2, j2) == blockMaterial && world.getBlockMetadata(l1, i2, j2) == 0) + { + continue; + } + if (!blockBlocksFlow(world, l1, i2 - 1, j2)) + { + return l; + } + if (l >= 4) + { + continue; + } + int k2 = calculateFlowCost(world, l1, i2, j2, l + 1, k1); + if (k2 < j1) + { + j1 = k2; + } + } + + return j1; + } + + private boolean[] getOptimalFlowDirections(World world, int i, int j, int k) + { + for (int l = 0; l < 4; l++) + { + flowCost[l] = 1000; + int j1 = i; + int i2 = j; + int j2 = k; + if (l == 0) + { + j1--; + } + if (l == 1) + { + j1++; + } + if (l == 2) + { + j2--; + } + if (l == 3) + { + j2++; + } + if (blockBlocksFlow(world, j1, i2, j2) || world.getBlockMaterial(j1, i2, j2) == blockMaterial && world.getBlockMetadata(j1, i2, j2) == 0) + { + continue; + } + if (!blockBlocksFlow(world, j1, i2 - 1, j2)) + { + flowCost[l] = 0; + } + else + { + flowCost[l] = calculateFlowCost(world, j1, i2, j2, 1, l); + } + } + + int i1 = flowCost[0]; + for (int k1 = 1; k1 < 4; k1++) { + if (flowCost[k1] < i1) { + i1 = flowCost[k1]; + } + } + + for (int l1 = 0; l1 < 4; l1++) { + isOptimalFlowDirection[l1] = flowCost[l1] == i1; + } + + return isOptimalFlowDirection; + } + + private boolean blockBlocksFlow(World par1World, int par2, int par3, int par4) + { + int l = par1World.getBlockId(par2, par3, par4); + + if (l != Block.doorWood.blockID && l != Block.doorIron.blockID && l != Block.signPost.blockID && l != Block.ladder.blockID && l != Block.reed.blockID) + { + if (l == 0) + { + return false; + } + else + { + Material material = Block.blocksList[l].blockMaterial; + return material == Material.portal ? true : material.blocksMovement(); + } + } + else + { + return true; + } + } + + private boolean liquidCanDisplaceBlock(World world, int i, int j, int k) + { + Material material = world.getBlockMaterial(i, j, k); + if (material == blockMaterial) + { + return false; + } else + { + return !blockBlocksFlow(world, i, j, k); + } + } + @Override public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { @@ -51,4 +331,22 @@ public class BlockLiquidPoisonFlowing extends BlockFlowing { this.theIcon = new Icon[]{iconRegister.registerIcon("BiomesOPlenty:liquid_poison_still"), iconRegister.registerIcon("BiomesOPlenty:liquid_poison_flowing")}; } + + @Override + public int stillLiquidId() + { + return Liquids.liquidPoisonStill.get().blockID; + } + + @Override + public boolean isMetaSensitive() + { + return false; + } + + @Override + public int stillLiquidMeta() + { + return 0; + } } diff --git a/src/minecraft/biomesoplenty/liquids/BlockLiquidPoisonStill.java b/src/minecraft/biomesoplenty/liquids/BlockLiquidPoisonStill.java index d6d7d0f72..8e68bf7ab 100644 --- a/src/minecraft/biomesoplenty/liquids/BlockLiquidPoisonStill.java +++ b/src/minecraft/biomesoplenty/liquids/BlockLiquidPoisonStill.java @@ -1,24 +1,21 @@ package biomesoplenty.liquids; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; +import biomesoplenty.api.Liquids; import net.minecraft.block.BlockStationary; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.liquids.ILiquid; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; -import biomesoplenty.BiomesOPlenty; -import biomesoplenty.api.Potions; -import biomesoplenty.configuration.BOPPotions; - -public class BlockLiquidPoisonStill extends BlockStationary +public class BlockLiquidPoisonStill extends BlockStationary implements ILiquid { public BlockLiquidPoisonStill(int id) { @@ -67,4 +64,22 @@ public class BlockLiquidPoisonStill extends BlockStationary { this.theIcon = new Icon[]{iconRegister.registerIcon("BiomesOPlenty:liquid_poison_still"), iconRegister.registerIcon("BiomesOPlenty:liquid_poison_flowing")}; } + + @Override + public int stillLiquidId() + { + return Liquids.liquidPoisonStill.get().blockID; + } + + @Override + public boolean isMetaSensitive() + { + return false; + } + + @Override + public int stillLiquidMeta() + { + return 0; + } } diff --git a/src/minecraft/biomesoplenty/liquids/BlockSpringWaterFlowing.java b/src/minecraft/biomesoplenty/liquids/BlockSpringWaterFlowing.java index 1cdeff2bb..97d55606c 100644 --- a/src/minecraft/biomesoplenty/liquids/BlockSpringWaterFlowing.java +++ b/src/minecraft/biomesoplenty/liquids/BlockSpringWaterFlowing.java @@ -1,5 +1,8 @@ package biomesoplenty.liquids; +import java.util.Random; + +import net.minecraft.block.Block; import net.minecraft.block.BlockFlowing; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; @@ -11,14 +14,20 @@ import net.minecraft.potion.PotionEffect; import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.liquids.ILiquid; import biomesoplenty.BiomesOPlenty; +import biomesoplenty.api.Liquids; import biomesoplenty.api.Potions; import biomesoplenty.configuration.BOPPotions; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class BlockSpringWaterFlowing extends BlockFlowing +public class BlockSpringWaterFlowing extends BlockFlowing implements ILiquid { + int numAdjacentSources = 0; + boolean isOptimalFlowDirection[] = new boolean[4]; + int flowCost[] = new int[4]; + public BlockSpringWaterFlowing(int id) { super(id, Material.water); @@ -27,6 +36,275 @@ public class BlockSpringWaterFlowing extends BlockFlowing this.setLightOpacity(0); } + private void updateFlow(World par1World, int par2, int par3, int par4) + { + int l = par1World.getBlockMetadata(par2, par3, par4); + par1World.setBlock(par2, par3, par4, this.blockID + 1, l, 2); + } + + @Override + public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) + { + int l = this.getFlowDecay(par1World, par2, par3, par4); + byte b0 = 1; + + boolean flag = true; + int i1; + + if (l > 0) + { + byte b1 = -100; + this.numAdjacentSources = 0; + int j1 = this.getSmallestFlowDecay(par1World, par2 - 1, par3, par4, b1); + j1 = this.getSmallestFlowDecay(par1World, par2 + 1, par3, par4, j1); + j1 = this.getSmallestFlowDecay(par1World, par2, par3, par4 - 1, j1); + j1 = this.getSmallestFlowDecay(par1World, par2, par3, par4 + 1, j1); + i1 = j1 + b0; + + if (i1 >= 8 || j1 < 0) + { + i1 = -1; + } + + if (this.getFlowDecay(par1World, par2, par3 + 1, par4) >= 0) + { + int k1 = this.getFlowDecay(par1World, par2, par3 + 1, par4); + + if (k1 >= 8) + { + i1 = k1; + } + else + { + i1 = k1 + 8; + } + } + + if (i1 == l) + { + if (flag) + { + this.updateFlow(par1World, par2, par3, par4); + } + } + else + { + l = i1; + + if (i1 < 0) + { + par1World.setBlockToAir(par2, par3, par4); + } + else + { + par1World.setBlockMetadataWithNotify(par2, par3, par4, i1, 2); + par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate(par1World)); + par1World.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID); + } + } + } + else + { + this.updateFlow(par1World, par2, par3, par4); + } + + if (this.liquidCanDisplaceBlock(par1World, par2, par3 - 1, par4)) + { + if (l >= 8) + { + this.flowIntoBlock(par1World, par2, par3 - 1, par4, l); + } + else + { + this.flowIntoBlock(par1World, par2, par3 - 1, par4, l + 8); + } + } + else if (l >= 0 && (l == 0 || this.blockBlocksFlow(par1World, par2, par3 - 1, par4))) + { + boolean[] aboolean = this.getOptimalFlowDirections(par1World, par2, par3, par4); + i1 = l + b0; + + if (l >= 8) + { + i1 = 1; + } + + if (i1 >= 8) + { + return; + } + + if (aboolean[0]) + { + this.flowIntoBlock(par1World, par2 - 1, par3, par4, i1); + } + + if (aboolean[1]) + { + this.flowIntoBlock(par1World, par2 + 1, par3, par4, i1); + } + + if (aboolean[2]) + { + this.flowIntoBlock(par1World, par2, par3, par4 - 1, i1); + } + + if (aboolean[3]) + { + this.flowIntoBlock(par1World, par2, par3, par4 + 1, i1); + } + } + } + + private void flowIntoBlock(World world, int i, int j, int k, int l) + { + if (liquidCanDisplaceBlock(world, i, j, k)) + { + int blockId = world.getBlockId(i, j, k); + if (blockId > 0) + { + Block.blocksList[blockId].dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k), 0); + } + world.setBlock(i, j, k, blockID, l, 3); + } + } + + private int calculateFlowCost(World world, int i, int j, int k, int l, int i1) + { + int j1 = 1000; + for (int k1 = 0; k1 < 4; k1++) + { + if (k1 == 0 && i1 == 1 || k1 == 1 && i1 == 0 || k1 == 2 && i1 == 3 || k1 == 3 && i1 == 2) + { + continue; + } + int l1 = i; + int i2 = j; + int j2 = k; + if (k1 == 0) + { + l1--; + } + if (k1 == 1) + { + l1++; + } + if (k1 == 2) + { + j2--; + } + if (k1 == 3) + { + j2++; + } + if (blockBlocksFlow(world, l1, i2, j2) || world.getBlockMaterial(l1, i2, j2) == blockMaterial && world.getBlockMetadata(l1, i2, j2) == 0) + { + continue; + } + if (!blockBlocksFlow(world, l1, i2 - 1, j2)) + { + return l; + } + if (l >= 4) + { + continue; + } + int k2 = calculateFlowCost(world, l1, i2, j2, l + 1, k1); + if (k2 < j1) + { + j1 = k2; + } + } + + return j1; + } + + private boolean[] getOptimalFlowDirections(World world, int i, int j, int k) + { + for (int l = 0; l < 4; l++) + { + flowCost[l] = 1000; + int j1 = i; + int i2 = j; + int j2 = k; + if (l == 0) + { + j1--; + } + if (l == 1) + { + j1++; + } + if (l == 2) + { + j2--; + } + if (l == 3) + { + j2++; + } + if (blockBlocksFlow(world, j1, i2, j2) || world.getBlockMaterial(j1, i2, j2) == blockMaterial && world.getBlockMetadata(j1, i2, j2) == 0) + { + continue; + } + if (!blockBlocksFlow(world, j1, i2 - 1, j2)) + { + flowCost[l] = 0; + } + else + { + flowCost[l] = calculateFlowCost(world, j1, i2, j2, 1, l); + } + } + + int i1 = flowCost[0]; + for (int k1 = 1; k1 < 4; k1++) { + if (flowCost[k1] < i1) { + i1 = flowCost[k1]; + } + } + + for (int l1 = 0; l1 < 4; l1++) { + isOptimalFlowDirection[l1] = flowCost[l1] == i1; + } + + return isOptimalFlowDirection; + } + + private boolean blockBlocksFlow(World par1World, int par2, int par3, int par4) + { + int l = par1World.getBlockId(par2, par3, par4); + + if (l != Block.doorWood.blockID && l != Block.doorIron.blockID && l != Block.signPost.blockID && l != Block.ladder.blockID && l != Block.reed.blockID) + { + if (l == 0) + { + return false; + } + else + { + Material material = Block.blocksList[l].blockMaterial; + return material == Material.portal ? true : material.blocksMovement(); + } + } + else + { + return true; + } + } + + private boolean liquidCanDisplaceBlock(World world, int i, int j, int k) + { + Material material = world.getBlockMaterial(i, j, k); + if (material == blockMaterial) + { + return false; + } else + { + return !blockBlocksFlow(world, i, j, k); + } + } + @Override public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { @@ -51,4 +329,22 @@ public class BlockSpringWaterFlowing extends BlockFlowing { this.theIcon = new Icon[]{iconRegister.registerIcon("BiomesOPlenty:spring_water_still"), iconRegister.registerIcon("BiomesOPlenty:spring_water_flowing")}; } + + @Override + public int stillLiquidId() + { + return Liquids.springWaterStill.get().blockID; + } + + @Override + public boolean isMetaSensitive() + { + return false; + } + + @Override + public int stillLiquidMeta() + { + return 0; + } } diff --git a/src/minecraft/biomesoplenty/liquids/BlockSpringWaterStill.java b/src/minecraft/biomesoplenty/liquids/BlockSpringWaterStill.java index e3a3fbc68..ce4348a4a 100644 --- a/src/minecraft/biomesoplenty/liquids/BlockSpringWaterStill.java +++ b/src/minecraft/biomesoplenty/liquids/BlockSpringWaterStill.java @@ -13,12 +13,14 @@ import net.minecraft.potion.PotionEffect; import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.liquids.ILiquid; import biomesoplenty.BiomesOPlenty; +import biomesoplenty.api.Liquids; import biomesoplenty.api.Potions; import biomesoplenty.configuration.BOPPotions; -public class BlockSpringWaterStill extends BlockStationary +public class BlockSpringWaterStill extends BlockStationary implements ILiquid { public BlockSpringWaterStill(int id) { @@ -67,4 +69,22 @@ public class BlockSpringWaterStill extends BlockStationary { this.theIcon = new Icon[]{iconRegister.registerIcon("BiomesOPlenty:spring_water_still"), iconRegister.registerIcon("BiomesOPlenty:spring_water_flowing")}; } + + @Override + public int stillLiquidId() + { + return Liquids.springWaterStill.get().blockID; + } + + @Override + public boolean isMetaSensitive() + { + return false; + } + + @Override + public int stillLiquidMeta() + { + return 0; + } } diff --git a/src/minecraft/mods/BiomesOPlenty/textures/blocks/liquid_poison_still.txt b/src/minecraft/mods/BiomesOPlenty/textures/blocks/liquid_poison_still.txt index d8fe765a9..55f2f4d6f 100644 --- a/src/minecraft/mods/BiomesOPlenty/textures/blocks/liquid_poison_still.txt +++ b/src/minecraft/mods/BiomesOPlenty/textures/blocks/liquid_poison_still.txt @@ -30,3 +30,4 @@ 29*2 30*2 31*2 +