Transmitters now intelligently maintain buffers when transmitter nodes are destroyed

This commit is contained in:
aidancbrady 2015-11-26 15:41:22 -07:00
parent b248cf4b07
commit 2b785c95f3
10 changed files with 133 additions and 90 deletions

View file

@ -1,18 +1,10 @@
package mekanism.api.transmitters;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map.Entry;
import java.util.Set;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.Event;
import mekanism.api.Coord4D;
import mekanism.api.IClientTicker;
import mekanism.api.Range4D;
@ -21,8 +13,9 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.Event;
import java.util.*;
import java.util.Map.Entry;
public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implements IClientTicker, INetworkDataHandler
{
@ -146,6 +139,28 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
public void invalidate()
{
//Remove invalid transmitters first for share calculations
for(Iterator<IGridTransmitter<A, N>> iter = transmitters.iterator(); iter.hasNext();)
{
IGridTransmitter<A, N> transmitter = iter.next();
if(!transmitter.isValid())
{
iter.remove();
continue;
}
}
//Clamp the new buffer
clampBuffer();
//Update all shares
for(IGridTransmitter<A, N> transmitter : transmitters)
{
transmitter.updateShare();
}
//Now invalidate the transmitters
for(IGridTransmitter<A, N> transmitter : transmitters)
{
invalidateTransmitter(transmitter);

View file

@ -1,12 +1,11 @@
package mekanism.api.transmitters;
import java.util.Collection;
import mekanism.api.Coord4D;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.Collection;
public interface IGridTransmitter<A, N extends DynamicNetwork<A, N>> extends ITransmitter
{
public boolean hasTransmitterNetwork();
@ -59,5 +58,7 @@ public interface IGridTransmitter<A, N extends DynamicNetwork<A, N>> extends ITr
public void takeShare();
public void updateShare();
public Object getBuffer();
}

View file

@ -76,6 +76,7 @@ public class EnergyNetwork extends DynamicNetwork<EnergyAcceptorWrapper, EnergyN
{
buffer.amount = getCapacity();
}
if(buffer.amount < 0)
{
buffer.amount = 0;

View file

@ -1,18 +1,17 @@
package mekanism.common.multipart;
import java.util.Collection;
import mekanism.api.Coord4D;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.api.transmitters.TransmissionType;
import mekanism.common.transmitters.Transmitter;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.Collection;
public class MultipartTransmitter<A, N extends DynamicNetwork<A,N>> extends Transmitter<A, N>
{
public PartTransmitter<A, N> containingPart;
@ -107,6 +106,12 @@ public class MultipartTransmitter<A, N extends DynamicNetwork<A,N>> extends Tran
containingPart.takeShare();
}
@Override
public void updateShare()
{
containingPart.updateShare();
}
@Override
public Object getBuffer()
{

View file

@ -1,28 +1,23 @@
package mekanism.common.multipart;
import java.util.Collection;
import mekanism.api.Coord4D;
import mekanism.api.IHeatTransfer;
import mekanism.api.transmitters.TransmissionType;
import mekanism.client.render.RenderPartTransmitter;
import mekanism.common.HeatNetwork;
import mekanism.common.util.HeatUtils;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import codechicken.lib.colour.ColourRGBA;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.lib.vec.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mekanism.api.IHeatTransfer;
import mekanism.api.transmitters.TransmissionType;
import mekanism.client.render.RenderPartTransmitter;
import mekanism.common.HeatNetwork;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.Collection;
public class PartHeatTransmitter extends PartTransmitter<IHeatTransfer, HeatNetwork>
{
@ -60,6 +55,9 @@ public class PartHeatTransmitter extends PartTransmitter<IHeatTransfer, HeatNetw
@Override
public void takeShare() {}
@Override
public void updateShare() {}
public static void registerIcons(IIconRegister register)
{
heatIcons.registerCenterIcons(register, new String[] {"HeatTransmitter"});

View file

@ -1,12 +1,12 @@
package mekanism.common.multipart;
import java.util.ArrayList;
import java.util.Collection;
import codechicken.lib.vec.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.Range4D;
import mekanism.common.base.ITransporterTile;
import mekanism.api.transmitters.TransmissionType;
import mekanism.client.render.RenderPartTransmitter;
import mekanism.common.InventoryNetwork;
@ -14,6 +14,7 @@ import mekanism.common.Mekanism;
import mekanism.common.Tier;
import mekanism.common.Tier.TransporterTier;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.base.ITransporterTile;
import mekanism.common.content.transporter.InvStack;
import mekanism.common.content.transporter.PathfinderCache;
import mekanism.common.content.transporter.TransporterManager;
@ -34,10 +35,9 @@ import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import codechicken.lib.vec.Vector3;
import java.util.ArrayList;
import java.util.Collection;
public class PartLogisticalTransporter extends PartTransmitter<IInventory, InventoryNetwork> implements ITransporterTile
{
@ -435,6 +435,9 @@ public class PartLogisticalTransporter extends PartTransmitter<IInventory, Inven
@Override
public void takeShare() {}
@Override
public void updateShare() {}
@Override
public MultipartTransporter getTransmitter()
{

View file

@ -42,17 +42,8 @@ public class PartMechanicalPipe extends PartTransmitter<IFluidHandler, FluidNetw
{
if(!world().isRemote)
{
if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetworkSize() > 0)
{
FluidStack last = getSaveShare();
if((last != null && !(lastWrite != null && lastWrite.amount == last.amount && lastWrite.getFluid() == last.getFluid())) || (last == null && lastWrite != null))
{
lastWrite = last;
MekanismUtils.saveChunk(tile());
}
}
updateShare();
IFluidHandler[] connectedAcceptors = PipeUtils.getConnectedAcceptors(tile());
for(ForgeDirection side : getConnections(ConnectionType.PULL))
@ -77,6 +68,21 @@ public class PartMechanicalPipe extends PartTransmitter<IFluidHandler, FluidNetw
super.update();
}
@Override
public void updateShare()
{
if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetworkSize() > 0)
{
FluidStack last = getSaveShare();
if((last != null && !(lastWrite != null && lastWrite.amount == last.amount && lastWrite.getFluid() == last.getFluid())) || (last == null && lastWrite != null))
{
lastWrite = last;
MekanismUtils.saveChunk(tile());
}
}
}
private FluidStack getSaveShare()
{
if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetwork().buffer != null)

View file

@ -39,17 +39,8 @@ public class PartPressurizedTube extends PartTransmitter<IGasHandler, GasNetwork
public void update()
{
if(!world().isRemote)
{
if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetworkSize() > 0)
{
GasStack last = getSaveShare();
if((last != null && !(lastWrite != null && lastWrite.amount == last.amount && lastWrite.getGas() == last.getGas())) || (last == null && lastWrite != null))
{
lastWrite = last;
MekanismUtils.saveChunk(tile());
}
}
{
updateShare();
IGasHandler[] connectedAcceptors = GasTransmission.getConnectedAcceptors(tile());
@ -84,6 +75,21 @@ public class PartPressurizedTube extends PartTransmitter<IGasHandler, GasNetwork
super.update();
}
@Override
public void updateShare()
{
if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetworkSize() > 0)
{
GasStack last = getSaveShare();
if((last != null && !(lastWrite != null && lastWrite.amount == last.amount && lastWrite.getGas() == last.getGas())) || (last == null && lastWrite != null))
{
lastWrite = last;
MekanismUtils.saveChunk(tile());
}
}
}
private GasStack getSaveShare()
{
if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetwork().buffer != null)

View file

@ -122,4 +122,6 @@ public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends
public abstract Object getBuffer();
public abstract void takeShare();
public abstract void updateShare();
}

View file

@ -1,11 +1,16 @@
package mekanism.common.multipart;
import java.util.Collection;
import java.util.List;
import codechicken.lib.vec.Vector3;
import cofh.api.energy.IEnergyHandler;
import cofh.api.energy.IEnergyProvider;
import cpw.mods.fml.common.Optional.Interface;
import cpw.mods.fml.common.Optional.InterfaceList;
import cpw.mods.fml.common.Optional.Method;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ic2.api.energy.tile.IEnergySource;
import mekanism.api.MekanismConfig.client;
import mekanism.api.MekanismConfig.general;
import mekanism.common.base.EnergyAcceptorWrapper;
import mekanism.api.energy.EnergyStack;
import mekanism.api.energy.ICableOutputter;
import mekanism.api.energy.IStrictEnergyAcceptor;
@ -14,6 +19,7 @@ import mekanism.api.transmitters.TransmissionType;
import mekanism.client.render.RenderPartTransmitter;
import mekanism.common.EnergyNetwork;
import mekanism.common.Tier;
import mekanism.common.base.EnergyAcceptorWrapper;
import mekanism.common.util.CableUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.client.renderer.texture.IIconRegister;
@ -21,15 +27,9 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.Optional.Interface;
import cpw.mods.fml.common.Optional.InterfaceList;
import cpw.mods.fml.common.Optional.Method;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import codechicken.lib.vec.Vector3;
import cofh.api.energy.IEnergyHandler;
import cofh.api.energy.IEnergyProvider;
import ic2.api.energy.tile.IEnergySource;
import java.util.Collection;
import java.util.List;
@InterfaceList({
@Interface(iface = "cofh.api.energy.IEnergyHandler", modid = "CoFHCore"),
@ -64,16 +64,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyAcceptorWrapper, E
}
}
else {
if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetworkSize() > 0)
{
double last = getSaveShare();
if(last != lastWrite)
{
lastWrite = last;
MekanismUtils.saveChunk(tile());
}
}
updateShare();
List<ForgeDirection> sides = getConnections(ConnectionType.PULL);
@ -135,6 +126,21 @@ public class PartUniversalCable extends PartTransmitter<EnergyAcceptorWrapper, E
super.update();
}
@Override
public void updateShare()
{
if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetworkSize() > 0)
{
double last = getSaveShare();
if(last != lastWrite)
{
lastWrite = last;
MekanismUtils.saveChunk(tile());
}
}
}
private double getSaveShare()
{
if(getTransmitter().hasTransmitterNetwork())