Merge pull request #264 from DarkGuardsman/master
could be a fix to concur modification error
This commit is contained in:
commit
53b659ca12
1 changed files with 37 additions and 34 deletions
|
@ -2,6 +2,7 @@ package mekanism.api.transmitters;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
@ -18,34 +19,34 @@ public class TransmitterNetworkRegistry implements ITickHandler
|
||||||
{
|
{
|
||||||
private static TransmitterNetworkRegistry INSTANCE = new TransmitterNetworkRegistry();
|
private static TransmitterNetworkRegistry INSTANCE = new TransmitterNetworkRegistry();
|
||||||
private static boolean loaderRegistered = false;
|
private static boolean loaderRegistered = false;
|
||||||
|
|
||||||
private HashSet<ITransmitterNetwork> networks = new HashSet<ITransmitterNetwork>();
|
private HashSet<ITransmitterNetwork> networks = new HashSet<ITransmitterNetwork>();
|
||||||
|
|
||||||
public TransmitterNetworkRegistry()
|
public TransmitterNetworkRegistry()
|
||||||
{
|
{
|
||||||
TickRegistry.registerTickHandler(this, Side.SERVER);
|
TickRegistry.registerTickHandler(this, Side.SERVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initiate()
|
public static void initiate()
|
||||||
{
|
{
|
||||||
if(!loaderRegistered)
|
if(!loaderRegistered)
|
||||||
{
|
{
|
||||||
loaderRegistered = true;
|
loaderRegistered = true;
|
||||||
|
|
||||||
MinecraftForge.EVENT_BUS.register(new NetworkLoader());
|
MinecraftForge.EVENT_BUS.register(new NetworkLoader());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TransmitterNetworkRegistry getInstance()
|
public static TransmitterNetworkRegistry getInstance()
|
||||||
{
|
{
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerNetwork(ITransmitterNetwork network)
|
public void registerNetwork(ITransmitterNetwork network)
|
||||||
{
|
{
|
||||||
networks.add(network);
|
networks.add(network);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeNetwork(ITransmitterNetwork network)
|
public void removeNetwork(ITransmitterNetwork network)
|
||||||
{
|
{
|
||||||
if(networks.contains(network))
|
if(networks.contains(network))
|
||||||
|
@ -53,7 +54,7 @@ public class TransmitterNetworkRegistry implements ITickHandler
|
||||||
networks.remove(network);
|
networks.remove(network);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pruneEmptyNetworks()
|
public void pruneEmptyNetworks()
|
||||||
{
|
{
|
||||||
HashSet<ITransmitterNetwork> copySet = new HashSet<ITransmitterNetwork>(networks);
|
HashSet<ITransmitterNetwork> copySet = new HashSet<ITransmitterNetwork>(networks);
|
||||||
|
@ -66,18 +67,18 @@ public class TransmitterNetworkRegistry implements ITickHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tickStart(EnumSet<TickType> type, Object... tickData)
|
public void tickStart(EnumSet<TickType> type, Object... tickData)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tickEnd(EnumSet<TickType> type, Object... tickData)
|
public void tickEnd(EnumSet<TickType> type, Object... tickData)
|
||||||
{
|
{
|
||||||
Set<ITransmitterNetwork> iterNetworks = (Set<ITransmitterNetwork>)networks.clone();
|
Set<ITransmitterNetwork> iterNetworks = (Set<ITransmitterNetwork>)networks.clone();
|
||||||
|
|
||||||
for(ITransmitterNetwork net : iterNetworks)
|
for(ITransmitterNetwork net : iterNetworks)
|
||||||
{
|
{
|
||||||
if(networks.contains(net))
|
if(networks.contains(net))
|
||||||
|
@ -98,13 +99,13 @@ public class TransmitterNetworkRegistry implements ITickHandler
|
||||||
{
|
{
|
||||||
return "MekanismNetworks";
|
return "MekanismNetworks";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "Network Registry:\n" + networks;
|
return "Network Registry:\n" + networks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NetworkLoader
|
public static class NetworkLoader
|
||||||
{
|
{
|
||||||
@ForgeSubscribe
|
@ForgeSubscribe
|
||||||
|
@ -114,41 +115,43 @@ public class TransmitterNetworkRegistry implements ITickHandler
|
||||||
{
|
{
|
||||||
int x = event.getChunk().xPosition;
|
int x = event.getChunk().xPosition;
|
||||||
int z = event.getChunk().zPosition;
|
int z = event.getChunk().zPosition;
|
||||||
|
|
||||||
IChunkProvider cProvider = event.getChunk().worldObj.getChunkProvider();
|
IChunkProvider cProvider = event.getChunk().worldObj.getChunkProvider();
|
||||||
Chunk[] neighbors = new Chunk[5];
|
Chunk[] neighbors = new Chunk[5];
|
||||||
|
|
||||||
neighbors[0] = event.getChunk();
|
neighbors[0] = event.getChunk();
|
||||||
|
|
||||||
if(cProvider.chunkExists(x + 1, z)) neighbors[1] = cProvider.provideChunk(x + 1, z);
|
if(cProvider.chunkExists(x + 1, z)) neighbors[1] = cProvider.provideChunk(x + 1, z);
|
||||||
if(cProvider.chunkExists(x - 1, z)) neighbors[2] = cProvider.provideChunk(x - 1, z);
|
if(cProvider.chunkExists(x - 1, z)) neighbors[2] = cProvider.provideChunk(x - 1, z);
|
||||||
if(cProvider.chunkExists(x, z + 1)) neighbors[3] = cProvider.provideChunk(x, z + 1);
|
if(cProvider.chunkExists(x, z + 1)) neighbors[3] = cProvider.provideChunk(x, z + 1);
|
||||||
if(cProvider.chunkExists(x, z - 1)) neighbors[4] = cProvider.provideChunk(x, z - 1);
|
if(cProvider.chunkExists(x, z - 1)) neighbors[4] = cProvider.provideChunk(x, z - 1);
|
||||||
|
|
||||||
for(Chunk c : neighbors)
|
for(Chunk c : neighbors)
|
||||||
{
|
{
|
||||||
refreshChunk(c);
|
refreshChunk(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshChunk(Chunk c)
|
public void refreshChunk(Chunk c)
|
||||||
{
|
{
|
||||||
if(c != null)
|
if(c != null)
|
||||||
{
|
{
|
||||||
for(Object obj : c.chunkTileEntityMap.values())
|
Iterator it = c.chunkTileEntityMap.entrySet().iterator();
|
||||||
{
|
while(it.hasNext())
|
||||||
if(obj instanceof TileEntity)
|
{
|
||||||
{
|
Object obj = it.next();
|
||||||
TileEntity tileEntity = (TileEntity)obj;
|
if(obj instanceof TileEntity)
|
||||||
|
{
|
||||||
if(tileEntity instanceof ITransmitter)
|
TileEntity tileEntity = (TileEntity)obj;
|
||||||
{
|
|
||||||
((ITransmitter)tileEntity).refreshTransmitterNetwork();
|
if(tileEntity instanceof ITransmitter)
|
||||||
}
|
{
|
||||||
}
|
((ITransmitter)tileEntity).refreshTransmitterNetwork();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue