Adding new liquids

Since oilcraft died and it was going to provid Oil/Fuel support i will
now be adding that to this mod. Other features like burning the fules
for energy will be added to steampower on a later date.

*reoginized api, will do some more of this later to make things easier
*added finite still and flowing liquid prefab class to the api folder
*added: oil, still ahve to add it in game
*added: milk, still have to add it in game
This commit is contained in:
Rseifert 2013-01-23 20:30:50 -05:00
parent dda6237c89
commit 5075a97d10
23 changed files with 375 additions and 31 deletions

View file

@ -1,5 +1,8 @@
package liquidmechanics.api.helpers; package liquidmechanics.api.helpers;
import liquidmechanics.api.liquids.LiquidData;
import liquidmechanics.api.liquids.LiquidHandler;
public enum ColorCode public enum ColorCode
{ {

View file

@ -1,6 +1,5 @@
package liquidmechanics.api; package liquidmechanics.api.liquids;
import liquidmechanics.api.helpers.LiquidData;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ITankContainer; import net.minecraftforge.liquids.ITankContainer;

View file

@ -1,5 +1,6 @@
package liquidmechanics.api.helpers; package liquidmechanics.api.liquids;
import liquidmechanics.api.helpers.ColorCode;
import net.minecraftforge.liquids.LiquidStack; import net.minecraftforge.liquids.LiquidStack;
public class LiquidData public class LiquidData

View file

@ -0,0 +1,246 @@
package liquidmechanics.api.liquids;
import java.util.Random;
import cpw.mods.fml.common.FMLLog;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFlowing;
import net.minecraft.block.material.Material;
import net.minecraft.world.World;
import net.minecraftforge.liquids.ILiquid;
public class LiquidFiniteFlowing extends BlockFlowing implements ILiquid {
int numAdjacentSources = 0;
int[] flowCost = new int[4];
boolean[] isOptimalFlowDirection = new boolean[4];
public LiquidFiniteFlowing(int blockId)
{
super(blockId, Material.water);
this.disableStats();
this.setHardness(100);
this.setTextureFile("");
}
private void updateFlow(World world, int i, int j, int k) {
world.markBlockRangeForRenderUpdate(i, j, k, i, j, k);
world.markBlockForUpdate(i, j, k);
}
@Override
public void updateTick(World world, int i, int j, int k, Random random) {
int l = getFlowDecay(world, i, j, k);
byte byte0 = 1;
boolean flag = true;
if (l > 0) {
int i1 = -100;
numAdjacentSources = 0;
i1 = getSmallestFlowDecay(world, i - 1, j, k, i1);
i1 = getSmallestFlowDecay(world, i + 1, j, k, i1);
i1 = getSmallestFlowDecay(world, i, j, k - 1, i1);
i1 = getSmallestFlowDecay(world, i, j, k + 1, i1);
int j1 = i1 + byte0;
if (j1 >= 8 || i1 < 0) {
j1 = -1;
}
if (getFlowDecay(world, i, j + 1, k) >= 0) {
int l1 = getFlowDecay(world, i, j + 1, k);
if (l1 >= 8) {
j1 = l1;
} else {
j1 = l1 + 8;
}
}
if (j1 != l) {
l = j1;
if (l < 0) {
world.setBlockWithNotify(i, j, k, 0);
} else {
world.setBlockMetadataWithNotify(i, j, k, l);
world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
world.notifyBlocksOfNeighborChange(i, j, k, blockID);
}
} else if (flag) {
updateFlow(world, i, j, k);
}
} else {
updateFlow(world, i, j, k);
}
if (liquidCanDisplaceBlock(world, i, j - 1, k)) {
if (l >= 8) {
world.setBlockAndMetadataWithNotify(i, j - 1, k, blockID, l);
} else {
world.setBlockAndMetadataWithNotify(i, j - 1, k, blockID, l + 8);
}
} else if (l >= 0 && (l == 0 || blockBlocksFlow(world, i, j - 1, k))) {
boolean aflag[] = getOptimalFlowDirections(world, i, j, k);
int k1 = l + byte0;
if (l >= 8) {
k1 = 1;
}
if (k1 >= 8)
return;
if (aflag[0]) {
flowIntoBlock(world, i - 1, j, k, k1);
}
if (aflag[1]) {
flowIntoBlock(world, i + 1, j, k, k1);
}
if (aflag[2]) {
flowIntoBlock(world, i, j, k - 1, k1);
}
if (aflag[3]) {
flowIntoBlock(world, i, j, k + 1, k1);
}
}
}
private void flowIntoBlock(World world, int i, int j, int k, int l) {
if (liquidCanDisplaceBlock(world, i, j, k)) {
int i1 = world.getBlockId(i, j, k);
if (i1 > 0) {
Block.blocksList[i1].dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k), 0);
}
world.setBlockAndMetadataWithNotify(i, j, k, blockID, l);
}
}
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 world, int i, int j, int k) {
int l = world.getBlockId(i, j, k);
if (l == Block.doorWood.blockID || l == Block.doorSteel.blockID || l == Block.signPost.blockID || l == Block.ladder.blockID || l == Block.reed.blockID)
return true;
if (l == 0)
return false;
Material material = Block.blocksList[l].blockMaterial;
return material.isSolid();
}
protected int getSmallestFlowDecay(World world, int i, int j, int k, int l) {
int i1 = getFlowDecay(world, i, j, k);
if (i1 < 0)
return l;
if (i1 >= 8) {
i1 = 0;
}
return l >= 0 && i1 >= l ? l : i1;
}
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 void onBlockAdded(World world, int i, int j, int k) {
super.onBlockAdded(world, i, j, k);
if (world.getBlockId(i, j, k) == blockID) {
world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
}
}
@Override
public int stillLiquidId() {
return this.blockID;
}
@Override
public boolean isMetaSensitive() {
return false;
}
@Override
public int stillLiquidMeta() {
return 0;
}
@Override
public boolean isBlockReplaceable(World world, int i, int j, int k) {
return true;
}
}

