mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 16:58:34 +01:00
Actually fixed Laser Network bugging sometimes for real now instead of thinking of stupid workarounds that don't really work
This commit is contained in:
parent
c300b080f4
commit
a7c8a3c6e4
6 changed files with 97 additions and 126 deletions
|
@ -31,10 +31,7 @@ import ellpeck.actuallyadditions.items.InitItems;
|
||||||
import ellpeck.actuallyadditions.items.ItemCoffee;
|
import ellpeck.actuallyadditions.items.ItemCoffee;
|
||||||
import ellpeck.actuallyadditions.material.InitArmorMaterials;
|
import ellpeck.actuallyadditions.material.InitArmorMaterials;
|
||||||
import ellpeck.actuallyadditions.material.InitToolMaterials;
|
import ellpeck.actuallyadditions.material.InitToolMaterials;
|
||||||
import ellpeck.actuallyadditions.misc.DispenserHandlerEmptyBucket;
|
import ellpeck.actuallyadditions.misc.*;
|
||||||
import ellpeck.actuallyadditions.misc.DispenserHandlerFertilize;
|
|
||||||
import ellpeck.actuallyadditions.misc.DispenserHandlerFillBucket;
|
|
||||||
import ellpeck.actuallyadditions.misc.WorldData;
|
|
||||||
import ellpeck.actuallyadditions.network.PacketHandler;
|
import ellpeck.actuallyadditions.network.PacketHandler;
|
||||||
import ellpeck.actuallyadditions.ore.InitOreDict;
|
import ellpeck.actuallyadditions.ore.InitOreDict;
|
||||||
import ellpeck.actuallyadditions.proxy.IProxy;
|
import ellpeck.actuallyadditions.proxy.IProxy;
|
||||||
|
@ -119,6 +116,16 @@ public class ActuallyAdditions{
|
||||||
Util.registerDispenserHandler(Items.bucket, new DispenserHandlerFillBucket());
|
Util.registerDispenserHandler(Items.bucket, new DispenserHandlerFillBucket());
|
||||||
Util.registerDispenserHandler(InitItems.itemFertilizer, new DispenserHandlerFertilize());
|
Util.registerDispenserHandler(InitItems.itemFertilizer, new DispenserHandlerFertilize());
|
||||||
|
|
||||||
|
if(LaserRelayConnectionHandler.getInstance() == null){
|
||||||
|
LaserRelayConnectionHandler.setInstance(new LaserRelayConnectionHandler());
|
||||||
|
}
|
||||||
|
|
||||||
WorldData.init(event.getServer());
|
WorldData.init(event.getServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void serverStopped(FMLServerStoppedEvent event){
|
||||||
|
//Clear all Network Connections so that they won't be carried over into other worlds
|
||||||
|
LaserRelayConnectionHandler.getInstance().networks.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ public class InitEvents{
|
||||||
Util.registerEvent(new EntityLivingEvent());
|
Util.registerEvent(new EntityLivingEvent());
|
||||||
Util.registerEvent(new BucketFillEvent());
|
Util.registerEvent(new BucketFillEvent());
|
||||||
Util.registerEvent(new LogoutEvent());
|
Util.registerEvent(new LogoutEvent());
|
||||||
Util.registerEvent(new WorldLoadEvent());
|
|
||||||
MinecraftForge.TERRAIN_GEN_BUS.register(new WorldDecorationEvent());
|
MinecraftForge.TERRAIN_GEN_BUS.register(new WorldDecorationEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
* This file ("WorldLoadEvent.java") is part of the Actually Additions Mod for Minecraft.
|
|
||||||
* It is created and owned by Ellpeck and distributed
|
|
||||||
* under the Actually Additions License to be found at
|
|
||||||
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
||||||
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
||||||
*
|
|
||||||
* © 2015 Ellpeck
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ellpeck.actuallyadditions.event;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import ellpeck.actuallyadditions.misc.LaserRelayConnectionHandler;
|
|
||||||
import net.minecraftforge.event.world.WorldEvent;
|
|
||||||
|
|
||||||
public class WorldLoadEvent{
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onLoad(WorldEvent.Load event){
|
|
||||||
if(LaserRelayConnectionHandler.getInstance() == null){
|
|
||||||
LaserRelayConnectionHandler.setInstance(new LaserRelayConnectionHandler());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -15,23 +15,20 @@ import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
||||||
import ellpeck.actuallyadditions.tile.TileEntityLaserRelay;
|
import ellpeck.actuallyadditions.tile.TileEntityLaserRelay;
|
||||||
import ellpeck.actuallyadditions.util.WorldPos;
|
import ellpeck.actuallyadditions.util.WorldPos;
|
||||||
import ellpeck.actuallyadditions.util.WorldUtil;
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
||||||
|
import io.netty.util.internal.ConcurrentSet;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
//This is probably like punching any experienced programmer in the face, but it works.
|
|
||||||
@SuppressWarnings("ForLoopReplaceableByForEach")
|
|
||||||
public class LaserRelayConnectionHandler{
|
public class LaserRelayConnectionHandler{
|
||||||
|
|
||||||
private static LaserRelayConnectionHandler instance;
|
private static LaserRelayConnectionHandler instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An ArrayList of all of the networks a world has
|
* All of the Networks
|
||||||
* (Every place contains an ArrayList of ConnectionPairs, that is a single network!)
|
|
||||||
*/
|
*/
|
||||||
public ArrayList<ArrayList<ConnectionPair>> networks = new ArrayList<ArrayList<ConnectionPair>>();
|
public ConcurrentSet<Network> networks = new ConcurrentSet<Network>();
|
||||||
|
|
||||||
public static LaserRelayConnectionHandler getInstance(){
|
public static LaserRelayConnectionHandler getInstance(){
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -41,40 +38,32 @@ public class LaserRelayConnectionHandler{
|
||||||
instance = i;
|
instance = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeNetworkToNBT(ArrayList<ConnectionPair> network, NBTTagCompound tag, String name){
|
public NBTTagCompound writeNetworkToNBT(Network network){
|
||||||
|
NBTTagList list = new NBTTagList();
|
||||||
|
for(ConnectionPair pair : network.connections){
|
||||||
|
list.appendTag(pair.writeToNBT());
|
||||||
|
}
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
NBTTagCompound compound = new NBTTagCompound();
|
||||||
compound.setInteger("NetworkSize", network.size());
|
compound.setTag("Network", list);
|
||||||
|
return compound;
|
||||||
for(int pair = 0; pair < network.size(); pair++){
|
|
||||||
network.get(pair).writeToNBT(compound, "Pair"+pair);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.setTag(name, compound);
|
public Network readNetworkFromNBT(NBTTagCompound tag){
|
||||||
|
NBTTagList list = tag.getTagList("Network", 10);
|
||||||
|
Network network = new Network();
|
||||||
|
for(int i = 0; i < list.tagCount(); i++){
|
||||||
|
network.connections.add(ConnectionPair.readFromNBT(list.getCompoundTagAt(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<ConnectionPair> readNetworkFromNBT(NBTTagCompound tag, String name){
|
|
||||||
NBTTagCompound compound = tag.getCompoundTag(name);
|
|
||||||
|
|
||||||
int networkSize = compound.getInteger("NetworkSize");
|
|
||||||
|
|
||||||
ArrayList<ConnectionPair> network = new ArrayList<ConnectionPair>();
|
|
||||||
for(int pair = 0; pair < networkSize; pair++){
|
|
||||||
network.add(ConnectionPair.readFromNBT(compound, "Pair"+pair));
|
|
||||||
}
|
|
||||||
|
|
||||||
return network;
|
return network;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all Connections for a Relay
|
* Gets all Connections for a Relay
|
||||||
*/
|
*/
|
||||||
public ArrayList<ConnectionPair> getConnectionsFor(WorldPos relay){
|
public ConcurrentSet<ConnectionPair> getConnectionsFor(WorldPos relay){
|
||||||
ArrayList<ConnectionPair> allPairs = new ArrayList<ConnectionPair>();
|
ConcurrentSet<ConnectionPair> allPairs = new ConcurrentSet<ConnectionPair>();
|
||||||
ArrayList<ArrayList<ConnectionPair>> networks1 = this.networks;
|
for(Network aNetwork : this.networks){
|
||||||
for(int i = 0; i < networks1.size(); i++){
|
for(ConnectionPair pair : aNetwork.connections){
|
||||||
ArrayList<ConnectionPair> aNetwork = networks1.get(i);
|
|
||||||
for(int i1 = 0; i1 < aNetwork.size(); i1++){
|
|
||||||
ConnectionPair pair = aNetwork.get(i1);
|
|
||||||
if(pair.contains(relay)){
|
if(pair.contains(relay)){
|
||||||
allPairs.add(pair);
|
allPairs.add(pair);
|
||||||
}
|
}
|
||||||
|
@ -87,16 +76,16 @@ public class LaserRelayConnectionHandler{
|
||||||
* Removes a Relay from its Network
|
* Removes a Relay from its Network
|
||||||
*/
|
*/
|
||||||
public void removeRelayFromNetwork(WorldPos relay){
|
public void removeRelayFromNetwork(WorldPos relay){
|
||||||
ArrayList<ConnectionPair> network = this.getNetworkFor(relay);
|
Network network = this.getNetworkFor(relay);
|
||||||
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)
|
||||||
this.networks.remove(network);
|
this.networks.remove(network);
|
||||||
for(int i = 0; i < network.size(); i++){
|
for(ConnectionPair pair : network.connections){
|
||||||
ConnectionPair pair = network.get(i);
|
|
||||||
if(!pair.contains(relay)){
|
if(!pair.contains(relay)){
|
||||||
this.addConnection(pair.firstRelay, pair.secondRelay);
|
this.addConnection(pair.firstRelay, pair.secondRelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
System.out.println("Removing a Relay from the Network!");
|
||||||
}
|
}
|
||||||
WorldData.makeDirty();
|
WorldData.makeDirty();
|
||||||
}
|
}
|
||||||
|
@ -104,12 +93,9 @@ public class LaserRelayConnectionHandler{
|
||||||
/**
|
/**
|
||||||
* Gets a Network for a Relay
|
* Gets a Network for a Relay
|
||||||
*/
|
*/
|
||||||
public ArrayList<ConnectionPair> getNetworkFor(WorldPos relay){
|
public Network getNetworkFor(WorldPos relay){
|
||||||
ArrayList<ArrayList<ConnectionPair>> networks1 = this.networks;
|
for(Network aNetwork : this.networks){
|
||||||
for(int i = 0; i < networks1.size(); i++){
|
for(ConnectionPair pair : aNetwork.connections){
|
||||||
ArrayList<ConnectionPair> aNetwork = networks1.get(i);
|
|
||||||
for(int i1 = 0; i1 < aNetwork.size(); i1++){
|
|
||||||
ConnectionPair pair = aNetwork.get(i1);
|
|
||||||
if(pair.contains(relay)){
|
if(pair.contains(relay)){
|
||||||
return aNetwork;
|
return aNetwork;
|
||||||
}
|
}
|
||||||
|
@ -128,14 +114,14 @@ public class LaserRelayConnectionHandler{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<ConnectionPair> firstNetwork = this.getNetworkFor(firstRelay);
|
Network firstNetwork = this.getNetworkFor(firstRelay);
|
||||||
ArrayList<ConnectionPair> secondNetwork = this.getNetworkFor(secondRelay);
|
Network secondNetwork = this.getNetworkFor(secondRelay);
|
||||||
|
|
||||||
//No Network exists
|
//No Network exists
|
||||||
if(firstNetwork == null && secondNetwork == null){
|
if(firstNetwork == null && secondNetwork == null){
|
||||||
firstNetwork = new ArrayList<ConnectionPair>();
|
firstNetwork = new Network();
|
||||||
this.networks.add(firstNetwork);
|
this.networks.add(firstNetwork);
|
||||||
firstNetwork.add(new ConnectionPair(firstRelay, secondRelay));
|
firstNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay));
|
||||||
}
|
}
|
||||||
//The same Network
|
//The same Network
|
||||||
else if(firstNetwork == secondNetwork){
|
else if(firstNetwork == secondNetwork){
|
||||||
|
@ -144,19 +130,20 @@ public class LaserRelayConnectionHandler{
|
||||||
//Both relays have networks
|
//Both relays have networks
|
||||||
else if(firstNetwork != null && secondNetwork != null){
|
else if(firstNetwork != null && secondNetwork != null){
|
||||||
this.mergeNetworks(firstNetwork, secondNetwork);
|
this.mergeNetworks(firstNetwork, secondNetwork);
|
||||||
firstNetwork.add(new ConnectionPair(firstRelay, secondRelay));
|
firstNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay));
|
||||||
}
|
}
|
||||||
//Only first network exists
|
//Only first network exists
|
||||||
else if(firstNetwork != null){
|
else if(firstNetwork != null){
|
||||||
firstNetwork.add(new ConnectionPair(firstRelay, secondRelay));
|
firstNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay));
|
||||||
}
|
}
|
||||||
//Only second network exists
|
//Only second network exists
|
||||||
else if(secondNetwork != null){
|
else if(secondNetwork != null){
|
||||||
secondNetwork.add(new ConnectionPair(firstRelay, secondRelay));
|
secondNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay));
|
||||||
}
|
}
|
||||||
WorldData.makeDirty();
|
WorldData.makeDirty();
|
||||||
//System.out.println("Connected "+firstRelay.toString()+" to "+secondRelay.toString());
|
System.out.println("Connected "+firstRelay.toString()+" to "+secondRelay.toString());
|
||||||
//System.out.println(firstNetwork == null ? secondNetwork.toString() : firstNetwork.toString());
|
System.out.println(firstNetwork == null ? secondNetwork.toString() : firstNetwork.toString());
|
||||||
|
System.out.println(this.networks);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,21 +151,19 @@ public class LaserRelayConnectionHandler{
|
||||||
* Merges two networks together
|
* Merges two networks 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 void mergeNetworks(ArrayList<ConnectionPair> firstNetwork, ArrayList<ConnectionPair> secondNetwork){
|
public void mergeNetworks(Network firstNetwork, Network secondNetwork){
|
||||||
for(int i = 0; i < secondNetwork.size(); i++){
|
for(ConnectionPair secondPair : secondNetwork.connections){
|
||||||
ConnectionPair secondPair = secondNetwork.get(i);
|
firstNetwork.connections.add(secondPair);
|
||||||
firstNetwork.add(secondPair);
|
|
||||||
}
|
}
|
||||||
this.networks.remove(secondNetwork);
|
this.networks.remove(secondNetwork);
|
||||||
WorldData.makeDirty();
|
WorldData.makeDirty();
|
||||||
//System.out.println("Merged Two Networks!");
|
System.out.println("Merged Two Networks!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int transferEnergyToReceiverInNeed(ArrayList<ConnectionPair> network, int maxTransfer, boolean simulate){
|
public int transferEnergyToReceiverInNeed(Network network, int maxTransfer, boolean simulate){
|
||||||
int transmitted = 0;
|
int transmitted = 0;
|
||||||
//Go through all of the connections in the network
|
//Go through all of the connections in the network
|
||||||
for(int i1 = 0; i1 < network.size(); i1++){
|
for(ConnectionPair pair : network.connections){
|
||||||
ConnectionPair pair = network.get(i1);
|
|
||||||
WorldPos[] relays = new WorldPos[]{pair.firstRelay, pair.secondRelay};
|
WorldPos[] relays = new WorldPos[]{pair.firstRelay, pair.secondRelay};
|
||||||
//Go through both relays in the connection
|
//Go through both relays in the connection
|
||||||
for(WorldPos relay : relays){
|
for(WorldPos relay : relays){
|
||||||
|
@ -217,13 +202,13 @@ public class LaserRelayConnectionHandler{
|
||||||
this.secondRelay = secondRelay;
|
this.secondRelay = secondRelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConnectionPair readFromNBT(NBTTagCompound compound, String name){
|
public static ConnectionPair readFromNBT(NBTTagCompound compound){
|
||||||
WorldPos[] pos = new WorldPos[2];
|
WorldPos[] pos = new WorldPos[2];
|
||||||
for(int i = 0; i < pos.length; i++){
|
for(int i = 0; i < pos.length; i++){
|
||||||
int anX = compound.getInteger("x"+name+i);
|
int anX = compound.getInteger("x"+i);
|
||||||
int aY = compound.getInteger("y"+name+i);
|
int aY = compound.getInteger("y"+i);
|
||||||
int aZ = compound.getInteger("z"+name+i);
|
int aZ = compound.getInteger("z"+i);
|
||||||
pos[i] = new WorldPos(compound.getInteger("world"+name+i), anX, aY, aZ);
|
pos[i] = new WorldPos(compound.getInteger("world"+i), anX, aY, aZ);
|
||||||
}
|
}
|
||||||
return new ConnectionPair(pos[0], pos[1]);
|
return new ConnectionPair(pos[0], pos[1]);
|
||||||
}
|
}
|
||||||
|
@ -237,14 +222,26 @@ public class LaserRelayConnectionHandler{
|
||||||
return (this.firstRelay == null ? "-" : this.firstRelay.toString())+" | "+(this.secondRelay == null ? "-" : this.secondRelay.toString());
|
return (this.firstRelay == null ? "-" : this.firstRelay.toString())+" | "+(this.secondRelay == null ? "-" : this.secondRelay.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToNBT(NBTTagCompound compound, String name){
|
public NBTTagCompound writeToNBT(){
|
||||||
|
NBTTagCompound compound = new NBTTagCompound();
|
||||||
for(int i = 0; i < 2; i++){
|
for(int i = 0; i < 2; i++){
|
||||||
WorldPos relay = i == 0 ? this.firstRelay : this.secondRelay;
|
WorldPos relay = i == 0 ? this.firstRelay : this.secondRelay;
|
||||||
compound.setInteger("world"+name+i, relay.getWorldID());
|
compound.setInteger("world"+i, relay.getWorldID());
|
||||||
compound.setInteger("x"+name+i, relay.getX());
|
compound.setInteger("x"+i, relay.getX());
|
||||||
compound.setInteger("y"+name+i, relay.getY());
|
compound.setInteger("y"+i, relay.getY());
|
||||||
compound.setInteger("z"+name+i, relay.getZ());
|
compound.setInteger("z"+i, relay.getZ());
|
||||||
}
|
}
|
||||||
|
return compound;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Network{
|
||||||
|
|
||||||
|
public ConcurrentSet<ConnectionPair> connections = new ConcurrentSet<ConnectionPair>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return this.connections.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -13,12 +13,11 @@ package ellpeck.actuallyadditions.misc;
|
||||||
import ellpeck.actuallyadditions.util.ModUtil;
|
import ellpeck.actuallyadditions.util.ModUtil;
|
||||||
import ellpeck.actuallyadditions.util.playerdata.PersistentServerData;
|
import ellpeck.actuallyadditions.util.playerdata.PersistentServerData;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldSavedData;
|
import net.minecraft.world.WorldSavedData;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class WorldData extends WorldSavedData{
|
public class WorldData extends WorldSavedData{
|
||||||
|
|
||||||
public static final String DATA_TAG = ModUtil.MOD_ID+"WorldData";
|
public static final String DATA_TAG = ModUtil.MOD_ID+"WorldData";
|
||||||
|
@ -55,14 +54,11 @@ public class WorldData extends WorldSavedData{
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound compound){
|
public void readFromNBT(NBTTagCompound compound){
|
||||||
//Laser World Data
|
//Laser World Data
|
||||||
int netAmount = compound.getInteger("LaserNetworkAmount");
|
NBTTagList list = compound.getTagList("Networks", 10);
|
||||||
LaserRelayConnectionHandler.getInstance().networks.clear();
|
for(int i = 0; i < list.tagCount(); i++){
|
||||||
for(int i = 0; i < netAmount; i++){
|
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getInstance().readNetworkFromNBT(list.getCompoundTagAt(i));
|
||||||
ArrayList<LaserRelayConnectionHandler.ConnectionPair> network = LaserRelayConnectionHandler.getInstance().readNetworkFromNBT(compound, "LaserNetwork"+i);
|
|
||||||
if(network != null){
|
|
||||||
LaserRelayConnectionHandler.getInstance().networks.add(network);
|
LaserRelayConnectionHandler.getInstance().networks.add(network);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//Player Data
|
//Player Data
|
||||||
int dataSize = compound.getInteger("PersistentDataSize");
|
int dataSize = compound.getInteger("PersistentDataSize");
|
||||||
|
@ -78,12 +74,11 @@ public class WorldData extends WorldSavedData{
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound compound){
|
public void writeToNBT(NBTTagCompound compound){
|
||||||
//Laser World Data
|
//Laser World Data
|
||||||
int netAmount = LaserRelayConnectionHandler.getInstance().networks.size();
|
NBTTagList list = new NBTTagList();
|
||||||
compound.setInteger("LaserNetworkAmount", netAmount);
|
for(LaserRelayConnectionHandler.Network network : LaserRelayConnectionHandler.getInstance().networks){
|
||||||
|
list.appendTag(LaserRelayConnectionHandler.getInstance().writeNetworkToNBT(network));
|
||||||
for(int i = 0; i < netAmount; i++){
|
|
||||||
LaserRelayConnectionHandler.getInstance().writeNetworkToNBT(LaserRelayConnectionHandler.getInstance().networks.get(i), compound, "LaserNetwork"+i);
|
|
||||||
}
|
}
|
||||||
|
compound.setTag("Networks", list);
|
||||||
|
|
||||||
//Player Data
|
//Player Data
|
||||||
compound.setInteger("PersistentDataSize", PersistentServerData.playerSaveData.size());
|
compound.setInteger("PersistentDataSize", PersistentServerData.playerSaveData.size());
|
||||||
|
|
|
@ -16,16 +16,16 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
|
import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
|
||||||
import ellpeck.actuallyadditions.misc.LaserRelayConnectionHandler;
|
import ellpeck.actuallyadditions.misc.LaserRelayConnectionHandler;
|
||||||
import ellpeck.actuallyadditions.util.WorldPos;
|
import ellpeck.actuallyadditions.util.WorldPos;
|
||||||
|
import io.netty.util.internal.ConcurrentSet;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.particle.EntityReddustFX;
|
import net.minecraft.client.particle.EntityReddustFX;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.network.NetworkManager;
|
import net.minecraft.network.NetworkManager;
|
||||||
import net.minecraft.network.Packet;
|
import net.minecraft.network.Packet;
|
||||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class TileEntityLaserRelay extends TileEntityBase implements IEnergyReceiver{
|
public class TileEntityLaserRelay extends TileEntityBase implements IEnergyReceiver{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,15 +41,13 @@ public class TileEntityLaserRelay extends TileEntityBase implements IEnergyRecei
|
||||||
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(new WorldPos(this.worldObj, this.xCoord, this.yCoord, this.zCoord));
|
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(new WorldPos(this.worldObj, this.xCoord, this.yCoord, this.zCoord));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ForLoopReplaceableByForEach")
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public void renderParticles(){
|
public void renderParticles(){
|
||||||
if(this.worldObj.rand.nextInt(2) == 0){
|
if(this.worldObj.rand.nextInt(2) == 0){
|
||||||
WorldPos thisPos = new WorldPos(this.getWorldObj(), this.xCoord, this.yCoord, this.zCoord);
|
WorldPos thisPos = new WorldPos(this.getWorldObj(), this.xCoord, this.yCoord, this.zCoord);
|
||||||
ArrayList<LaserRelayConnectionHandler.ConnectionPair> network = LaserRelayConnectionHandler.getInstance().getNetworkFor(thisPos);
|
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getInstance().getNetworkFor(thisPos);
|
||||||
if(network != null){
|
if(network != null){
|
||||||
for(int i1 = 0; i1 < network.size(); i1++){
|
for(LaserRelayConnectionHandler.ConnectionPair aPair : network.connections){
|
||||||
LaserRelayConnectionHandler.ConnectionPair aPair = network.get(i1);
|
|
||||||
if(aPair.contains(thisPos) && thisPos.isEqual(aPair.firstRelay)){
|
if(aPair.contains(thisPos) && thisPos.isEqual(aPair.firstRelay)){
|
||||||
if(Minecraft.getMinecraft().thePlayer.getDistance(aPair.firstRelay.getX(), aPair.firstRelay.getY(), aPair.firstRelay.getZ()) <= 64){
|
if(Minecraft.getMinecraft().thePlayer.getDistance(aPair.firstRelay.getX(), aPair.firstRelay.getY(), aPair.firstRelay.getZ()) <= 64){
|
||||||
int difX = aPair.firstRelay.getX()-aPair.secondRelay.getX();
|
int difX = aPair.firstRelay.getX()-aPair.secondRelay.getX();
|
||||||
|
@ -72,13 +70,14 @@ public class TileEntityLaserRelay extends TileEntityBase implements IEnergyRecei
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
NBTTagCompound compound = new NBTTagCompound();
|
||||||
|
|
||||||
WorldPos thisPos = new WorldPos(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
WorldPos thisPos = new WorldPos(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
||||||
ArrayList<LaserRelayConnectionHandler.ConnectionPair> connections = LaserRelayConnectionHandler.getInstance().getConnectionsFor(thisPos);
|
ConcurrentSet<LaserRelayConnectionHandler.ConnectionPair> connections = LaserRelayConnectionHandler.getInstance().getConnectionsFor(thisPos);
|
||||||
|
|
||||||
if(connections != null){
|
if(connections != null){
|
||||||
compound.setInteger("ConnectionAmount", connections.size());
|
NBTTagList list = new NBTTagList();
|
||||||
for(int i = 0; i < connections.size(); i++){
|
for(LaserRelayConnectionHandler.ConnectionPair pair : connections){
|
||||||
connections.get(i).writeToNBT(compound, "Connection"+i);
|
list.appendTag(pair.writeToNBT());
|
||||||
}
|
}
|
||||||
|
compound.setTag("Connections", list);
|
||||||
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 3, compound);
|
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 3, compound);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -90,9 +89,9 @@ public class TileEntityLaserRelay extends TileEntityBase implements IEnergyRecei
|
||||||
|
|
||||||
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(new WorldPos(this.worldObj, this.xCoord, this.yCoord, this.zCoord));
|
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(new WorldPos(this.worldObj, this.xCoord, this.yCoord, this.zCoord));
|
||||||
|
|
||||||
int amount = compound.getInteger("ConnectionAmount");
|
NBTTagList list = compound.getTagList("Connections", 10);
|
||||||
for(int i = 0; i < amount; i++){
|
for(int i = 0; i < list.tagCount(); i++){
|
||||||
LaserRelayConnectionHandler.ConnectionPair pair = LaserRelayConnectionHandler.ConnectionPair.readFromNBT(compound, "Connection"+i);
|
LaserRelayConnectionHandler.ConnectionPair pair = LaserRelayConnectionHandler.ConnectionPair.readFromNBT(list.getCompoundTagAt(i));
|
||||||
LaserRelayConnectionHandler.getInstance().addConnection(pair.firstRelay, pair.secondRelay);
|
LaserRelayConnectionHandler.getInstance().addConnection(pair.firstRelay, pair.secondRelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +114,7 @@ public class TileEntityLaserRelay extends TileEntityBase implements IEnergyRecei
|
||||||
public int transmitEnergy(int maxTransmit, boolean simulate){
|
public int transmitEnergy(int maxTransmit, boolean simulate){
|
||||||
int transmitted = 0;
|
int transmitted = 0;
|
||||||
if(maxTransmit > 0){
|
if(maxTransmit > 0){
|
||||||
ArrayList<LaserRelayConnectionHandler.ConnectionPair> network = LaserRelayConnectionHandler.getInstance().getNetworkFor(new WorldPos(this.worldObj, this.xCoord, this.yCoord, this.zCoord));
|
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getInstance().getNetworkFor(new WorldPos(this.worldObj, this.xCoord, this.yCoord, this.zCoord));
|
||||||
if(network != null){
|
if(network != null){
|
||||||
transmitted = LaserRelayConnectionHandler.getInstance().transferEnergyToReceiverInNeed(network, maxTransmit, simulate);
|
transmitted = LaserRelayConnectionHandler.getInstance().transferEnergyToReceiverInNeed(network, maxTransmit, simulate);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue