Code cleanup and bug fixes

mainly just a code upload but cleanup and bug fixes were made but not
finished.
This commit is contained in:
Rseifert 2012-07-22 06:56:05 -04:00
parent 916ddca95d
commit 35b1f75329
6 changed files with 193 additions and 301 deletions

View file

@ -8,7 +8,6 @@ import net.minecraft.src.basiccomponents.*;
import net.minecraft.src.eui.boiler.*;
import net.minecraft.src.eui.burner.GUIFireBox;
import net.minecraft.src.eui.burner.TileEntityFireBox;
import net.minecraft.src.eui.grinder.*;
import net.minecraft.src.eui.turbine.GUIGenerator;
import net.minecraft.src.eui.turbine.TileEntityGenerator;
import net.minecraft.src.forge.*;
@ -74,48 +73,37 @@ public class BlockMachine extends net.minecraft.src.universalelectricity.extend.
{
TileEntity tileEntity = par1iBlockAccess.getBlockTileEntity(x, y, z);
int metadata = par1iBlockAccess.getBlockMetadata(x, y, z);
if(metadata > -1 && tileEntity != null)
{
if (side == 1)
{
switch(metadata)
{
case 0: return 1;
case 1: return 3;
case 2: return 18;
case 3: return 5;
case 0: return 6;
case 1: return 4;
case 2: return 7;
case 3: return 4;
}
}
//If it is the front side
if(side == ((TileEntityMachine)tileEntity).getDirection())
{
switch(metadata)
{
case 1: return 3;
case 3: return 3;
}
}
//If it is the back side
else if(side == UniversalElectricity.getOrientationFromSide(((TileEntityMachine)tileEntity).getDirection(), (byte)2))
{
switch(metadata)
{
case 0: return 19;
case 1: return 6;
case 2: return 17;
case 3: return 3;
case 0: return 5;
case 2: return 8;
case 3: return 4;
}
}
switch(metadata)
{
case 1: return 4;
case 2: return 16;
case 3: return 2;
case 1: return 0;
case 2: return 2;
}
return 0;
}
return 1;
}
@ -126,10 +114,10 @@ public class BlockMachine extends net.minecraft.src.universalelectricity.extend.
{
switch(metadata)
{
case 0: return 1;
case 1: return 3;
case 2: return 18;
case 3: return 5;
case 0: return 6;
case 1: return 4;
case 2: return 7;
case 3: return 0;
}
}
else
@ -139,10 +127,10 @@ public class BlockMachine extends net.minecraft.src.universalelectricity.extend.
{
switch(metadata)
{
case 0: return 19;
case 1: return 6;
case 2: return 17;
case 3: return 3;
case 0: return 5;
case 1: return 0;
case 2: return 8;
case 3: return 4;
}
}
//If it is the back side
@ -158,12 +146,12 @@ public class BlockMachine extends net.minecraft.src.universalelectricity.extend.
switch(metadata)
{
case 1: return 4;
case 2: return 16;
case 3: return 2;
case 1: return 0;
case 2: return 2;
case 3: return 0;
}
}
return 0;
return 1;
}
public boolean blockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
{
@ -229,11 +217,7 @@ public class BlockMachine extends net.minecraft.src.universalelectricity.extend.
if (blockEntity != null)
{
if(blockEntity instanceof TileEntityGrinder)
{
TileEntity var6 = (TileEntityGrinder)par1World.getBlockTileEntity(x, y, z);
ModLoader.openGUI(par5EntityPlayer, new GuiGrinder(par5EntityPlayer.inventory, (TileEntityGrinder) var6 )); ;
}
if(blockEntity instanceof TileEntityBoiler)
{
TileEntity var6 = (TileEntityBoiler)par1World.getBlockTileEntity(x, y, z);
@ -258,8 +242,7 @@ public class BlockMachine extends net.minecraft.src.universalelectricity.extend.
public TileEntity getBlockEntity(int meta)
{
switch(meta)
{
case 0: return new TileEntityGrinder();
{
case 1: return new TileEntityBoiler();
case 2: return new TileEntityFireBox();
case 3: return new TileEntityGenerator();
@ -306,8 +289,16 @@ public class BlockMachine extends net.minecraft.src.universalelectricity.extend.
{
if (!keepFurnaceInventory)
{
TileEntityGrinder var5 = (TileEntityGrinder)par1World.getBlockTileEntity(par2, par3, par4);
TileEntityMachine var5 = null;
TileEntity entityBox = par1World.getBlockTileEntity(par2, par3, par4);
if(entityBox instanceof TileEntityFireBox)
{
var5 = (TileEntityFireBox)entityBox;
}
else if(entityBox instanceof TileEntityBoiler)
{
var5 = (TileEntityBoiler)entityBox;
}
if (var5 != null)
{
for (int var6 = 0; var6 < var5.getSizeInventory(); ++var6)
@ -369,13 +360,10 @@ public class BlockMachine extends net.minecraft.src.universalelectricity.extend.
{
return 0;
}
public void addCreativeItems(ArrayList itemList) {
itemList.add(new ItemStack(this, 1,0));
itemList.add(new ItemStack(this, 1,1));
itemList.add(new ItemStack(this, 1,2));
itemList.add(new ItemStack(this, 1,3));
itemList.add(new ItemStack(this, 1,14));
itemList.add(new ItemStack(this, 1,15));
public void addCreativeItems(ArrayList itemList) {
itemList.add(new ItemStack(this, 1,1));//boiler
itemList.add(new ItemStack(this, 1,2));//firebox
itemList.add(new ItemStack(this, 1,3));//generator
itemList.add(new ItemStack(this, 1,15));//eu vamp
}
}

View file

@ -34,15 +34,5 @@ public class ItemMachine extends ItemBlock {
}
return this.getItemName();
}
@Override
public void addCreativeItems(ArrayList itemList) {
itemList.add(new ItemStack(this, 1,0));
itemList.add(new ItemStack(this, 1,1));
itemList.add(new ItemStack(this, 1,2));
itemList.add(new ItemStack(this, 1,3));
itemList.add(new ItemStack(this, 1,15));
}
}

View file

@ -1,13 +1,14 @@
package net.minecraft.src.eui;
import net.minecraft.src.*;
import net.minecraft.src.eui.boiler.TileEntityBoiler;
import net.minecraft.src.forge.ITextureProvider;
import net.minecraft.src.universalelectricity.electricity.TileEntityElectricUnit;
import net.minecraft.src.universalelectricity.extend.IRotatable;
public class TileEntityMachine extends TileEntityElectricUnit implements ITextureProvider, IRotatable
{
private byte facing;
private byte facing = 0;
public TileEntity getSteamMachine(int i)
{
@ -74,4 +75,20 @@ public class TileEntityMachine extends TileEntityElectricUnit implements ITextur
// TODO Auto-generated method stub
return false;
}
public int getSizeInventory() {
// TODO Auto-generated method stub
return 0;
}
public ItemStack getStackInSlot(int var6) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean canUpdate()
{
return true;
}
}

View file

@ -0,0 +1,15 @@
package net.minecraft.src.eui.boiler;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
public class ShareResources {
}

View file

@ -16,7 +16,7 @@ public class TileEntityBoiler extends TileEntityMachine implements IInventory, I
/**
* The ItemStacks that hold the items currently being used in the furnace
*/
private ItemStack[] furnaceItemStacks = new ItemStack[3];
private ItemStack[] furnaceItemStacks = new ItemStack[1];
/** The number of ticks that the boiler will keep burning */
public int RunTime = 0;
@ -33,8 +33,9 @@ public class TileEntityBoiler extends TileEntityMachine implements IInventory, I
public int hullHeat = 0;
public int hullHeatMax = 10000;
private int heatTick = 0;
public TileEntity[] connectedBlocks = {null, null, null, null, null, null};
public TileEntity[] connectedFaces = {null, null, null, null, null, null, null, null};
int count = 0;
boolean hullHeated = false;
TileEntity[] connectedBlocks = {null, null, null, null, null, null};
int steamMax = 140;
public boolean isBeingHeated = false;
/**
@ -52,11 +53,7 @@ public class TileEntityBoiler extends TileEntityMachine implements IInventory, I
{
return this.furnaceItemStacks[par1];
}
/**
* Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
* stack.
*/
public ItemStack decrStackSize(int par1, int par2)
{
if (this.furnaceItemStacks[par1] != null)
@ -205,48 +202,19 @@ public class TileEntityBoiler extends TileEntityMachine implements IInventory, I
{
return false;
}
}
private int getTextureFront() {
return 0;
}
public TileEntity getFacingBoilers(int i)
{
int x = this.xCoord;
int y = this.yCoord;
int z = this.zCoord;
switch(i){
case 0: y = y - 1;break;
case 1: y = y + 1;break;
case 2: z = z + 1;break;
case 3: z = z - 1;break;
case 4: x = x + 1;break;
case 5: x = x - 1;break;
}
TileEntity aEntity = worldObj.getBlockTileEntity(x, y, z);
if(aEntity instanceof TileEntityBoiler)
{
return aEntity;
}
return null;
}
int count = 0;
}
@Override
public void updateEntity(){
if(count == 20){
isBeingHeated = getIsHeated();
addConnection();
shareResources();
count++;
if(count >= 20){
isBeingHeated = getIsHeated();
addWater();//adds water from container slot
shareWater();
count = 0;
}
else
{
count++;
}
boolean hullHeated = false;
//changed hullHeat max depending on contents of boiler
if(waterStored>0)
if(waterStored > 0)
{
hullHeatMax = 4700;
if(hullHeat > hullHeatMax)
@ -280,8 +248,7 @@ public class TileEntityBoiler extends TileEntityMachine implements IInventory, I
heatTick += 1;
}
}
//adds water from container slot
addWater();
int heatNeeded = mod_EUIndustry.boilerHeat; // kilo joules
//if hull heated do work
@ -312,190 +279,118 @@ public class TileEntityBoiler extends TileEntityMachine implements IInventory, I
}
}
}
int transferW = 0;
int transferS = 0;
int transferH = 0;
public void shareResources()
{
for(int i = 0; i<6; i++)
}
public void shareWater()
{
int wSum = getStoredLiquid(1); //pre-sets the sum to the first tanks current volume
int tankCount = 1; //amount of tanks around this tank, used to get avarage liquid ammount
boolean bottom = false; // whether or not this tanks need to worry about what is bellow it
TileEntity entityBellow = worldObj.getBlockTileEntity(this.xCoord,this.yCoord-1, this.zCoord);
TileEntity entityAbove = worldObj.getBlockTileEntity(this.xCoord,this.yCoord+1, this.zCoord);
//checks wether or not the block bellow it is a tank to move liquid too
if(entityBellow instanceof TileEntityBoiler)
{
if(connectedBlocks[i] instanceof TileEntityBoiler)
{
TileEntityBoiler connectedConsumer = (TileEntityBoiler)connectedBlocks[i];
//add steam to other boiler if less
boolean canTradeSteam;
if( i ==0)
{
if(this.steamStored == this.steamMax)
int bWater = ((TileEntityBoiler) entityBellow).getStoredLiquid(1);
int bMax = ((TileEntityBoiler) entityBellow).getLiquidCapacity(1);
//checks if that tank has room to get liquid.
if(bWater < bMax)
{
int emptyVol = Math.max( bMax - bWater,0);
int tradeVol = Math.min(emptyVol, waterStored);
int rejected = ((TileEntityBoiler) entityBellow).onReceiveLiquid(1, tradeVol, (byte) 1);
waterStored = Math.max(waterStored - rejected,0);
wSum -= rejected;
}
else
{
canTradeSteam = true;
}
else
{
canTradeSteam = false;
bottom = true;
}
}
else
{
canTradeSteam = true;
}
if(canTradeSteam)
//there was no tank bellow this tank
bottom = true;
}
//if this is the bottom tank or bottom tank is full then trade liquid with tanks around it.
if(bottom)
{
if( this.steamStored > 0)
//get average water around center tank
for(int i = 0; i<4;i++)
{
int x = this.xCoord;
int z = this.zCoord;
//switch to check each side TODO rewrite for side values
switch(i)
{
int SSum = (this.steamStored + connectedConsumer.steamStored)/2;
if(i == 1 && connectedConsumer.steamStored < connectedConsumer.steamMax && this.steamStored > 0){
if(this.steamStored >= 10 )
{
int rejectedW = connectedConsumer.addSteam(10);
this.steamStored = Math.max(Math.min(this.steamStored - 10 + rejectedW, this.steamMax), 0);
}
else
{
int rejectedW = connectedConsumer.addSteam(this.steamStored);
this.steamStored = Math.max(Math.min(this.steamStored - this.steamStored + rejectedW, this.steamMax), 0);
}
}
if(this.steamStored > connectedConsumer.steamStored)
{
transferS = SSum - connectedConsumer.steamStored;
int rejectedS = connectedConsumer.addSteam(transferS);
this.steamStored = Math.max(Math.min(this.steamStored - transferS + rejectedS, 140), 0);
}
case 0: --x;
case 1: ++x;
case 2: --z;
case 3: ++z;
}
}
//add water to other boiler if less
if( this.waterStored > 0)
{
boolean canTradeWater;
if( i ==1)
{
if(this.waterStored == this.getLiquidCapacity(1))
{
canTradeWater = true;
}
else
{
canTradeWater = false;
}
}
else
{
canTradeWater = true;
}
if(canTradeWater)
{
int WSum = (this.waterStored + connectedConsumer.waterStored)/2;
if(i == 0 && this.waterStored > 0 && connectedConsumer.waterStored < connectedConsumer.getLiquidCapacity(1))
{
int rejectedW = connectedConsumer.addwater(1);
this.waterStored = Math.max(Math.min(this.waterStored - 1 + rejectedW, this.getLiquidCapacity(1)), 0);
}
if(this.waterStored > connectedConsumer.waterStored)
{
transferW =Math.round(WSum - connectedConsumer.waterStored);
if(transferW > 0)
{
int rejectedW = connectedConsumer.addwater(transferW);
this.waterStored = Math.max(Math.min(this.waterStored - transferW + rejectedW, this.getLiquidCapacity(1)), 0);
}
}
}
}
//add heat to other boiler if less
boolean canTradeHeat;
if(this.heatStored == heatMax || !isBeingHeated)
{
canTradeHeat = true;
}
else
{
canTradeHeat = false;
}
if(canTradeHeat)
TileEntity entity = worldObj.getBlockTileEntity(x,this.yCoord, z);
if(entity instanceof TileEntityBoiler)
{
if( this.heatStored > 0)
{
if(this.heatStored > connectedConsumer.heatStored )
{
int HSum = (this.heatStored + connectedConsumer.heatStored)/2;
transferH = HSum - connectedConsumer.heatStored;
int rejectedH = connectedConsumer.onReceiveHeat(transferH);
this.heatStored = Math.max(Math.min(this.waterStored - transferW + rejectedH, heatMax), 0);
}
}
//if is a tank add to the sum
wSum += ((TileEntityBoiler) entity).getStoredLiquid(1);
tankCount += 1;
}
}
}
}
private int onProduceWater(int t, int i) {
if(waterStored - t > 0)
//transfers water
for(int i = 0; i<4;i++)
{
waterStored = waterStored - t;
return t;
int average = wSum / tankCount;// takes the sum and makes it an average
int x2 = this.xCoord;
int z2 = this.zCoord;
int tradeSum = 0;
//switch to check each side TODO rewrite for side values
switch(i)
{
case 0: --x2;
case 1: ++x2;
case 2: --z2;
case 3: ++z2;
}
TileEntity entity = worldObj.getBlockTileEntity(x2,this.yCoord, z2);
if(entity instanceof TileEntityBoiler)
{
int targetW = ((TileEntityBoiler) entity).getStoredLiquid(1);
if(targetW < average)
{
tradeSum = Math.min(average, waterStored); //gets the ammount to give to the target tank
int rejectedAm = ((TileEntityBoiler) entity).onReceiveLiquid(1, tradeSum, (byte) i); //send that ammount with safty incase some comes back
waterStored =rejectedAm + waterStored - tradeSum; //counts up current water sum after trade
}
}
}
if(entityAbove instanceof TileEntityBoiler)
{
int bWater = ((TileEntityBoiler) entityAbove).getStoredLiquid(1);
int bMax = ((TileEntityBoiler) entityAbove).getLiquidCapacity(1);
if(bottom && waterStored > 0)
{
if(bWater < bMax)
{
int emptyVolS = Math.max( bMax - bWater,0);
int tradeVolS = Math.min(emptyVolS, steamStored);
int rejectedS = ((TileEntityBoiler) entityAbove).addSteam(tradeVolS);
waterStored = Math.max(waterStored - rejectedS,0);
wSum -= rejectedS;
}
}
}
return 0;
}
public void addConnection()
{
for(int i = 0; i<6; i++)
{
TileEntity aEntity = getSteamMachine(i);
if(aEntity instanceof TileEntityBoiler)
{
this.connectedBlocks[i] = aEntity;
}
else
{
this.connectedBlocks[i] = null;
}
}
}
}
public int addSteam(int watt) {
int rejectedElectricity = Math.max((this.steamStored + watt) - steamMax, 0);
this.steamStored += watt - rejectedElectricity;
return rejectedElectricity;
}
public int addwater(int watt) {
int rejectedElectricity = Math.max((this.waterStored + watt) - this.getLiquidCapacity(1), 0);
this.waterStored += watt - rejectedElectricity;
return rejectedElectricity;
}
public int onReceiveHeat(int watt) {
if(heatStored < heatMax)
{
int rejectedElectricity = Math.max((this.heatStored + watt) - heatMax, 0);
this.heatStored += watt - rejectedElectricity;
return rejectedElectricity;
}
return watt;
}
/**
* adds water too the system
*/
private void addWater() {
if (this.furnaceItemStacks[0] != null)
{
@ -527,9 +422,7 @@ public class TileEntityBoiler extends TileEntityMachine implements IInventory, I
@Override
public int getStartInventorySide(int side)
{
if (side == 0) return 1;
if (side == 1) return 0;
return 2;
return 0;
}
@Override
@ -588,16 +481,20 @@ public class TileEntityBoiler extends TileEntityMachine implements IInventory, I
{
return 14;
}
if(type == 0)
{
return steamMax;
}
return 0;
}
@Override
public int onProduceLiquid(int type, int maxVol, int side) {
if(type == 0)
{
if(steamStored > maxVol)
if(steamStored > 1)
{
this.steamStored -= maxVol;
return maxVol;
this.steamStored -= 1;
return 1;
}
}
return 0;

View file

@ -4,7 +4,6 @@ import net.minecraft.src.basiccomponents.BasicComponents;
import net.minecraft.src.eui.*;
import net.minecraft.src.eui.boiler.TileEntityBoiler;
import net.minecraft.src.eui.burner.TileEntityFireBox;
import net.minecraft.src.eui.grinder.TileEntityGrinder;
import net.minecraft.src.eui.turbine.TileEntityGenerator;
import net.minecraft.src.forge.*;
import net.minecraft.src.universalelectricity.*;
@ -14,19 +13,13 @@ import java.util.Map;
import java.io.*;
public class mod_EUIndustry extends NetworkMod {
static Configuration config = new Configuration((new File(Minecraft.getMinecraftDir(), "config/EUIndustry/SteamPower.cfg")));
private static int coalID = configurationProperties();
private static int BlockID;
public static int pipeID;
public static int partID;
public static int pipeBlockID;
public static int pipeBlockID2;
private static int BlockID= configurationProperties();
public static int genOutput;
public static int steamOutBoiler;
public static int pipeLoss;
public static int boilerHeat;
public static int fireOutput;
public static Block machine = new net.minecraft.src.eui.BlockMachine(BlockID).setBlockName("machine");
public static Item coalNugget = new net.minecraft.src.eui.ItemCoalFuel(coalID);
@Override
public String getVersion() {
// TODO change version on each update ;/
@ -34,19 +27,14 @@ public class mod_EUIndustry extends NetworkMod {
}
public static int configurationProperties()
{
config.load();
coalID = Integer.parseInt(config.getOrCreateIntProperty("coalItems", Configuration.CATEGORY_ITEM, 30439).value);
pipeBlockID = Integer.parseInt(config.getOrCreateIntProperty("PipeS", Configuration.CATEGORY_BLOCK, 128).value);
pipeBlockID2 = Integer.parseInt(config.getOrCreateIntProperty("PipeW", Configuration.CATEGORY_BLOCK, 130).value);
BlockID = Integer.parseInt(config.getOrCreateIntProperty("Machines", Configuration.CATEGORY_BLOCK, 129).value);
pipeID = Integer.parseInt(config.getOrCreateIntProperty("pipes", Configuration.CATEGORY_ITEM, 30433).value);
partID = Integer.parseInt(config.getOrCreateIntProperty("parts", Configuration.CATEGORY_ITEM, 30434).value);
config.load();
BlockID = Integer.parseInt(config.getOrCreateIntProperty("Machines", Configuration.CATEGORY_BLOCK, 129).value);
genOutput = Integer.parseInt(config.getOrCreateIntProperty("genOutputWatts", Configuration.CATEGORY_GENERAL, 1000).value);
steamOutBoiler = Integer.parseInt(config.getOrCreateIntProperty("steamOutBoiler", Configuration.CATEGORY_GENERAL, 10).value);
boilerHeat = Integer.parseInt(config.getOrCreateIntProperty("boilerInKJ", Configuration.CATEGORY_GENERAL, 4500).value);
fireOutput = Integer.parseInt(config.getOrCreateIntProperty("fireBoxOutKJ", Configuration.CATEGORY_GENERAL,50).value);
config.save();
return coalID;
return BlockID;
}
@Override
public void modsLoaded()
@ -69,9 +57,6 @@ public class mod_EUIndustry extends NetworkMod {
ModLoader.addName((new ItemStack(machine, 1, 2)), "FireBox");
ModLoader.addName((new ItemStack(machine, 1, 3)), "SteamGen");
ModLoader.addName((new ItemStack(machine, 1, 15)), "EUVampire");
ModLoader.addName((new ItemStack(coalNugget, 1, 0)), "CoalNuggets");
ModLoader.addName((new ItemStack(coalNugget, 1, 1)), "CoalPellets");
ModLoader.addName((new ItemStack(coalNugget, 1, 2)), "CoalDust");
//Crafting
/**
* case 0: return new TileEntityGrinder(); <-Removed