View file

@ -0,0 +1,57 @@
package liquidmechanics.api.liquids;
import net.minecraft.block.BlockStationary;
import net.minecraft.block.material.Material;
import net.minecraft.world.World;
import net.minecraftforge.liquids.ILiquid;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class LiquidFiniteStill extends BlockStationary implements ILiquid
{
public LiquidFiniteStill(int blockId)
{
super(blockId, Material.water);
this.setHardness(100);
this.disableStats();
this.setTextureFile("");
}
@SideOnly(Side.CLIENT)
public int getBlockColor()
{
return 0xFFFFFF;
}
@Override
public int tickRate()
{
return 20;
}
@Override
public int stillLiquidId()
{
return this.blockID;
}
@Override
public boolean isMetaSensitive()
{
return false;
}
@Override
public int stillLiquidMeta()
{
return 0;
}
@Override
public boolean isBlockReplaceable(World world, int x, int y, int z)
{
return true;
}
}

View file

@ -1,10 +1,12 @@
package liquidmechanics.api.helpers; package liquidmechanics.api.liquids;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import liquidmechanics.api.helpers.ColorCode;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.ForgeSubscribe;

View file

@ -1,4 +1,4 @@
package liquidmechanics.api; package liquidmechanics.api.mech;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;

View file

@ -1,7 +1,7 @@
package liquidmechanics.client.render; package liquidmechanics.client.render;
import liquidmechanics.api.helpers.LiquidData; import liquidmechanics.api.liquids.LiquidData;
import liquidmechanics.api.helpers.LiquidHandler; import liquidmechanics.api.liquids.LiquidHandler;
import liquidmechanics.client.model.ModelPump; import liquidmechanics.client.model.ModelPump;
import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.tileentity.TileEntityPump; import liquidmechanics.common.tileentity.TileEntityPump;

View file

@ -1,9 +1,9 @@
package liquidmechanics.client.render; package liquidmechanics.client.render;
import liquidmechanics.api.helpers.LiquidData;
import liquidmechanics.api.helpers.LiquidHandler;
import liquidmechanics.api.helpers.ColorCode; import liquidmechanics.api.helpers.ColorCode;
import liquidmechanics.api.helpers.connectionHelper; import liquidmechanics.api.helpers.connectionHelper;
import liquidmechanics.api.liquids.LiquidData;
import liquidmechanics.api.liquids.LiquidHandler;
import liquidmechanics.client.model.ModelLiquidTank; import liquidmechanics.client.model.ModelLiquidTank;
import liquidmechanics.client.model.ModelLiquidTankCorner; import liquidmechanics.client.model.ModelLiquidTankCorner;
import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.LiquidMechanics;

View file

