mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 00:38:35 +01:00
How did I not think of this?
This commit is contained in:
parent
c154ccbbbf
commit
e17a48d7f0
7 changed files with 33 additions and 29 deletions
|
@ -46,8 +46,17 @@ public class WorldData{
|
||||||
this.dimension = dimension;
|
this.dimension = dimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WorldData getDataForWorld(int world){
|
public static WorldData getDataForWorld(World world){
|
||||||
return worldData.get(world);
|
int dim = world.provider.getDimension();
|
||||||
|
WorldData data = worldData.get(dim);
|
||||||
|
|
||||||
|
if(data == null && world.isRemote){
|
||||||
|
data = new WorldData(null, dim);
|
||||||
|
worldData.put(dim, data);
|
||||||
|
ModUtil.LOGGER.info("Creating temporary WorldData for world "+dim+" on the client!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readFromNBT(NBTTagCompound compound){
|
private void readFromNBT(NBTTagCompound compound){
|
||||||
|
@ -142,7 +151,7 @@ public class WorldData{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
ModUtil.LOGGER.error("Tried to save WorldData without any data being present!?");
|
ModUtil.LOGGER.error("Tried to save WorldData for "+world.provider.getDimension()+" without any data being present!?");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,9 +159,9 @@ public class WorldData{
|
||||||
public static void unload(World world){
|
public static void unload(World world){
|
||||||
if(!world.isRemote){
|
if(!world.isRemote){
|
||||||
save(world);
|
save(world);
|
||||||
int dim = world.provider.getDimension();
|
|
||||||
worldData.remove(dim);
|
worldData.remove(world.provider.getDimension());
|
||||||
ModUtil.LOGGER.info("Unloading WorldData for world "+dim+"!");
|
ModUtil.LOGGER.info("Unloading WorldData for world "+world.provider.getDimension()+"!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,24 +19,18 @@ public class WorldLoadingEvents{
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onLoad(WorldEvent.Load event){
|
public void onLoad(WorldEvent.Load event){
|
||||||
if(!event.getWorld().isRemote){
|
WorldData.load(event.getWorld());
|
||||||
WorldData.load(event.getWorld());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onUnload(WorldEvent.Unload event){
|
public void onUnload(WorldEvent.Unload event){
|
||||||
if(!event.getWorld().isRemote){
|
WorldData.unload(event.getWorld());
|
||||||
WorldData.unload(event.getWorld());
|
FakePlayerUtil.unloadFakePlayer();
|
||||||
FakePlayerUtil.unloadFakePlayer();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onSave(WorldEvent.Save event){
|
public void onSave(WorldEvent.Save event){
|
||||||
if(!event.getWorld().isRemote){
|
WorldData.save(event.getWorld());
|
||||||
WorldData.save(event.getWorld());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class ItemLaserWrench extends ItemBase{
|
||||||
BlockPos savedPos = ItemPhantomConnector.getStoredPosition(stack);
|
BlockPos savedPos = ItemPhantomConnector.getStoredPosition(stack);
|
||||||
if(savedPos != null){
|
if(savedPos != null){
|
||||||
TileEntity savedTile = world.getTileEntity(savedPos);
|
TileEntity savedTile = world.getTileEntity(savedPos);
|
||||||
if(ItemPhantomConnector.getStoredWorld(stack) == world && savedTile instanceof TileEntityLaserRelay && ((TileEntityLaserRelay)savedTile).isItem == ((TileEntityLaserRelay)tile).isItem && LaserRelayConnectionHandler.addConnection(savedPos, pos, world.provider.getDimension())){
|
if(ItemPhantomConnector.getStoredWorld(stack) == world && savedTile instanceof TileEntityLaserRelay && ((TileEntityLaserRelay)savedTile).isItem == ((TileEntityLaserRelay)tile).isItem && LaserRelayConnectionHandler.addConnection(savedPos, pos, world)){
|
||||||
ItemPhantomConnector.clearStorage(stack);
|
ItemPhantomConnector.clearStorage(stack);
|
||||||
|
|
||||||
((TileEntityLaserRelay)world.getTileEntity(savedPos)).sendUpdate();
|
((TileEntityLaserRelay)world.getTileEntity(savedPos)).sendUpdate();
|
||||||
|
|
|
@ -17,6 +17,7 @@ import io.netty.util.internal.ConcurrentSet;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class LaserRelayConnectionHandler{
|
public class LaserRelayConnectionHandler{
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ public class LaserRelayConnectionHandler{
|
||||||
/**
|
/**
|
||||||
* Gets all Connections for a Relay
|
* Gets all Connections for a Relay
|
||||||
*/
|
*/
|
||||||
public static ConcurrentSet<ConnectionPair> getConnectionsFor(BlockPos relay, int world){
|
public static ConcurrentSet<ConnectionPair> getConnectionsFor(BlockPos relay, World world){
|
||||||
ConcurrentSet<ConnectionPair> allPairs = new ConcurrentSet<ConnectionPair>();
|
ConcurrentSet<ConnectionPair> allPairs = new ConcurrentSet<ConnectionPair>();
|
||||||
for(Network aNetwork : WorldData.getDataForWorld(world).laserRelayNetworks){
|
for(Network aNetwork : WorldData.getDataForWorld(world).laserRelayNetworks){
|
||||||
for(ConnectionPair pair : aNetwork.connections){
|
for(ConnectionPair pair : aNetwork.connections){
|
||||||
|
@ -57,7 +58,7 @@ public class LaserRelayConnectionHandler{
|
||||||
/**
|
/**
|
||||||
* Removes a Relay from its Network
|
* Removes a Relay from its Network
|
||||||
*/
|
*/
|
||||||
public static void removeRelayFromNetwork(BlockPos relay, int world){
|
public static void removeRelayFromNetwork(BlockPos relay, World world){
|
||||||
Network network = getNetworkFor(relay, world);
|
Network network = getNetworkFor(relay, world);
|
||||||
if(network != null){
|
if(network != null){
|
||||||
//Setup new network (so that splitting a network will cause it to break into two)
|
//Setup new network (so that splitting a network will cause it to break into two)
|
||||||
|
@ -74,7 +75,7 @@ public class LaserRelayConnectionHandler{
|
||||||
/**
|
/**
|
||||||
* Gets a Network for a Relay
|
* Gets a Network for a Relay
|
||||||
*/
|
*/
|
||||||
public static Network getNetworkFor(BlockPos relay, int world){
|
public static Network getNetworkFor(BlockPos relay, World world){
|
||||||
for(Network aNetwork : WorldData.getDataForWorld(world).laserRelayNetworks){
|
for(Network aNetwork : WorldData.getDataForWorld(world).laserRelayNetworks){
|
||||||
for(ConnectionPair pair : aNetwork.connections){
|
for(ConnectionPair pair : aNetwork.connections){
|
||||||
if(pair.contains(relay)){
|
if(pair.contains(relay)){
|
||||||
|
@ -89,7 +90,7 @@ public class LaserRelayConnectionHandler{
|
||||||
* Adds a new connection between two relays
|
* Adds a new connection between two relays
|
||||||
* (Puts it into the correct network!)
|
* (Puts it into the correct network!)
|
||||||
*/
|
*/
|
||||||
public static boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, int world){
|
public static boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, World world){
|
||||||
int distance = (int)PosUtil.toVec(firstRelay).distanceTo(PosUtil.toVec(secondRelay));
|
int distance = (int)PosUtil.toVec(firstRelay).distanceTo(PosUtil.toVec(secondRelay));
|
||||||
if(distance > TileEntityLaserRelay.MAX_DISTANCE || PosUtil.areSamePos(firstRelay, secondRelay)){
|
if(distance > TileEntityLaserRelay.MAX_DISTANCE || PosUtil.areSamePos(firstRelay, secondRelay)){
|
||||||
return false;
|
return false;
|
||||||
|
@ -131,7 +132,7 @@ public class LaserRelayConnectionHandler{
|
||||||
* Merges two laserRelayNetworks together
|
* Merges two laserRelayNetworks together
|
||||||
* (Actually puts everything from the second network into the first one and removes the second one)
|
* (Actually puts everything from the second network into the first one and removes the second one)
|
||||||
*/
|
*/
|
||||||
public static void mergeNetworks(Network firstNetwork, Network secondNetwork, int world){
|
public static void mergeNetworks(Network firstNetwork, Network secondNetwork, World world){
|
||||||
for(ConnectionPair secondPair : secondNetwork.connections){
|
for(ConnectionPair secondPair : secondNetwork.connections){
|
||||||
firstNetwork.connections.add(secondPair);
|
firstNetwork.connections.add(secondPair);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
||||||
private List<GenericItemHandlerInfo> getItemHandlerInfos(){
|
private List<GenericItemHandlerInfo> getItemHandlerInfos(){
|
||||||
TileEntityLaserRelayItem relay = this.getConnectedRelay();
|
TileEntityLaserRelayItem relay = this.getConnectedRelay();
|
||||||
if(relay != null){
|
if(relay != null){
|
||||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(relay.getPos(), this.worldObj.provider.getDimension());
|
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(relay.getPos(), this.worldObj);
|
||||||
if(network != null){
|
if(network != null){
|
||||||
return relay.getItemHandlersInNetwork(network);
|
return relay.getItemHandlersInNetwork(network);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,13 +37,13 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveSyncCompound(NBTTagCompound compound){
|
public void receiveSyncCompound(NBTTagCompound compound){
|
||||||
LaserRelayConnectionHandler.removeRelayFromNetwork(this.pos, this.worldObj.provider.getDimension());
|
LaserRelayConnectionHandler.removeRelayFromNetwork(this.pos, this.worldObj);
|
||||||
|
|
||||||
NBTTagList list = compound.getTagList("Connections", 10);
|
NBTTagList list = compound.getTagList("Connections", 10);
|
||||||
if(!list.hasNoTags()){
|
if(!list.hasNoTags()){
|
||||||
for(int i = 0; i < list.tagCount(); i++){
|
for(int i = 0; i < list.tagCount(); i++){
|
||||||
LaserRelayConnectionHandler.ConnectionPair pair = LaserRelayConnectionHandler.ConnectionPair.readFromNBT(list.getCompoundTagAt(i));
|
LaserRelayConnectionHandler.ConnectionPair pair = LaserRelayConnectionHandler.ConnectionPair.readFromNBT(list.getCompoundTagAt(i));
|
||||||
LaserRelayConnectionHandler.addConnection(pair.firstRelay, pair.secondRelay, this.worldObj.provider.getDimension());
|
LaserRelayConnectionHandler.addConnection(pair.firstRelay, pair.secondRelay, this.worldObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
NBTTagCompound compound = super.getUpdateTag();
|
NBTTagCompound compound = super.getUpdateTag();
|
||||||
NBTTagList list = new NBTTagList();
|
NBTTagList list = new NBTTagList();
|
||||||
|
|
||||||
ConcurrentSet<LaserRelayConnectionHandler.ConnectionPair> connections = LaserRelayConnectionHandler.getConnectionsFor(this.pos, this.worldObj.provider.getDimension());
|
ConcurrentSet<LaserRelayConnectionHandler.ConnectionPair> connections = LaserRelayConnectionHandler.getConnectionsFor(this.pos, this.worldObj);
|
||||||
if(connections != null && !connections.isEmpty()){
|
if(connections != null && !connections.isEmpty()){
|
||||||
for(LaserRelayConnectionHandler.ConnectionPair pair : connections){
|
for(LaserRelayConnectionHandler.ConnectionPair pair : connections){
|
||||||
list.appendTag(pair.writeToNBT());
|
list.appendTag(pair.writeToNBT());
|
||||||
|
@ -79,7 +79,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
public void renderParticles(){
|
public void renderParticles(){
|
||||||
if(Util.RANDOM.nextInt(ConfigValues.lessParticles ? 16 : 8) == 0){
|
if(Util.RANDOM.nextInt(ConfigValues.lessParticles ? 16 : 8) == 0){
|
||||||
BlockPos thisPos = this.pos;
|
BlockPos thisPos = this.pos;
|
||||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(thisPos, this.worldObj.provider.getDimension());
|
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(thisPos, this.worldObj);
|
||||||
if(network != null){
|
if(network != null){
|
||||||
for(LaserRelayConnectionHandler.ConnectionPair aPair : network.connections){
|
for(LaserRelayConnectionHandler.ConnectionPair aPair : network.connections){
|
||||||
if(aPair.contains(thisPos) && PosUtil.areSamePos(thisPos, aPair.firstRelay)){
|
if(aPair.contains(thisPos) && PosUtil.areSamePos(thisPos, aPair.firstRelay)){
|
||||||
|
@ -93,7 +93,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
@Override
|
@Override
|
||||||
public void invalidate(){
|
public void invalidate(){
|
||||||
super.invalidate();
|
super.invalidate();
|
||||||
LaserRelayConnectionHandler.removeRelayFromNetwork(this.pos, this.worldObj.provider.getDimension());
|
LaserRelayConnectionHandler.removeRelayFromNetwork(this.pos, this.worldObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
|
||||||
public int transmitEnergy(BlockPos blockFrom, int maxTransmit, boolean simulate){
|
public int transmitEnergy(BlockPos blockFrom, int maxTransmit, boolean simulate){
|
||||||
int transmitted = 0;
|
int transmitted = 0;
|
||||||
if(maxTransmit > 0){
|
if(maxTransmit > 0){
|
||||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(this.pos, this.worldObj.provider.getDimension());
|
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(this.pos, this.worldObj);
|
||||||
if(network != null){
|
if(network != null){
|
||||||
transmitted = this.transferEnergyToReceiverInNeed(blockFrom, network, Math.min(ConfigIntValues.LASER_RELAY_MAX_TRANSFER.getValue(), maxTransmit), simulate);
|
transmitted = this.transferEnergyToReceiverInNeed(blockFrom, network, Math.min(ConfigIntValues.LASER_RELAY_MAX_TRANSFER.getValue(), maxTransmit), simulate);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue