Added basic Laser Connection setup & World Storage

This commit is contained in:
Ellpeck 2015-10-19 17:50:43 +02:00
parent 09fd03f270
commit b641977ec2
5 changed files with 175 additions and 4 deletions

View file

@ -34,6 +34,7 @@ import ellpeck.actuallyadditions.material.InitToolMaterials;
import ellpeck.actuallyadditions.misc.DispenserHandlerEmptyBucket;
import ellpeck.actuallyadditions.misc.DispenserHandlerFertilize;
import ellpeck.actuallyadditions.misc.DispenserHandlerFillBucket;
import ellpeck.actuallyadditions.misc.WorldData;
import ellpeck.actuallyadditions.network.PacketHandler;
import ellpeck.actuallyadditions.ore.InitOreDict;
import ellpeck.actuallyadditions.proxy.IProxy;
@ -117,5 +118,7 @@ public class ActuallyAdditions{
Util.registerDispenserHandler(InitItems.itemBucketCanolaOil, new DispenserHandlerEmptyBucket());
Util.registerDispenserHandler(Items.bucket, new DispenserHandlerFillBucket());
Util.registerDispenserHandler(InitItems.itemFertilizer, new DispenserHandlerFertilize());
WorldData.init(event.getServer());
}
}

View file

@ -97,7 +97,7 @@ public class InitBlocks{
public static Block blockDirectionalBreaker;
public static Block blockRangedCollector;
//public static Block blockLaserRelay;
public static Block blockLaserRelay;
//TODO: Plan for Laser Power Transmitters:
//TODO: Connectable with Laser Wrench
@ -112,8 +112,8 @@ public class InitBlocks{
public static void init(){
ModUtil.LOGGER.info("Initializing Blocks...");
//blockLaserRelay = new BlockLaserRelay();
//BlockUtil.register(blockLaserRelay);
blockLaserRelay = new BlockLaserRelay();
BlockUtil.register(blockLaserRelay);
blockRangedCollector = new BlockRangedCollector();
BlockUtil.register(blockRangedCollector);

View file

@ -0,0 +1,106 @@
/*
* This file ("LaserRelayConnectionHandler.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.misc;
import ellpeck.actuallyadditions.util.WorldPos;
import java.util.ArrayList;
public class LaserRelayConnectionHandler{
private static LaserRelayConnectionHandler instance;
/**
* An ArrayList of all of the networks a world has
* (Every place contains an ArrayList of ConnectionPairs, that is a single network!)
*/
public ArrayList<ArrayList<ConnectionPair>> networks = new ArrayList<ArrayList<ConnectionPair>>();
public static LaserRelayConnectionHandler getInstance(){
if(instance == null){
instance = new LaserRelayConnectionHandler();
}
return instance;
}
/**
* Gets a Network for a Relay
*/
public ArrayList<ConnectionPair> getNetworkFor(WorldPos relay){
for(ArrayList<ConnectionPair> aNetwork : this.networks){
for(ConnectionPair pair : aNetwork){
if(pair.contains(relay)){
return aNetwork;
}
}
}
return null;
}
/**
* Adds a new connection between two relays
* (Puts it into the correct network!)
*/
public void addConnection(WorldPos firstRelay, WorldPos secondRelay){
ArrayList<ConnectionPair> firstNetwork = this.getNetworkFor(firstRelay);
ArrayList<ConnectionPair> secondNetwork = this.getNetworkFor(secondRelay);
if(firstNetwork != null && secondNetwork != null){
this.mergeNetworks(firstNetwork, secondNetwork);
}
else if(firstNetwork != null){
firstNetwork.add(new ConnectionPair(firstRelay, secondRelay));
}
else if(secondNetwork != null){
secondNetwork.add(new ConnectionPair(firstRelay, secondRelay));
}
}
/**
* Removes a Relay from its Network
*/
public void removeRelayFromNetwork(WorldPos relay){
ArrayList<ConnectionPair> network = this.getNetworkFor(relay);
if(network != null){
for(ConnectionPair pair : network){
if(pair.contains(relay)){
network.remove(pair);
}
}
}
}
/**
* Merges two networks together
* (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){
for(ConnectionPair secondPair : secondNetwork){
firstNetwork.add(secondPair);
}
this.networks.remove(secondNetwork);
}
public static class ConnectionPair{
public WorldPos firstRelay;
public WorldPos secondRelay;
public ConnectionPair(WorldPos firstRelay, WorldPos secondRelay){
this.firstRelay = firstRelay;
this.secondRelay = secondRelay;
}
public boolean contains(WorldPos relay){
return (this.firstRelay != null && this.firstRelay.isEqual(relay)) || (this.secondRelay != null && this.secondRelay.isEqual(relay));
}
}
}

View file

@ -0,0 +1,62 @@
/*
* This file ("WorldData.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.misc;
import ellpeck.actuallyadditions.util.ModUtil;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraft.world.WorldSavedData;
public class WorldData extends WorldSavedData{
public static final String DATA_TAG = ModUtil.MOD_ID+"WorldData";
public WorldData(){
super(DATA_TAG);
}
public static WorldData instance;
@Override
public void readFromNBT(NBTTagCompound compound){
}
@Override
public void writeToNBT(NBTTagCompound compound){
}
public static void makeDirty(){
if(instance != null){
instance.markDirty();
}
}
public static void init(MinecraftServer server){
if(server != null){
World world = server.getEntityWorld();
if(!world.isRemote){
WorldSavedData savedData = world.loadItemData(WorldData.class, WorldData.DATA_TAG);
//Generate new SavedData
if(savedData == null){
savedData = new WorldData();
world.setItemData(WorldData.DATA_TAG, savedData);
}
//Set the current SavedData to the retreived one
if(savedData instanceof WorldData){
WorldData.instance = (WorldData)savedData;
}
}
}
}
}

View file

@ -62,7 +62,7 @@ public abstract class TileEntityBase extends TileEntity{
GameRegistry.registerTileEntity(TileEntityLeafGenerator.class, ModUtil.MOD_ID_LOWER+":tileEntityLeafGenerator");
GameRegistry.registerTileEntity(TileEntityDirectionalBreaker.class, ModUtil.MOD_ID_LOWER+":tileEntityDirectionalBreaker");
GameRegistry.registerTileEntity(TileEntityRangedCollector.class, ModUtil.MOD_ID_LOWER+":tileEntityRangedCollector");
//GameRegistry.registerTileEntity(TileEntityLaserRelay.class, ModUtil.MOD_ID_LOWER+":tileEntityLaserRelay");
GameRegistry.registerTileEntity(TileEntityLaserRelay.class, ModUtil.MOD_ID_LOWER+":tileEntityLaserRelay");
}
@Override