@ -2,9 +2,9 @@ package liquidmechanics.common;
import java.io.File; import java.io.File;
import liquidmechanics.api.helpers.LiquidData;
import liquidmechanics.api.helpers.LiquidHandler;
import liquidmechanics.api.helpers.ColorCode; import liquidmechanics.api.helpers.ColorCode;
import liquidmechanics.api.liquids.LiquidData;
import liquidmechanics.api.liquids.LiquidHandler;
import liquidmechanics.common.block.BlockGenerator; import liquidmechanics.common.block.BlockGenerator;
import liquidmechanics.common.block.BlockPumpMachine; import liquidmechanics.common.block.BlockPumpMachine;
import liquidmechanics.common.block.BlockPipe; import liquidmechanics.common.block.BlockPipe;

View file

@ -4,7 +4,7 @@ import java.util.List;
import universalelectricity.prefab.BlockMachine; import universalelectricity.prefab.BlockMachine;
import universalelectricity.prefab.tile.TileEntityAdvanced; import universalelectricity.prefab.tile.TileEntityAdvanced;
import liquidmechanics.api.helpers.LiquidHandler; import liquidmechanics.api.liquids.LiquidHandler;
import liquidmechanics.client.render.BlockRenderHelper; import liquidmechanics.client.render.BlockRenderHelper;
import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.MetaGroup; import liquidmechanics.common.MetaGroup;

View file

@ -2,7 +2,7 @@ package liquidmechanics.common.block;
import java.util.List; import java.util.List;
import liquidmechanics.api.helpers.LiquidHandler; import liquidmechanics.api.liquids.LiquidHandler;
import liquidmechanics.client.render.BlockRenderHelper; import liquidmechanics.client.render.BlockRenderHelper;
import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.TabLiquidMechanics; import liquidmechanics.common.TabLiquidMechanics;

View file

@ -0,0 +1,12 @@
package liquidmechanics.common.block.liquids;
import liquidmechanics.api.liquids.LiquidFiniteStill;
public class BlockMilk extends LiquidFiniteStill
{
public BlockMilk(int i)
{
super(i);
this.setBlockName("MilkStill");
}
}

View file

@ -0,0 +1,12 @@
package liquidmechanics.common.block.liquids;
import liquidmechanics.api.liquids.LiquidFiniteStill;
public class BlockOil extends LiquidFiniteStill
{
public BlockOil(int i)
{
super(i);
this.setBlockName("OilStill");
}
}

View file

@ -0,0 +1,12 @@
package liquidmechanics.common.block.liquids;
import liquidmechanics.api.liquids.LiquidFiniteFlowing;
public class BlockOilFlowing extends LiquidFiniteFlowing
{
public BlockOilFlowing(int i)
{
super(i);
this.setBlockName("OilFlowing");
}
}

View file

@ -1,8 +1,8 @@
package liquidmechanics.common.handlers; package liquidmechanics.common.handlers;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import liquidmechanics.api.helpers.LiquidHandler;
import liquidmechanics.api.helpers.ColorCode; import liquidmechanics.api.helpers.ColorCode;
import liquidmechanics.api.liquids.LiquidHandler;
import liquidmechanics.common.tileentity.TileEntityPipe; import liquidmechanics.common.tileentity.TileEntityPipe;
import liquidmechanics.common.tileentity.TileEntityTank; import liquidmechanics.common.tileentity.TileEntityTank;

View file

@ -2,9 +2,9 @@ package liquidmechanics.common.tileentity;
import java.util.EnumSet; import java.util.EnumSet;
import liquidmechanics.api.IForce;
import liquidmechanics.api.IReadOut; import liquidmechanics.api.IReadOut;
import liquidmechanics.api.helpers.connectionHelper; import liquidmechanics.api.helpers.connectionHelper;
import liquidmechanics.api.mech.IForce;
import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.MetaGroup; import liquidmechanics.common.MetaGroup;
import liquidmechanics.common.block.BlockGenerator; import liquidmechanics.common.block.BlockGenerator;

View file

@ -2,11 +2,11 @@ package liquidmechanics.common.tileentity;
import liquidmechanics.api.IColorCoded; import liquidmechanics.api.IColorCoded;
import liquidmechanics.api.IReadOut; import liquidmechanics.api.IReadOut;
import liquidmechanics.api.IPressure;
import liquidmechanics.api.helpers.LiquidData;
import liquidmechanics.api.helpers.LiquidHandler;
import liquidmechanics.api.helpers.ColorCode; import liquidmechanics.api.helpers.ColorCode;
import liquidmechanics.api.helpers.connectionHelper; import liquidmechanics.api.helpers.connectionHelper;
import liquidmechanics.api.liquids.IPressure;
import liquidmechanics.api.liquids.LiquidData;
import liquidmechanics.api.liquids.LiquidHandler;
import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.handlers.UpdateConverter; import liquidmechanics.common.handlers.UpdateConverter;
import net.minecraft.block.Block; import net.minecraft.block.Block;

