Greatly improve performance of transmitter networks, improved logistics of Mechanical Pipe
This commit is contained in:
parent
c10ba92522
commit
a360255f63
16 changed files with 317 additions and 261 deletions
|
@ -6,12 +6,15 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import mekanism.api.Object3D;
|
import mekanism.api.Object3D;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
@ -23,10 +26,14 @@ public abstract class DynamicNetwork<A, N> implements ITransmitterNetwork<A, N>
|
||||||
public HashSet<A> possibleAcceptors = new HashSet<A>();
|
public HashSet<A> possibleAcceptors = new HashSet<A>();
|
||||||
public HashMap<A, ForgeDirection> acceptorDirections = new HashMap<A, ForgeDirection>();
|
public HashMap<A, ForgeDirection> acceptorDirections = new HashMap<A, ForgeDirection>();
|
||||||
|
|
||||||
|
private List<DelayQueue> updateQueue = new ArrayList<DelayQueue>();
|
||||||
|
|
||||||
protected int ticksSinceCreate = 0;
|
protected int ticksSinceCreate = 0;
|
||||||
|
|
||||||
protected boolean fixed = false;
|
protected boolean fixed = false;
|
||||||
|
|
||||||
|
protected boolean needsUpdate = false;
|
||||||
|
|
||||||
protected abstract ITransmitterNetwork<A, N> create(ITransmitter<N>... varTransmitters);
|
protected abstract ITransmitterNetwork<A, N> create(ITransmitter<N>... varTransmitters);
|
||||||
|
|
||||||
protected abstract ITransmitterNetwork<A, N> create(Collection<ITransmitter<N>> collection);
|
protected abstract ITransmitterNetwork<A, N> create(Collection<ITransmitter<N>> collection);
|
||||||
|
@ -94,6 +101,25 @@ public abstract class DynamicNetwork<A, N> implements ITransmitterNetwork<A, N>
|
||||||
fixMessedUpNetwork(transmitters.iterator().next());
|
fixMessedUpNetwork(transmitters.iterator().next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||||
|
{
|
||||||
|
Iterator<DelayQueue> i = updateQueue.iterator();
|
||||||
|
|
||||||
|
while(i.hasNext())
|
||||||
|
{
|
||||||
|
DelayQueue q = i.next();
|
||||||
|
|
||||||
|
if(q.delay > 0)
|
||||||
|
{
|
||||||
|
q.delay--;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
needsUpdate = true;
|
||||||
|
i.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -195,6 +221,11 @@ public abstract class DynamicNetwork<A, N> implements ITransmitterNetwork<A, N>
|
||||||
fixed = value;
|
fixed = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addUpdate(EntityPlayer player)
|
||||||
|
{
|
||||||
|
updateQueue.add(new DelayQueue(player));
|
||||||
|
}
|
||||||
|
|
||||||
public static class NetworkFinder
|
public static class NetworkFinder
|
||||||
{
|
{
|
||||||
public TransmissionType transmissionType;
|
public TransmissionType transmissionType;
|
||||||
|
@ -254,4 +285,16 @@ public abstract class DynamicNetwork<A, N> implements ITransmitterNetwork<A, N>
|
||||||
return iterated;
|
return iterated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class DelayQueue
|
||||||
|
{
|
||||||
|
public EntityPlayer player;
|
||||||
|
public int delay;
|
||||||
|
|
||||||
|
public DelayQueue(EntityPlayer p)
|
||||||
|
{
|
||||||
|
player = p;
|
||||||
|
delay = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package mekanism.api.transmitters;
|
package mekanism.api.transmitters;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
@ -138,19 +136,14 @@ public class TransmitterNetworkRegistry implements ITickHandler
|
||||||
try {
|
try {
|
||||||
if(c != null)
|
if(c != null)
|
||||||
{
|
{
|
||||||
Map copy = (Map)((HashMap)c.chunkTileEntityMap).clone();
|
for(Iterator iter = c.chunkTileEntityMap.values().iterator(); iter.hasNext();)
|
||||||
|
|
||||||
for(Object obj : copy.values())
|
|
||||||
{
|
{
|
||||||
if(obj instanceof TileEntity)
|
Object obj = iter.next();
|
||||||
|
|
||||||
|
if(obj instanceof ITransmitter && !((TileEntity)obj).worldObj.isRemote)
|
||||||
{
|
{
|
||||||
TileEntity tileEntity = (TileEntity)obj;
|
((ITransmitter)obj).refreshTransmitterNetwork();
|
||||||
|
((ITransmitter)obj).chunkLoad();
|
||||||
if(tileEntity instanceof ITransmitter)
|
|
||||||
{
|
|
||||||
((ITransmitter)tileEntity).refreshTransmitterNetwork();
|
|
||||||
((ITransmitter)tileEntity).chunkLoad();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
package mekanism.client;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import mekanism.api.transmitters.TransmissionType;
|
|
||||||
import mekanism.api.transmitters.DynamicNetwork.NetworkFinder;
|
|
||||||
import mekanism.api.Object3D;
|
|
||||||
import mekanism.common.tileentity.TileEntityUniversalCable;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
public class EnergyClientUpdate
|
|
||||||
{
|
|
||||||
public NetworkFinder finder;
|
|
||||||
|
|
||||||
public World worldObj;
|
|
||||||
|
|
||||||
public double energyScale;
|
|
||||||
|
|
||||||
public EnergyClientUpdate(TileEntity head, double power)
|
|
||||||
{
|
|
||||||
worldObj = head.worldObj;
|
|
||||||
energyScale = power;
|
|
||||||
finder = new NetworkFinder(head.worldObj, TransmissionType.ENERGY, Object3D.get(head));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clientUpdate()
|
|
||||||
{
|
|
||||||
List<Object3D> found = finder.exploreNetwork();
|
|
||||||
|
|
||||||
for(Object3D object : found)
|
|
||||||
{
|
|
||||||
TileEntity tileEntity = object.getTileEntity(worldObj);
|
|
||||||
|
|
||||||
if(tileEntity instanceof TileEntityUniversalCable)
|
|
||||||
{
|
|
||||||
((TileEntityUniversalCable)tileEntity).setCachedEnergy(energyScale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +1,7 @@
|
||||||
package mekanism.client;
|
package mekanism.client;
|
||||||
|
|
||||||
import java.util.List;
|
import mekanism.api.transmitters.ITransmitter;
|
||||||
|
import mekanism.common.FluidNetwork;
|
||||||
import mekanism.api.transmitters.TransmissionType;
|
|
||||||
import mekanism.api.transmitters.DynamicNetwork.NetworkFinder;
|
|
||||||
import mekanism.api.Object3D;
|
|
||||||
import mekanism.common.tileentity.TileEntityMechanicalPipe;
|
import mekanism.common.tileentity.TileEntityMechanicalPipe;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -12,31 +9,16 @@ import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
public class FluidClientUpdate
|
public class FluidClientUpdate
|
||||||
{
|
{
|
||||||
public NetworkFinder finder;
|
|
||||||
|
|
||||||
public World worldObj;
|
public World worldObj;
|
||||||
|
|
||||||
public FluidStack fluidStack;
|
public FluidStack fluidStack;
|
||||||
|
|
||||||
|
public TileEntity tileEntity;
|
||||||
|
|
||||||
public FluidClientUpdate(TileEntity head, FluidStack fluid)
|
public FluidClientUpdate(TileEntity head, FluidStack fluid)
|
||||||
{
|
{
|
||||||
worldObj = head.worldObj;
|
worldObj = head.worldObj;
|
||||||
|
tileEntity = head;
|
||||||
fluidStack = fluid;
|
fluidStack = fluid;
|
||||||
finder = new NetworkFinder(head.worldObj, TransmissionType.FLUID, Object3D.get(head));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clientUpdate()
|
|
||||||
{
|
|
||||||
List<Object3D> found = finder.exploreNetwork();
|
|
||||||
|
|
||||||
for(Object3D object : found)
|
|
||||||
{
|
|
||||||
TileEntity tileEntity = object.getTileEntity(worldObj);
|
|
||||||
|
|
||||||
if(tileEntity instanceof TileEntityMechanicalPipe)
|
|
||||||
{
|
|
||||||
((TileEntityMechanicalPipe)tileEntity).onTransfer(fluidStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,47 +60,50 @@ public class RenderMechanicalPipe extends TileEntitySpecialRenderer
|
||||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
if(tileEntity.fluidScale > 0 && tileEntity.refFluid != null)
|
Fluid fluid = tileEntity.getTransmitterNetwork().refFluid;
|
||||||
|
float scale = tileEntity.getTransmitterNetwork().fluidScale;
|
||||||
|
|
||||||
|
if(scale > 0 && fluid != null)
|
||||||
{
|
{
|
||||||
push();
|
push();
|
||||||
|
|
||||||
MekanismRenderer.glowOn(tileEntity.refFluid.getFluid().getLuminosity());
|
MekanismRenderer.glowOn(fluid.getLuminosity());
|
||||||
|
|
||||||
bindTexture(MekanismRenderer.getBlocksTexture());
|
bindTexture(MekanismRenderer.getBlocksTexture());
|
||||||
GL11.glTranslatef((float)x, (float)y, (float)z);
|
GL11.glTranslatef((float)x, (float)y, (float)z);
|
||||||
|
|
||||||
boolean gas = tileEntity.refFluid.getFluid().isGaseous();
|
boolean gas = fluid.isGaseous();
|
||||||
|
|
||||||
for(int i = 0; i < 6; i++)
|
for(int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
if(connectable[i])
|
if(connectable[i])
|
||||||
{
|
{
|
||||||
DisplayInteger[] displayLists = getListAndRender(ForgeDirection.getOrientation(i), tileEntity.refFluid.getFluid());
|
DisplayInteger[] displayLists = getListAndRender(ForgeDirection.getOrientation(i), fluid);
|
||||||
|
|
||||||
if(displayLists != null)
|
if(displayLists != null)
|
||||||
{
|
{
|
||||||
if(!gas)
|
if(!gas)
|
||||||
{
|
{
|
||||||
displayLists[Math.max(0, (int)((float)tileEntity.fluidScale*(stages-1)))].render();
|
displayLists[Math.max(0, (int)((float)scale*(stages-1)))].render();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
GL11.glColor4f(1F, 1F, 1F, tileEntity.fluidScale);
|
GL11.glColor4f(1F, 1F, 1F, scale);
|
||||||
displayLists[stages-1].render();
|
displayLists[stages-1].render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayInteger[] displayLists = getListAndRender(ForgeDirection.UNKNOWN, tileEntity.refFluid.getFluid());
|
DisplayInteger[] displayLists = getListAndRender(ForgeDirection.UNKNOWN, fluid);
|
||||||
|
|
||||||
if(displayLists != null)
|
if(displayLists != null)
|
||||||
{
|
{
|
||||||
if(!gas)
|
if(!gas)
|
||||||
{
|
{
|
||||||
displayLists[Math.max(3, (int)((float)tileEntity.fluidScale*(stages-1)))].render();
|
displayLists[Math.max(3, (int)((float)scale*(stages-1)))].render();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
GL11.glColor4f(1F, 1F, 1F, tileEntity.fluidScale);
|
GL11.glColor4f(1F, 1F, 1F, scale);
|
||||||
displayLists[stages-1].render();
|
displayLists[stages-1].render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class RenderUniversalCable extends TileEntitySpecialRenderer
|
||||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
if(tileEntity.getEnergyScale() <= 0 || !MekanismClient.fancyUniversalCableRender)
|
if(tileEntity.getTransmitterNetwork().clientEnergyScale <= 0 || !MekanismClient.fancyUniversalCableRender)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ public class RenderUniversalCable extends TileEntitySpecialRenderer
|
||||||
push();
|
push();
|
||||||
|
|
||||||
MekanismRenderer.glowOn();
|
MekanismRenderer.glowOn();
|
||||||
GL11.glColor4f(1F, 1F, 1F, tileEntity.getEnergyScale());
|
GL11.glColor4f(1F, 1F, 1F, (float)tileEntity.getTransmitterNetwork().clientEnergyScale);
|
||||||
bindTexture(MekanismRenderer.getBlocksTexture());
|
bindTexture(MekanismRenderer.getBlocksTexture());
|
||||||
GL11.glTranslatef((float)x, (float)y, (float)z);
|
GL11.glTranslatef((float)x, (float)y, (float)z);
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
||||||
private double joulesTransmitted = 0;
|
private double joulesTransmitted = 0;
|
||||||
private double joulesLastTick = 0;
|
private double joulesLastTick = 0;
|
||||||
|
|
||||||
private List<DelayQueue> updateQueue = new ArrayList<DelayQueue>();
|
public double clientEnergyScale = 0;
|
||||||
|
|
||||||
private boolean needsUpdate = false;
|
|
||||||
|
|
||||||
public EnergyNetwork(ITransmitter<EnergyNetwork>... varCables)
|
public EnergyNetwork(ITransmitter<EnergyNetwork>... varCables)
|
||||||
{
|
{
|
||||||
|
@ -72,6 +70,11 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
||||||
|
|
||||||
public synchronized double getEnergyNeeded(List<TileEntity> ignored)
|
public synchronized double getEnergyNeeded(List<TileEntity> ignored)
|
||||||
{
|
{
|
||||||
|
if(FMLCommonHandler.instance().getEffectiveSide().isClient())
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
double totalNeeded = 0;
|
double totalNeeded = 0;
|
||||||
|
|
||||||
for(TileEntity acceptor : getAcceptors())
|
for(TileEntity acceptor : getAcceptors())
|
||||||
|
@ -109,6 +112,11 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
||||||
|
|
||||||
public synchronized double emit(double energyToSend, ArrayList<TileEntity> ignored)
|
public synchronized double emit(double energyToSend, ArrayList<TileEntity> ignored)
|
||||||
{
|
{
|
||||||
|
if(FMLCommonHandler.instance().getEffectiveSide().isClient())
|
||||||
|
{
|
||||||
|
return energyToSend;
|
||||||
|
}
|
||||||
|
|
||||||
double prevEnergy = energyToSend;
|
double prevEnergy = energyToSend;
|
||||||
double sent;
|
double sent;
|
||||||
|
|
||||||
|
@ -207,6 +215,11 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
||||||
{
|
{
|
||||||
Set<TileEntity> toReturn = new HashSet<TileEntity>();
|
Set<TileEntity> toReturn = new HashSet<TileEntity>();
|
||||||
|
|
||||||
|
if(FMLCommonHandler.instance().getEffectiveSide().isClient())
|
||||||
|
{
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
Set<TileEntity> copy = (Set<TileEntity>)possibleAcceptors.clone();
|
Set<TileEntity> copy = (Set<TileEntity>)possibleAcceptors.clone();
|
||||||
|
|
||||||
for(TileEntity acceptor : copy)
|
for(TileEntity acceptor : copy)
|
||||||
|
@ -355,31 +368,15 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick()
|
public void tick()
|
||||||
{
|
{
|
||||||
clearJoulesTransmitted();
|
|
||||||
|
|
||||||
super.tick();
|
super.tick();
|
||||||
|
|
||||||
|
clearJoulesTransmitted();
|
||||||
|
|
||||||
double currentPowerScale = getPowerScale();
|
double currentPowerScale = getPowerScale();
|
||||||
|
|
||||||
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
|
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||||
{
|
{
|
||||||
Iterator<DelayQueue> i = updateQueue.iterator();
|
|
||||||
|
|
||||||
while(i.hasNext())
|
|
||||||
{
|
|
||||||
DelayQueue q = i.next();
|
|
||||||
|
|
||||||
if(q.delay > 0)
|
|
||||||
{
|
|
||||||
q.delay--;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
needsUpdate = true;
|
|
||||||
i.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(currentPowerScale != lastPowerScale)
|
if(currentPowerScale != lastPowerScale)
|
||||||
{
|
{
|
||||||
needsUpdate = true;
|
needsUpdate = true;
|
||||||
|
@ -411,11 +408,6 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
||||||
return joulesLastTick * 20;
|
return joulesLastTick * 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUpdate(EntityPlayer player)
|
|
||||||
{
|
|
||||||
updateQueue.add(new DelayQueue(player));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected EnergyNetwork create(ITransmitter<EnergyNetwork>... varTransmitters)
|
protected EnergyNetwork create(ITransmitter<EnergyNetwork>... varTransmitters)
|
||||||
{
|
{
|
||||||
|
@ -451,16 +443,4 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
||||||
{
|
{
|
||||||
return ElectricityDisplay.getDisplay((float)(getPower()*Mekanism.TO_UE), ElectricityDisplay.ElectricUnit.JOULES);
|
return ElectricityDisplay.getDisplay((float)(getPower()*Mekanism.TO_UE), ElectricityDisplay.ElectricUnit.JOULES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class DelayQueue
|
|
||||||
{
|
|
||||||
public EntityPlayer player;
|
|
||||||
public int delay;
|
|
||||||
|
|
||||||
public DelayQueue(EntityPlayer p)
|
|
||||||
{
|
|
||||||
player = p;
|
|
||||||
delay = 5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,13 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
|
|
||||||
public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
||||||
{
|
{
|
||||||
|
public int transferDelay = 0;
|
||||||
|
|
||||||
|
public float fluidScale;
|
||||||
|
public float prevFluidScale;
|
||||||
|
|
||||||
|
public Fluid refFluid = null;
|
||||||
|
|
||||||
public FluidNetwork(ITransmitter<FluidNetwork>... varPipes)
|
public FluidNetwork(ITransmitter<FluidNetwork>... varPipes)
|
||||||
{
|
{
|
||||||
transmitters.addAll(Arrays.asList(varPipes));
|
transmitters.addAll(Arrays.asList(varPipes));
|
||||||
|
@ -74,6 +81,11 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
||||||
|
|
||||||
public synchronized int emit(FluidStack fluidToSend, boolean doTransfer, TileEntity emitter)
|
public synchronized int emit(FluidStack fluidToSend, boolean doTransfer, TileEntity emitter)
|
||||||
{
|
{
|
||||||
|
if(refFluid != null && refFluid != fluidToSend.getFluid())
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
List availableAcceptors = Arrays.asList(getAcceptors(fluidToSend).toArray());
|
List availableAcceptors = Arrays.asList(getAcceptors(fluidToSend).toArray());
|
||||||
|
|
||||||
Collections.shuffle(availableAcceptors);
|
Collections.shuffle(availableAcceptors);
|
||||||
|
@ -108,12 +120,53 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
||||||
{
|
{
|
||||||
FluidStack sendStack = fluidToSend.copy();
|
FluidStack sendStack = fluidToSend.copy();
|
||||||
sendStack.amount = fluidSent;
|
sendStack.amount = fluidSent;
|
||||||
MinecraftForge.EVENT_BUS.post(new FluidTransferEvent(this, sendStack));
|
|
||||||
|
if(sendStack.getFluid() == refFluid)
|
||||||
|
{
|
||||||
|
fluidScale = Math.min(1, fluidScale+((float)sendStack.amount/1000F));
|
||||||
|
}
|
||||||
|
else if(refFluid == null)
|
||||||
|
{
|
||||||
|
refFluid = sendStack.getFluid();
|
||||||
|
fluidScale += Math.min(1, ((float)sendStack.amount/1000F));
|
||||||
|
}
|
||||||
|
|
||||||
|
transferDelay = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fluidSent;
|
return fluidSent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick()
|
||||||
|
{
|
||||||
|
super.tick();
|
||||||
|
|
||||||
|
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||||
|
{
|
||||||
|
if(transferDelay == 0)
|
||||||
|
{
|
||||||
|
if(fluidScale > 0)
|
||||||
|
{
|
||||||
|
fluidScale -= .02;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
refFluid = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
transferDelay--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fluidScale != prevFluidScale)
|
||||||
|
{
|
||||||
|
MinecraftForge.EVENT_BUS.post(new FluidTransferEvent(this, refFluid != null ? refFluid.getID() : -1, fluidScale));
|
||||||
|
}
|
||||||
|
|
||||||
|
prevFluidScale = fluidScale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Set<IFluidHandler> getAcceptors(Object... data)
|
public synchronized Set<IFluidHandler> getAcceptors(Object... data)
|
||||||
{
|
{
|
||||||
|
@ -188,12 +241,14 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
||||||
{
|
{
|
||||||
public final FluidNetwork fluidNetwork;
|
public final FluidNetwork fluidNetwork;
|
||||||
|
|
||||||
public final FluidStack fluidSent;
|
public final int fluidType;
|
||||||
|
public final float fluidScale;
|
||||||
|
|
||||||
public FluidTransferEvent(FluidNetwork network, FluidStack fluid)
|
public FluidTransferEvent(FluidNetwork network, int type, float scale)
|
||||||
{
|
{
|
||||||
fluidNetwork = network;
|
fluidNetwork = network;
|
||||||
fluidSent = fluid;
|
fluidType = type;
|
||||||
|
fluidScale = scale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -18,6 +19,7 @@ import mekanism.api.infuse.InfuseObject;
|
||||||
import mekanism.api.infuse.InfuseRegistry;
|
import mekanism.api.infuse.InfuseRegistry;
|
||||||
import mekanism.api.infuse.InfuseType;
|
import mekanism.api.infuse.InfuseType;
|
||||||
import mekanism.api.infuse.InfusionInput;
|
import mekanism.api.infuse.InfusionInput;
|
||||||
|
import mekanism.api.transmitters.ITransmitter;
|
||||||
import mekanism.api.transmitters.TransmitterNetworkRegistry;
|
import mekanism.api.transmitters.TransmitterNetworkRegistry;
|
||||||
import mekanism.common.EnergyNetwork.EnergyTransferEvent;
|
import mekanism.common.EnergyNetwork.EnergyTransferEvent;
|
||||||
import mekanism.common.FluidNetwork.FluidTransferEvent;
|
import mekanism.common.FluidNetwork.FluidTransferEvent;
|
||||||
|
@ -72,8 +74,8 @@ import mekanism.common.network.PacketRobit;
|
||||||
import mekanism.common.network.PacketSimpleGui;
|
import mekanism.common.network.PacketSimpleGui;
|
||||||
import mekanism.common.network.PacketStatusUpdate;
|
import mekanism.common.network.PacketStatusUpdate;
|
||||||
import mekanism.common.network.PacketTileEntity;
|
import mekanism.common.network.PacketTileEntity;
|
||||||
import mekanism.common.network.PacketTransmitterTransferUpdate;
|
import mekanism.common.network.PacketTransmitterUpdate;
|
||||||
import mekanism.common.network.PacketTransmitterTransferUpdate.TransmitterTransferType;
|
import mekanism.common.network.PacketTransmitterUpdate.PacketType;
|
||||||
import mekanism.common.network.PacketWalkieTalkieState;
|
import mekanism.common.network.PacketWalkieTalkieState;
|
||||||
import mekanism.common.tileentity.TileEntityAdvancedBoundingBlock;
|
import mekanism.common.tileentity.TileEntityAdvancedBoundingBlock;
|
||||||
import mekanism.common.tileentity.TileEntityBoundingBlock;
|
import mekanism.common.tileentity.TileEntityBoundingBlock;
|
||||||
|
@ -97,6 +99,7 @@ import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||||
import rebelkeithy.mods.metallurgy.api.IOreInfo;
|
import rebelkeithy.mods.metallurgy.api.IOreInfo;
|
||||||
import rebelkeithy.mods.metallurgy.api.MetallurgyAPI;
|
import rebelkeithy.mods.metallurgy.api.MetallurgyAPI;
|
||||||
import thermalexpansion.api.crafting.CraftingManagers;
|
import thermalexpansion.api.crafting.CraftingManagers;
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import cpw.mods.fml.common.Mod;
|
import cpw.mods.fml.common.Mod;
|
||||||
import cpw.mods.fml.common.Mod.EventHandler;
|
import cpw.mods.fml.common.Mod.EventHandler;
|
||||||
import cpw.mods.fml.common.Mod.Instance;
|
import cpw.mods.fml.common.Mod.Instance;
|
||||||
|
@ -1120,7 +1123,7 @@ public class Mekanism
|
||||||
|
|
||||||
//Packet registrations
|
//Packet registrations
|
||||||
PacketHandler.registerPacket(PacketRobit.class);
|
PacketHandler.registerPacket(PacketRobit.class);
|
||||||
PacketHandler.registerPacket(PacketTransmitterTransferUpdate.class);
|
PacketHandler.registerPacket(PacketTransmitterUpdate.class);
|
||||||
PacketHandler.registerPacket(PacketElectricChest.class);
|
PacketHandler.registerPacket(PacketElectricChest.class);
|
||||||
PacketHandler.registerPacket(PacketElectricBowState.class);
|
PacketHandler.registerPacket(PacketElectricBowState.class);
|
||||||
PacketHandler.registerPacket(PacketConfiguratorState.class);
|
PacketHandler.registerPacket(PacketConfiguratorState.class);
|
||||||
|
@ -1160,7 +1163,7 @@ public class Mekanism
|
||||||
public void onEnergyTransferred(EnergyTransferEvent event)
|
public void onEnergyTransferred(EnergyTransferEvent event)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterTransferUpdate().setParams(TransmitterTransferType.ENERGY, event.energyNetwork.transmitters.iterator().next(), event.power));
|
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterUpdate().setParams(PacketType.ENERGY, event.energyNetwork.transmitters.iterator().next(), event.power));
|
||||||
} catch(Exception e) {}
|
} catch(Exception e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1168,7 +1171,7 @@ public class Mekanism
|
||||||
public void onGasTransferred(GasTransferEvent event)
|
public void onGasTransferred(GasTransferEvent event)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterTransferUpdate().setParams(TransmitterTransferType.GAS, event.gasNetwork.transmitters.iterator().next(), event.transferType));
|
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterUpdate().setParams(PacketType.GAS, event.gasNetwork.transmitters.iterator().next(), event.transferType));
|
||||||
} catch(Exception e) {}
|
} catch(Exception e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1176,7 +1179,7 @@ public class Mekanism
|
||||||
public void onLiquidTransferred(FluidTransferEvent event)
|
public void onLiquidTransferred(FluidTransferEvent event)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterTransferUpdate().setParams(TransmitterTransferType.FLUID, event.fluidNetwork.transmitters.iterator().next(), event.fluidSent));
|
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterUpdate().setParams(PacketType.FLUID, event.fluidNetwork.transmitters.iterator().next(), event.fluidType, event.fluidScale));
|
||||||
} catch(Exception e) {}
|
} catch(Exception e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1185,10 +1188,10 @@ public class Mekanism
|
||||||
{
|
{
|
||||||
if(event.getChunk() != null)
|
if(event.getChunk() != null)
|
||||||
{
|
{
|
||||||
Map copy = (Map)((HashMap)event.getChunk().chunkTileEntityMap).clone();
|
for(Iterator iter = event.getChunk().chunkTileEntityMap.values().iterator(); iter.hasNext();)
|
||||||
|
|
||||||
for(Object obj : copy.values())
|
|
||||||
{
|
{
|
||||||
|
Object obj = iter.next();
|
||||||
|
|
||||||
if(obj instanceof TileEntity)
|
if(obj instanceof TileEntity)
|
||||||
{
|
{
|
||||||
TileEntity tileEntity = (TileEntity)obj;
|
TileEntity tileEntity = (TileEntity)obj;
|
||||||
|
|
|
@ -187,6 +187,9 @@ public class PacketHandler implements IPacketHandler
|
||||||
Object3D obj = (Object3D)transParams[0];
|
Object3D obj = (Object3D)transParams[0];
|
||||||
PacketDispatcher.sendPacketToAllAround(obj.xCoord, obj.yCoord, obj.zCoord, (Double)transParams[1], obj.dimensionId, packet);
|
PacketDispatcher.sendPacketToAllAround(obj.xCoord, obj.yCoord, obj.zCoord, (Double)transParams[1], obj.dimensionId, packet);
|
||||||
break;
|
break;
|
||||||
|
case CLIENTS_DIM:
|
||||||
|
PacketDispatcher.sendPacketToAllInDimension(packet, (Integer)transParams[0]);
|
||||||
|
break;
|
||||||
case SINGLE_CLIENT:
|
case SINGLE_CLIENT:
|
||||||
((EntityPlayerMP)transParams[0]).playerNetServerHandler.sendPacketToPlayer(packet);
|
((EntityPlayerMP)transParams[0]).playerNetServerHandler.sendPacketToPlayer(packet);
|
||||||
break;
|
break;
|
||||||
|
@ -216,6 +219,9 @@ public class PacketHandler implements IPacketHandler
|
||||||
case CLIENTS_RANGE:
|
case CLIENTS_RANGE:
|
||||||
System.out.println("[Mekanism] Sent '" + packetType.getName() + "' packet to clients in a " + (Double)transParams[1] + " block range.");
|
System.out.println("[Mekanism] Sent '" + packetType.getName() + "' packet to clients in a " + (Double)transParams[1] + " block range.");
|
||||||
break;
|
break;
|
||||||
|
case CLIENTS_DIM:
|
||||||
|
System.out.println("[Mekanism] Sent '" + packetType.getName() + "' packet to clients in dimension ID " + (Integer)transParams[0] + ".");
|
||||||
|
break;
|
||||||
case SINGLE_CLIENT:
|
case SINGLE_CLIENT:
|
||||||
System.out.println("[Mekanism] Sent '" + packetType.getName() + "' packet to " + ((EntityPlayer)transParams[0]).username);
|
System.out.println("[Mekanism] Sent '" + packetType.getName() + "' packet to " + ((EntityPlayer)transParams[0]).username);
|
||||||
break;
|
break;
|
||||||
|
@ -234,6 +240,9 @@ public class PacketHandler implements IPacketHandler
|
||||||
/** 2 parameters - Object3D representing the location of the transmission, and a double of the distance this packet can be sent in. */
|
/** 2 parameters - Object3D representing the location of the transmission, and a double of the distance this packet can be sent in. */
|
||||||
CLIENTS_RANGE(2),
|
CLIENTS_RANGE(2),
|
||||||
|
|
||||||
|
/** 1 parameter - int representing the dimension ID to send this packet to. */
|
||||||
|
CLIENTS_DIM(1),
|
||||||
|
|
||||||
/** 1 parameter - EntityPlayer to send this packet to. */
|
/** 1 parameter - EntityPlayer to send this packet to. */
|
||||||
SINGLE_CLIENT(1);
|
SINGLE_CLIENT(1);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,11 @@ import mekanism.api.gas.ITubeConnection;
|
||||||
import mekanism.api.transmitters.ITransmitter;
|
import mekanism.api.transmitters.ITransmitter;
|
||||||
import mekanism.client.ClientProxy;
|
import mekanism.client.ClientProxy;
|
||||||
import mekanism.common.Mekanism;
|
import mekanism.common.Mekanism;
|
||||||
|
import mekanism.common.PacketHandler;
|
||||||
|
import mekanism.common.PacketHandler.Transmission;
|
||||||
import mekanism.common.PipeUtils;
|
import mekanism.common.PipeUtils;
|
||||||
|
import mekanism.common.network.PacketTransmitterUpdate;
|
||||||
|
import mekanism.common.network.PacketTransmitterUpdate.PacketType;
|
||||||
import mekanism.common.tileentity.TileEntityDiversionTransporter;
|
import mekanism.common.tileentity.TileEntityDiversionTransporter;
|
||||||
import mekanism.common.tileentity.TileEntityLogisticalTransporter;
|
import mekanism.common.tileentity.TileEntityLogisticalTransporter;
|
||||||
import mekanism.common.tileentity.TileEntityMechanicalPipe;
|
import mekanism.common.tileentity.TileEntityMechanicalPipe;
|
||||||
|
@ -311,6 +315,7 @@ public class BlockTransmitter extends Block
|
||||||
if(tileEntity instanceof ITransmitter)
|
if(tileEntity instanceof ITransmitter)
|
||||||
{
|
{
|
||||||
((ITransmitter)tileEntity).refreshTransmitterNetwork();
|
((ITransmitter)tileEntity).refreshTransmitterNetwork();
|
||||||
|
PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketTransmitterUpdate().setParams(PacketType.UPDATE, tileEntity), world.provider.dimensionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,6 +330,7 @@ public class BlockTransmitter extends Block
|
||||||
if(tileEntity instanceof ITransmitter)
|
if(tileEntity instanceof ITransmitter)
|
||||||
{
|
{
|
||||||
((ITransmitter)tileEntity).refreshTransmitterNetwork();
|
((ITransmitter)tileEntity).refreshTransmitterNetwork();
|
||||||
|
PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketTransmitterUpdate().setParams(PacketType.UPDATE, tileEntity), world.provider.dimensionId);
|
||||||
|
|
||||||
if(tileEntity instanceof TileEntityUniversalCable)
|
if(tileEntity instanceof TileEntityUniversalCable)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,19 +3,21 @@ package mekanism.common.network;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
|
|
||||||
import mekanism.api.gas.EnumGas;
|
import mekanism.api.gas.EnumGas;
|
||||||
import mekanism.client.EnergyClientUpdate;
|
import mekanism.api.transmitters.ITransmitter;
|
||||||
import mekanism.client.FluidClientUpdate;
|
|
||||||
import mekanism.client.GasClientUpdate;
|
import mekanism.client.GasClientUpdate;
|
||||||
|
import mekanism.common.tileentity.TileEntityMechanicalPipe;
|
||||||
|
import mekanism.common.tileentity.TileEntityUniversalCable;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
public class PacketTransmitterTransferUpdate implements IMekanismPacket
|
public class PacketTransmitterUpdate implements IMekanismPacket
|
||||||
{
|
{
|
||||||
public TransmitterTransferType activeType;
|
public PacketType packetType;
|
||||||
|
|
||||||
public TileEntity tileEntity;
|
public TileEntity tileEntity;
|
||||||
|
|
||||||
|
@ -23,7 +25,8 @@ public class PacketTransmitterTransferUpdate implements IMekanismPacket
|
||||||
|
|
||||||
public String gasName;
|
public String gasName;
|
||||||
|
|
||||||
public FluidStack fluidStack;
|
public int fluidType;
|
||||||
|
public float fluidScale;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName()
|
public String getName()
|
||||||
|
@ -34,10 +37,10 @@ public class PacketTransmitterTransferUpdate implements IMekanismPacket
|
||||||
@Override
|
@Override
|
||||||
public IMekanismPacket setParams(Object... data)
|
public IMekanismPacket setParams(Object... data)
|
||||||
{
|
{
|
||||||
activeType = (TransmitterTransferType)data[0];
|
packetType = (PacketType)data[0];
|
||||||
tileEntity = (TileEntity)data[1];
|
tileEntity = (TileEntity)data[1];
|
||||||
|
|
||||||
switch(activeType)
|
switch(packetType)
|
||||||
{
|
{
|
||||||
case ENERGY:
|
case ENERGY:
|
||||||
power = (Double)data[2];
|
power = (Double)data[2];
|
||||||
|
@ -46,7 +49,8 @@ public class PacketTransmitterTransferUpdate implements IMekanismPacket
|
||||||
gasName = ((EnumGas)data[2]).name;
|
gasName = ((EnumGas)data[2]).name;
|
||||||
break;
|
break;
|
||||||
case FLUID:
|
case FLUID:
|
||||||
fluidStack = (FluidStack)data[2];
|
fluidType = (Integer)data[2];
|
||||||
|
fluidScale = (Float)data[3];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +67,15 @@ public class PacketTransmitterTransferUpdate implements IMekanismPacket
|
||||||
int z = dataStream.readInt();
|
int z = dataStream.readInt();
|
||||||
|
|
||||||
if(transmitterType == 0)
|
if(transmitterType == 0)
|
||||||
|
{
|
||||||
|
ITransmitter transmitter = (ITransmitter)world.getBlockTileEntity(x, y, z);
|
||||||
|
|
||||||
|
if(transmitter != null)
|
||||||
|
{
|
||||||
|
transmitter.refreshTransmitterNetwork();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(transmitterType == 1)
|
||||||
{
|
{
|
||||||
double powerLevel = dataStream.readDouble();
|
double powerLevel = dataStream.readDouble();
|
||||||
|
|
||||||
|
@ -70,10 +83,10 @@ public class PacketTransmitterTransferUpdate implements IMekanismPacket
|
||||||
|
|
||||||
if(tileEntity != null)
|
if(tileEntity != null)
|
||||||
{
|
{
|
||||||
new EnergyClientUpdate(tileEntity, powerLevel).clientUpdate();
|
((TileEntityUniversalCable)tileEntity).getTransmitterNetwork().clientEnergyScale = powerLevel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(transmitterType == 1)
|
else if(transmitterType == 2)
|
||||||
{
|
{
|
||||||
EnumGas type = EnumGas.getFromName(dataStream.readUTF());
|
EnumGas type = EnumGas.getFromName(dataStream.readUTF());
|
||||||
|
|
||||||
|
@ -84,14 +97,18 @@ public class PacketTransmitterTransferUpdate implements IMekanismPacket
|
||||||
new GasClientUpdate(tileEntity, type).clientUpdate();
|
new GasClientUpdate(tileEntity, type).clientUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(transmitterType == 2)
|
else if(transmitterType == 3)
|
||||||
{
|
{
|
||||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||||
FluidStack fluidStack = new FluidStack(dataStream.readInt(), dataStream.readInt());
|
|
||||||
|
int type = dataStream.readInt();
|
||||||
|
Fluid fluidType = type != -1 ? FluidRegistry.getFluid(type) : null;
|
||||||
|
float fluidScale = dataStream.readFloat();
|
||||||
|
|
||||||
if(tileEntity != null)
|
if(tileEntity != null)
|
||||||
{
|
{
|
||||||
new FluidClientUpdate(tileEntity, fluidStack).clientUpdate();
|
((TileEntityMechanicalPipe)tileEntity).getTransmitterNetwork().refFluid = fluidType;
|
||||||
|
((TileEntityMechanicalPipe)tileEntity).getTransmitterNetwork().fluidScale = fluidScale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,13 +116,13 @@ public class PacketTransmitterTransferUpdate implements IMekanismPacket
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutputStream dataStream) throws Exception
|
public void write(DataOutputStream dataStream) throws Exception
|
||||||
{
|
{
|
||||||
dataStream.writeInt(activeType.ordinal());
|
dataStream.writeInt(packetType.ordinal());
|
||||||
|
|
||||||
dataStream.writeInt(tileEntity.xCoord);
|
dataStream.writeInt(tileEntity.xCoord);
|
||||||
dataStream.writeInt(tileEntity.yCoord);
|
dataStream.writeInt(tileEntity.yCoord);
|
||||||
dataStream.writeInt(tileEntity.zCoord);
|
dataStream.writeInt(tileEntity.zCoord);
|
||||||
|
|
||||||
switch(activeType)
|
switch(packetType)
|
||||||
{
|
{
|
||||||
case ENERGY:
|
case ENERGY:
|
||||||
dataStream.writeDouble(power);
|
dataStream.writeDouble(power);
|
||||||
|
@ -114,14 +131,15 @@ public class PacketTransmitterTransferUpdate implements IMekanismPacket
|
||||||
dataStream.writeUTF(gasName);
|
dataStream.writeUTF(gasName);
|
||||||
break;
|
break;
|
||||||
case FLUID:
|
case FLUID:
|
||||||
dataStream.writeInt(fluidStack.fluidID);
|
dataStream.writeInt(fluidType);
|
||||||
dataStream.writeInt(fluidStack.amount);
|
dataStream.writeFloat(fluidScale);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum TransmitterTransferType
|
public static enum PacketType
|
||||||
{
|
{
|
||||||
|
UPDATE,
|
||||||
ENERGY,
|
ENERGY,
|
||||||
GAS,
|
GAS,
|
||||||
FLUID
|
FLUID
|
|
@ -7,6 +7,7 @@ import java.util.HashSet;
|
||||||
import mekanism.api.Object3D;
|
import mekanism.api.Object3D;
|
||||||
import mekanism.api.transmitters.ITransmitter;
|
import mekanism.api.transmitters.ITransmitter;
|
||||||
import mekanism.api.transmitters.TransmissionType;
|
import mekanism.api.transmitters.TransmissionType;
|
||||||
|
import mekanism.api.transmitters.TransmitterNetworkRegistry;
|
||||||
import mekanism.common.FluidNetwork;
|
import mekanism.common.FluidNetwork;
|
||||||
import mekanism.common.ITileNetwork;
|
import mekanism.common.ITileNetwork;
|
||||||
import mekanism.common.PacketHandler;
|
import mekanism.common.PacketHandler;
|
||||||
|
@ -34,32 +35,9 @@ public class TileEntityMechanicalPipe extends TileEntityTransmitter<FluidNetwork
|
||||||
/** The fake tank used for fluid transfer calculations. */
|
/** The fake tank used for fluid transfer calculations. */
|
||||||
public FluidTank dummyTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
|
public FluidTank dummyTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
|
||||||
|
|
||||||
/** The FluidStack displayed on this pipe. */
|
|
||||||
public FluidStack refFluid = null;
|
|
||||||
|
|
||||||
/** This pipe's active state. */
|
/** This pipe's active state. */
|
||||||
public boolean isActive = false;
|
public boolean isActive = false;
|
||||||
|
|
||||||
public int transferDelay = 0;
|
|
||||||
|
|
||||||
/** The scale (0F -> 1F) of this pipe's fluid level. */
|
|
||||||
public float fluidScale;
|
|
||||||
|
|
||||||
public void onTransfer(FluidStack fluidStack)
|
|
||||||
{
|
|
||||||
if(fluidStack.isFluidEqual(refFluid))
|
|
||||||
{
|
|
||||||
fluidScale = Math.min(1, fluidScale+((float)fluidStack.amount/1000F));
|
|
||||||
}
|
|
||||||
else if(refFluid == null)
|
|
||||||
{
|
|
||||||
refFluid = fluidStack.copy();
|
|
||||||
fluidScale += Math.min(1, ((float)fluidStack.amount/1000F));
|
|
||||||
}
|
|
||||||
|
|
||||||
transferDelay = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TransmissionType getTransmissionType()
|
public TransmissionType getTransmissionType()
|
||||||
{
|
{
|
||||||
|
@ -82,7 +60,7 @@ public class TileEntityMechanicalPipe extends TileEntityTransmitter<FluidNetwork
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(connectedNets.size() == 0 || worldObj.isRemote)
|
if(connectedNets.size() == 0)
|
||||||
{
|
{
|
||||||
theNetwork = new FluidNetwork(this);
|
theNetwork = new FluidNetwork(this);
|
||||||
}
|
}
|
||||||
|
@ -106,12 +84,22 @@ public class TileEntityMechanicalPipe extends TileEntityTransmitter<FluidNetwork
|
||||||
getTransmitterNetwork().fixMessedUpNetwork(this);
|
getTransmitterNetwork().fixMessedUpNetwork(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChunkUnload()
|
||||||
|
{
|
||||||
|
super.onChunkUnload();
|
||||||
|
|
||||||
|
getTransmitterNetwork().split(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidate()
|
public void invalidate()
|
||||||
{
|
{
|
||||||
|
getTransmitterNetwork().split(this);
|
||||||
|
|
||||||
if(!worldObj.isRemote)
|
if(!worldObj.isRemote)
|
||||||
{
|
{
|
||||||
getTransmitterNetwork().split(this);
|
TransmitterNetworkRegistry.getInstance().pruneEmptyNetworks();
|
||||||
}
|
}
|
||||||
|
|
||||||
super.invalidate();
|
super.invalidate();
|
||||||
|
@ -129,42 +117,24 @@ public class TileEntityMechanicalPipe extends TileEntityTransmitter<FluidNetwork
|
||||||
@Override
|
@Override
|
||||||
public void refreshTransmitterNetwork()
|
public void refreshTransmitterNetwork()
|
||||||
{
|
{
|
||||||
if(!worldObj.isRemote)
|
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
TileEntity tileEntity = Object3D.get(this).getFromSide(side).getTileEntity(worldObj);
|
||||||
{
|
|
||||||
TileEntity tileEntity = Object3D.get(this).getFromSide(side).getTileEntity(worldObj);
|
|
||||||
|
|
||||||
if(TransmissionType.checkTransmissionType(tileEntity, getTransmissionType()))
|
|
||||||
{
|
|
||||||
getTransmitterNetwork().merge(((ITransmitter<FluidNetwork>)tileEntity).getTransmitterNetwork());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getTransmitterNetwork().refresh();
|
if(TransmissionType.checkTransmissionType(tileEntity, getTransmissionType()))
|
||||||
|
{
|
||||||
|
getTransmitterNetwork().merge(((ITransmitter<FluidNetwork>)tileEntity).getTransmitterNetwork());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTransmitterNetwork().refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity()
|
public void updateEntity()
|
||||||
{
|
{
|
||||||
if(worldObj.isRemote)
|
if(!worldObj.isRemote)
|
||||||
{
|
{
|
||||||
if(transferDelay == 0)
|
|
||||||
{
|
|
||||||
if(fluidScale > 0)
|
|
||||||
{
|
|
||||||
fluidScale -= .01;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
refFluid = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
transferDelay--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(isActive)
|
if(isActive)
|
||||||
{
|
{
|
||||||
IFluidHandler[] connectedAcceptors = PipeUtils.getConnectedAcceptors(this);
|
IFluidHandler[] connectedAcceptors = PipeUtils.getConnectedAcceptors(this);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import mekanism.api.gas.IGasTransmitter;
|
||||||
import mekanism.api.gas.ITubeConnection;
|
import mekanism.api.gas.ITubeConnection;
|
||||||
import mekanism.api.transmitters.ITransmitter;
|
import mekanism.api.transmitters.ITransmitter;
|
||||||
import mekanism.api.transmitters.TransmissionType;
|
import mekanism.api.transmitters.TransmissionType;
|
||||||
|
import mekanism.api.transmitters.TransmitterNetworkRegistry;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ public class TileEntityPressurizedTube extends TileEntityTransmitter<GasNetwork>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(connectedNets.size() == 0 || worldObj.isRemote)
|
if(connectedNets.size() == 0)
|
||||||
{
|
{
|
||||||
theNetwork = new GasNetwork(this);
|
theNetwork = new GasNetwork(this);
|
||||||
}
|
}
|
||||||
|
@ -67,12 +68,22 @@ public class TileEntityPressurizedTube extends TileEntityTransmitter<GasNetwork>
|
||||||
getTransmitterNetwork().fixMessedUpNetwork(this);
|
getTransmitterNetwork().fixMessedUpNetwork(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChunkUnload()
|
||||||
|
{
|
||||||
|
super.onChunkUnload();
|
||||||
|
|
||||||
|
getTransmitterNetwork().split(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidate()
|
public void invalidate()
|
||||||
{
|
{
|
||||||
|
getTransmitterNetwork().split(this);
|
||||||
|
|
||||||
if(!worldObj.isRemote)
|
if(!worldObj.isRemote)
|
||||||
{
|
{
|
||||||
getTransmitterNetwork().split(this);
|
TransmitterNetworkRegistry.getInstance().pruneEmptyNetworks();
|
||||||
}
|
}
|
||||||
|
|
||||||
super.invalidate();
|
super.invalidate();
|
||||||
|
@ -90,20 +101,17 @@ public class TileEntityPressurizedTube extends TileEntityTransmitter<GasNetwork>
|
||||||
@Override
|
@Override
|
||||||
public void refreshTransmitterNetwork()
|
public void refreshTransmitterNetwork()
|
||||||
{
|
{
|
||||||
if(!worldObj.isRemote)
|
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
TileEntity tileEntity = Object3D.get(this).getFromSide(side).getTileEntity(worldObj);
|
||||||
{
|
|
||||||
TileEntity tileEntity = Object3D.get(this).getFromSide(side).getTileEntity(worldObj);
|
|
||||||
|
|
||||||
if(TransmissionType.checkTransmissionType(tileEntity, TransmissionType.GAS, this))
|
|
||||||
{
|
|
||||||
getTransmitterNetwork().merge(((ITransmitter<GasNetwork>)tileEntity).getTransmitterNetwork());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getTransmitterNetwork().refresh();
|
if(TransmissionType.checkTransmissionType(tileEntity, TransmissionType.GAS, this))
|
||||||
|
{
|
||||||
|
getTransmitterNetwork().merge(((ITransmitter<GasNetwork>)tileEntity).getTransmitterNetwork());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTransmitterNetwork().refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTransfer(EnumGas type)
|
public void onTransfer(EnumGas type)
|
||||||
|
@ -125,12 +133,6 @@ public class TileEntityPressurizedTube extends TileEntityTransmitter<GasNetwork>
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUpdate()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTransmitterNetworkSize()
|
public int getTransmitterNetworkSize()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
package mekanism.common.tileentity;
|
package mekanism.common.tileentity;
|
||||||
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
|
||||||
import mekanism.api.Object3D;
|
|
||||||
import mekanism.api.transmitters.ITransmitter;
|
import mekanism.api.transmitters.ITransmitter;
|
||||||
import mekanism.api.transmitters.TransmitterNetworkRegistry;
|
import mekanism.api.transmitters.TransmitterNetworkRegistry;
|
||||||
import mekanism.common.PacketHandler;
|
|
||||||
import mekanism.common.PacketHandler.Transmission;
|
|
||||||
import mekanism.common.network.PacketDataRequest;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
public abstract class TileEntityTransmitter<N> extends TileEntity implements ITransmitter<N>
|
public abstract class TileEntityTransmitter<N> extends TileEntity implements ITransmitter<N>
|
||||||
{
|
{
|
||||||
public N theNetwork;
|
public N theNetwork;
|
||||||
|
|
||||||
|
public int delayTicks = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public AxisAlignedBB getRenderBoundingBox()
|
public AxisAlignedBB getRenderBoundingBox()
|
||||||
|
@ -22,11 +21,40 @@ public abstract class TileEntityTransmitter<N> extends TileEntity implements ITr
|
||||||
return INFINITE_EXTENT_AABB;
|
return INFINITE_EXTENT_AABB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUpdate()
|
||||||
|
{
|
||||||
|
return FMLCommonHandler.instance().getEffectiveSide().isClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateEntity()
|
||||||
|
{
|
||||||
|
super.updateEntity();
|
||||||
|
|
||||||
|
if(worldObj.isRemote)
|
||||||
|
{
|
||||||
|
if(delayTicks == 3)
|
||||||
|
{
|
||||||
|
delayTicks++;
|
||||||
|
refreshTransmitterNetwork();
|
||||||
|
}
|
||||||
|
else if(delayTicks < 3)
|
||||||
|
{
|
||||||
|
delayTicks++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChunkUnload()
|
public void onChunkUnload()
|
||||||
{
|
{
|
||||||
invalidate();
|
super.onChunkUnload();
|
||||||
TransmitterNetworkRegistry.getInstance().pruneEmptyNetworks();
|
|
||||||
|
if(!worldObj.isRemote)
|
||||||
|
{
|
||||||
|
TransmitterNetworkRegistry.getInstance().pruneEmptyNetworks();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.Set;
|
||||||
import mekanism.api.Object3D;
|
import mekanism.api.Object3D;
|
||||||
import mekanism.api.transmitters.ITransmitter;
|
import mekanism.api.transmitters.ITransmitter;
|
||||||
import mekanism.api.transmitters.TransmissionType;
|
import mekanism.api.transmitters.TransmissionType;
|
||||||
|
import mekanism.api.transmitters.TransmitterNetworkRegistry;
|
||||||
import mekanism.common.EnergyNetwork;
|
import mekanism.common.EnergyNetwork;
|
||||||
import mekanism.common.ITileNetwork;
|
import mekanism.common.ITileNetwork;
|
||||||
import mekanism.common.Mekanism;
|
import mekanism.common.Mekanism;
|
||||||
|
@ -59,12 +60,6 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
|
||||||
return TransmissionType.ENERGY;
|
return TransmissionType.ENERGY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUpdate()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnergyNetwork getTransmitterNetwork(boolean createIfNull)
|
public EnergyNetwork getTransmitterNetwork(boolean createIfNull)
|
||||||
{
|
{
|
||||||
|
@ -81,7 +76,7 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(connectedNets.size() == 0 || worldObj.isRemote)
|
if(connectedNets.size() == 0)
|
||||||
{
|
{
|
||||||
theNetwork = new EnergyNetwork(this);
|
theNetwork = new EnergyNetwork(this);
|
||||||
}
|
}
|
||||||
|
@ -108,17 +103,30 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
|
||||||
@Override
|
@Override
|
||||||
public void invalidate()
|
public void invalidate()
|
||||||
{
|
{
|
||||||
|
getTransmitterNetwork().split(this);
|
||||||
|
|
||||||
if(!worldObj.isRemote)
|
if(!worldObj.isRemote)
|
||||||
{
|
{
|
||||||
getTransmitterNetwork().split(this);
|
TransmitterNetworkRegistry.getInstance().pruneEmptyNetworks();
|
||||||
|
|
||||||
Mekanism.ic2Registered.remove(Object3D.get(this));
|
|
||||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.invalidate();
|
super.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChunkUnload()
|
||||||
|
{
|
||||||
|
super.onChunkUnload();
|
||||||
|
|
||||||
|
getTransmitterNetwork().split(this);
|
||||||
|
|
||||||
|
if(!worldObj.isRemote)
|
||||||
|
{
|
||||||
|
Mekanism.ic2Registered.remove(Object3D.get(this));
|
||||||
|
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeFromTransmitterNetwork()
|
public void removeFromTransmitterNetwork()
|
||||||
{
|
{
|
||||||
|
@ -131,21 +139,18 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
|
||||||
@Override
|
@Override
|
||||||
public void refreshTransmitterNetwork()
|
public void refreshTransmitterNetwork()
|
||||||
{
|
{
|
||||||
if(!worldObj.isRemote)
|
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
TileEntity tileEntity = Object3D.get(this).getFromSide(side).getTileEntity(worldObj);
|
||||||
{
|
|
||||||
TileEntity tileEntity = Object3D.get(this).getFromSide(side).getTileEntity(worldObj);
|
|
||||||
|
|
||||||
if(TransmissionType.checkTransmissionType(tileEntity, TransmissionType.ENERGY))
|
|
||||||
{
|
|
||||||
getTransmitterNetwork().merge(((ITransmitter<EnergyNetwork>)tileEntity).getTransmitterNetwork());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getTransmitterNetwork().refresh();
|
if(TransmissionType.checkTransmissionType(tileEntity, TransmissionType.ENERGY))
|
||||||
reconfigure();
|
{
|
||||||
|
getTransmitterNetwork().merge(((ITransmitter<EnergyNetwork>)tileEntity).getTransmitterNetwork());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTransmitterNetwork().refresh();
|
||||||
|
reconfigure();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue