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>>>"; String output = "Debug>>>";
output += "Channel:" + (asm.getTileNetwork() != null ? asm.getTileNetwork().toString() : "Error") + "|"; output += "Channel:" + (asm.getTileNetwork() != null ? asm.getTileNetwork().toString() : "Error") + "|";
entityPlayer.sendChatToPlayer(output); 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); 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) if (((TileEntityAssembly) part).powered)
{ {
this.markAsPowerSource((TileEntity) part); this.markAsPowerSource((TileEntity) part, true);
} }
} }
return added; return added;
@ -81,18 +81,21 @@ public class NetworkAssembly extends NetworkTileEntities
return super.isValidMember(part) && part instanceof TileEntityAssembly; return super.isValidMember(part) && part instanceof TileEntityAssembly;
} }
/** Marks a tile as the source of power for the network */ /** Marks a tile as the source of power for the network
public void markAsPowerSource(TileEntity entity) *
* @param powered true to add, false to remove */
public void markAsPowerSource(TileEntity entity, boolean powered)
{ {
if (!this.powerSources.contains(entity)) if (powered)
{ {
this.powerSources.add(entity); if (!this.powerSources.contains(entity))
{
this.powerSources.add(entity);
}
}
else
{
this.powerSources.remove(entity);
} }
} }
/** unmarks or removes the tile as a source of power for the network */
public void removeAsPowerSource(TileEntity entity)
{
this.powerSources.remove(entity);
}
} }

View file

@ -1,8 +1,11 @@
package assemblyline.common.machine; package assemblyline.common.machine;
import java.util.Random;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.vector.Vector3;
import assemblyline.common.AssemblyLine; import assemblyline.common.AssemblyLine;
import dark.core.api.INetworkPart; import dark.core.api.INetworkPart;
import dark.core.tile.network.NetworkTileEntities; import dark.core.tile.network.NetworkTileEntities;
@ -20,32 +23,45 @@ public abstract class TileEntityAssembly extends TileEntityRunnableMachine imple
private NetworkAssembly assemblyNetwork; private NetworkAssembly assemblyNetwork;
/** Tiles that are connected to this */ /** Tiles that are connected to this */
private TileEntity[] connectedTiles = new TileEntity[6]; 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 @Override
public void updateEntity() public void updateEntity()
{ {
super.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()) if (this.wattsReceived >= this.getRequest().getWatts())
{ {
this.wattsReceived -= getRequest().getWatts(); this.wattsReceived -= getRequest().getWatts();
this.powered = true; this.powered = true;
if (this.getTileNetwork() instanceof NetworkAssembly) this.powerTicks = 2;
{
NetworkAssembly net = ((NetworkAssembly) this.getTileNetwork()); }
net.markAsPowerSource(this); else if (this.powerTicks > 0)
} {
this.powerTicks--;
this.powered = true;
} }
else else
{ {
this.powered = false; this.powered = false;
if (this.getTileNetwork() instanceof NetworkAssembly) }
{ if (this.getTileNetwork() instanceof NetworkAssembly)
NetworkAssembly net = ((NetworkAssembly) this.getTileNetwork()); {
net.removeAsPowerSource(this); NetworkAssembly net = ((NetworkAssembly) this.getTileNetwork());
} net.markAsPowerSource(this, this.powered);
} }
this.onUpdate(); 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 @Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving par5EntityLiving, ItemStack stack) 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 angle = MathHelper.floor_double((par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
int change = 2; int change = 2;