View file

@ -3,10 +3,10 @@ package liquidmechanics.common.tileentity;
import java.util.EnumSet; import java.util.EnumSet;
import liquidmechanics.api.IReadOut; import liquidmechanics.api.IReadOut;
import liquidmechanics.api.IPressure;
import liquidmechanics.api.helpers.ColorCode; import liquidmechanics.api.helpers.ColorCode;
import liquidmechanics.api.helpers.LiquidData; import liquidmechanics.api.liquids.IPressure;
import liquidmechanics.api.helpers.LiquidHandler; import liquidmechanics.api.liquids.LiquidData;
import liquidmechanics.api.liquids.LiquidHandler;
import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.MetaGroup; import liquidmechanics.common.MetaGroup;
import liquidmechanics.common.handlers.UpdateConverter; import liquidmechanics.common.handlers.UpdateConverter;

View file

@ -8,12 +8,12 @@ import java.util.List;
import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.FMLLog;
import liquidmechanics.api.IColorCoded; import liquidmechanics.api.IColorCoded;
import liquidmechanics.api.IPressure;
import liquidmechanics.api.IReadOut; import liquidmechanics.api.IReadOut;
import liquidmechanics.api.helpers.LiquidData;
import liquidmechanics.api.helpers.LiquidHandler;
import liquidmechanics.api.helpers.ColorCode; import liquidmechanics.api.helpers.ColorCode;
import liquidmechanics.api.helpers.connectionHelper; import liquidmechanics.api.helpers.connectionHelper;
import liquidmechanics.api.liquids.IPressure;
import liquidmechanics.api.liquids.LiquidData;
import liquidmechanics.api.liquids.LiquidHandler;
import liquidmechanics.common.block.BlockReleaseValve; import liquidmechanics.common.block.BlockReleaseValve;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;

View file

@ -1,7 +1,7 @@
package liquidmechanics.common.tileentity; package liquidmechanics.common.tileentity;
import liquidmechanics.api.IForce;
import liquidmechanics.api.IReadOut; import liquidmechanics.api.IReadOut;
import liquidmechanics.api.mech.IForce;
import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.LiquidMechanics;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager; import net.minecraft.network.INetworkManager;

View file

@ -4,11 +4,11 @@ import javax.swing.colorchooser.ColorSelectionModel;
import liquidmechanics.api.IColorCoded; import liquidmechanics.api.IColorCoded;
import liquidmechanics.api.IReadOut; import liquidmechanics.api.IReadOut;
import liquidmechanics.api.IPressure;
import liquidmechanics.api.helpers.LiquidData;
import liquidmechanics.api.helpers.LiquidHandler;
import liquidmechanics.api.helpers.ColorCode; import liquidmechanics.api.helpers.ColorCode;
import liquidmechanics.api.helpers.connectionHelper; import liquidmechanics.api.helpers.connectionHelper;
import liquidmechanics.api.liquids.IPressure;
import liquidmechanics.api.liquids.LiquidData;
import liquidmechanics.api.liquids.LiquidHandler;
import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.handlers.UpdateConverter; import liquidmechanics.common.handlers.UpdateConverter;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;

View file

@ -4,11 +4,11 @@ import javax.swing.colorchooser.ColorSelectionModel;
import liquidmechanics.api.IColorCoded; import liquidmechanics.api.IColorCoded;
import liquidmechanics.api.IReadOut; import liquidmechanics.api.IReadOut;
import liquidmechanics.api.IPressure;
import liquidmechanics.api.helpers.LiquidData;
import liquidmechanics.api.helpers.LiquidHandler;
import liquidmechanics.api.helpers.ColorCode; import liquidmechanics.api.helpers.ColorCode;
import liquidmechanics.api.helpers.connectionHelper; import liquidmechanics.api.helpers.connectionHelper;
import liquidmechanics.api.liquids.IPressure;
import liquidmechanics.api.liquids.LiquidData;
import liquidmechanics.api.liquids.LiquidHandler;
import liquidmechanics.common.LiquidMechanics; import liquidmechanics.common.LiquidMechanics;
import liquidmechanics.common.handlers.UpdateConverter; import liquidmechanics.common.handlers.UpdateConverter;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;