more work on tile network code

This commit is contained in:
DarkGuardsman 2013-06-30 19:25:37 -04:00
parent 1160213f47
commit 12ea85d5b9
4 changed files with 52 additions and 24 deletions

View file

@ -39,6 +39,9 @@ public class BlockALMachine extends BlockAdvanced
String output = "Debug>>>";
output += "Channel:" + (asm.getTileNetwork() != null ? asm.getTileNetwork().toString() : "Error") + "|";
entityPlayer.sendChatToPlayer(output);
output = "Debug>>>";
output += "Powered:"+asm.powered + " By:"+(asm.powerSource != null ? asm.powerSource.toString() : "Error");
entityPlayer.sendChatToPlayer(output);
}
return super.onBlockActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ);
}

View file

@ -69,7 +69,7 @@ public class NetworkAssembly extends NetworkTileEntities
{
if (((TileEntityAssembly) part).powered)
{
this.markAsPowerSource((TileEntity) part);
this.markAsPowerSource((TileEntity) part, true);
}
}
return added;
@ -81,18 +81,21 @@ public class NetworkAssembly extends NetworkTileEntities
return super.isValidMember(part) && part instanceof TileEntityAssembly;
}
/** Marks a tile as the source of power for the network */
public void markAsPowerSource(TileEntity entity)
/** Marks a tile as the source of power for the network
*
* @param powered true to add, false to remove */
public void markAsPowerSource(TileEntity entity, boolean powered)
{
if (powered)
{
if (!this.powerSources.contains(entity))
{
this.powerSources.add(entity);
}
}
/** unmarks or removes the tile as a source of power for the network */
public void removeAsPowerSource(TileEntity entity)
else
{
this.powerSources.remove(entity);
}
}
}

View file

@ -1,8 +1,11 @@
package assemblyline.common.machine;
import java.util.Random;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.vector.Vector3;
import assemblyline.common.AssemblyLine;
import dark.core.api.INetworkPart;
import dark.core.tile.network.NetworkTileEntities;
@ -20,32 +23,45 @@ public abstract class TileEntityAssembly extends TileEntityRunnableMachine imple
private NetworkAssembly assemblyNetwork;
/** Tiles that are connected to this */
private TileEntity[] connectedTiles = new TileEntity[6];
private TileEntityAssembly powerSource;
/** Cached power source to reduce the need to path find for a new one each tick */
public TileEntityAssembly powerSource;
/** Random instance */
public Random random = new Random();
/** Number of ticks this can go without power */
private int powerTicks = 0;
private int updateTick = 1;
@Override
public void updateEntity()
{
super.updateEntity();
if (ticks % updateTick == 0)
{
this.updateTick = ((int) random.nextInt(10) + 20);
this.updateNetworkConnections();
this.powerSource = null;
}
if (this.wattsReceived >= this.getRequest().getWatts())
{
this.wattsReceived -= getRequest().getWatts();
this.powered = true;
if (this.getTileNetwork() instanceof NetworkAssembly)
{
NetworkAssembly net = ((NetworkAssembly) this.getTileNetwork());
net.markAsPowerSource(this);
this.powerTicks = 2;
}
else if (this.powerTicks > 0)
{
this.powerTicks--;
this.powered = true;
}
else
{
this.powered = false;
}
if (this.getTileNetwork() instanceof NetworkAssembly)
{
NetworkAssembly net = ((NetworkAssembly) this.getTileNetwork());
net.removeAsPowerSource(this);
}
net.markAsPowerSource(this, this.powered);
}
this.onUpdate();
@ -137,4 +153,9 @@ public abstract class TileEntityAssembly extends TileEntityRunnableMachine imple
}
}
public String toString()
{
return "AssemblyTile>>>At>>>" + (new Vector3(this).toString());
}
}

View file

@ -170,6 +170,7 @@ public class BlockConveyorBelt extends BlockALMachine
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving par5EntityLiving, ItemStack stack)
{
super.onBlockPlacedBy(world, x, y, z, par5EntityLiving, stack);
int angle = MathHelper.floor_double((par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
int change = 2;