mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 00:38:35 +01:00
Added ILaserRelayConnectionHandler to the API so that you can make your own Laser Relay connections :v
This commit is contained in:
parent
b26c74c23a
commit
df4bcf05cf
12 changed files with 204 additions and 119 deletions
|
@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.api;
|
||||||
import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
|
import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
|
||||||
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
|
||||||
import de.ellpeck.actuallyadditions.api.internal.IMethodHandler;
|
import de.ellpeck.actuallyadditions.api.internal.IMethodHandler;
|
||||||
|
import de.ellpeck.actuallyadditions.api.laser.ILaserRelayConnectionHandler;
|
||||||
import de.ellpeck.actuallyadditions.api.lens.Lens;
|
import de.ellpeck.actuallyadditions.api.lens.Lens;
|
||||||
import de.ellpeck.actuallyadditions.api.lens.LensConversion;
|
import de.ellpeck.actuallyadditions.api.lens.LensConversion;
|
||||||
import de.ellpeck.actuallyadditions.api.recipe.*;
|
import de.ellpeck.actuallyadditions.api.recipe.*;
|
||||||
|
@ -30,7 +31,7 @@ public final class ActuallyAdditionsAPI{
|
||||||
|
|
||||||
public static final String MOD_ID = "actuallyadditions";
|
public static final String MOD_ID = "actuallyadditions";
|
||||||
public static final String API_ID = MOD_ID+"api";
|
public static final String API_ID = MOD_ID+"api";
|
||||||
public static final String API_VERSION = "18";
|
public static final String API_VERSION = "19";
|
||||||
|
|
||||||
public static final List<CrusherRecipe> CRUSHER_RECIPES = new ArrayList<CrusherRecipe>();
|
public static final List<CrusherRecipe> CRUSHER_RECIPES = new ArrayList<CrusherRecipe>();
|
||||||
public static final List<BallOfFurReturn> BALL_OF_FUR_RETURN_ITEMS = new ArrayList<BallOfFurReturn>();
|
public static final List<BallOfFurReturn> BALL_OF_FUR_RETURN_ITEMS = new ArrayList<BallOfFurReturn>();
|
||||||
|
@ -41,12 +42,23 @@ public final class ActuallyAdditionsAPI{
|
||||||
public static final List<CompostRecipe> COMPOST_RECIPES = new ArrayList<CompostRecipe>();
|
public static final List<CompostRecipe> COMPOST_RECIPES = new ArrayList<CompostRecipe>();
|
||||||
public static final List<IBookletEntry> BOOKLET_ENTRIES = new ArrayList<IBookletEntry>();
|
public static final List<IBookletEntry> BOOKLET_ENTRIES = new ArrayList<IBookletEntry>();
|
||||||
public static final List<BookletPage> BOOKLET_PAGES_WITH_ITEM_DATA = new ArrayList<BookletPage>();
|
public static final List<BookletPage> BOOKLET_PAGES_WITH_ITEM_DATA = new ArrayList<BookletPage>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this to handle things that aren't based in the API itself
|
* Use this to handle things that aren't based in the API itself
|
||||||
* DO NOT CHANGE/OVERRIDE THIS!!
|
* DO NOT CHANGE/OVERRIDE THIS!!
|
||||||
* This is getting initialized in Actually Additions' PreInit phase
|
* This is getting initialized in Actually Additions' PreInit phase
|
||||||
*/
|
*/
|
||||||
public static IMethodHandler methodHandler;
|
public static IMethodHandler methodHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this to add, remove or get Laser Relay Connections and Networks
|
||||||
|
* The network system is built in a way that doesn't need the individual
|
||||||
|
* positions to be Laser Relays, it relies only on BlockPos
|
||||||
|
* DO NOT CHANGE/OVERRIDE THIS!!
|
||||||
|
* This is getting initialized in Actually Additions' PreInit phase
|
||||||
|
*/
|
||||||
|
public static ILaserRelayConnectionHandler connectionHandler;
|
||||||
|
|
||||||
//These are getting initialized in Actually Additions' PreInit phase
|
//These are getting initialized in Actually Additions' PreInit phase
|
||||||
//DO NOT CHANGE/OVERRIDE THESE!!
|
//DO NOT CHANGE/OVERRIDE THESE!!
|
||||||
public static IBookletEntry entryGettingStarted;
|
public static IBookletEntry entryGettingStarted;
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* This file ("ConnectionPair.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://ellpeck.de/actaddlicense
|
||||||
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||||
|
*
|
||||||
|
* © 2015-2016 Ellpeck
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.ellpeck.actuallyadditions.api.laser;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
public class ConnectionPair{
|
||||||
|
|
||||||
|
public final BlockPos[] positions = new BlockPos[2];
|
||||||
|
|
||||||
|
public ConnectionPair(BlockPos firstRelay, BlockPos secondRelay){
|
||||||
|
this.positions[0] = firstRelay;
|
||||||
|
this.positions[1] = secondRelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConnectionPair readFromNBT(NBTTagCompound compound){
|
||||||
|
if(compound != null){
|
||||||
|
BlockPos[] pos = new BlockPos[2];
|
||||||
|
for(int i = 0; i < pos.length; i++){
|
||||||
|
int anX = compound.getInteger("x"+i);
|
||||||
|
int aY = compound.getInteger("y"+i);
|
||||||
|
int aZ = compound.getInteger("z"+i);
|
||||||
|
pos[i] = new BlockPos(anX, aY, aZ);
|
||||||
|
}
|
||||||
|
return new ConnectionPair(pos[0], pos[1]);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(BlockPos relay){
|
||||||
|
for(BlockPos position : this.positions){
|
||||||
|
if(position != null && position.equals(relay)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return (this.positions[0] == null ? "-" : this.positions[0].toString())+" | "+(this.positions[1] == null ? "-" : this.positions[1].toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBTTagCompound writeToNBT(){
|
||||||
|
NBTTagCompound compound = new NBTTagCompound();
|
||||||
|
for(int i = 0; i < this.positions.length; i++){
|
||||||
|
BlockPos relay = this.positions[i];
|
||||||
|
compound.setInteger("x"+i, relay.getX());
|
||||||
|
compound.setInteger("y"+i, relay.getY());
|
||||||
|
compound.setInteger("z"+i, relay.getZ());
|
||||||
|
}
|
||||||
|
return compound;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj){
|
||||||
|
if(obj instanceof ConnectionPair){
|
||||||
|
ConnectionPair pair = (ConnectionPair)obj;
|
||||||
|
for(int i = 0; i < this.positions.length; i++){
|
||||||
|
if(this.positions[i] == pair.positions[i] || (this.positions[i] != null && this.positions[i].equals(pair.positions[i]))){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.equals(obj);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* This file ("ILaserRelayConnectionHandler.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://ellpeck.de/actaddlicense
|
||||||
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||||
|
*
|
||||||
|
* © 2015-2016 Ellpeck
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.ellpeck.actuallyadditions.api.laser;
|
||||||
|
|
||||||
|
import io.netty.util.internal.ConcurrentSet;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the internal laser relay connection handler.
|
||||||
|
* Use ActuallyAdditionsAPI.connectionHandler for calling
|
||||||
|
* This is not supposed to be implemented.
|
||||||
|
*
|
||||||
|
* The network system is built in a way that doesn't need the individual
|
||||||
|
* positions to be Laser Relays, it relies only on BlockPos
|
||||||
|
*/
|
||||||
|
public interface ILaserRelayConnectionHandler{
|
||||||
|
|
||||||
|
ConcurrentSet<ConnectionPair> getConnectionsFor(BlockPos relay, World world);
|
||||||
|
|
||||||
|
void removeRelayFromNetwork(BlockPos relay, World world);
|
||||||
|
|
||||||
|
Network getNetworkFor(BlockPos relay, World world);
|
||||||
|
|
||||||
|
boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, World world);
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* This file ("Network.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://ellpeck.de/actaddlicense
|
||||||
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||||
|
*
|
||||||
|
* © 2015-2016 Ellpeck
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.ellpeck.actuallyadditions.api.laser;
|
||||||
|
|
||||||
|
import io.netty.util.internal.ConcurrentSet;
|
||||||
|
|
||||||
|
public class Network{
|
||||||
|
|
||||||
|
public final ConcurrentSet<ConnectionPair> connections = new ConcurrentSet<ConnectionPair>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return this.connections.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj){
|
||||||
|
if(obj instanceof Network){
|
||||||
|
if(this.connections.equals(((Network)obj).connections)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.equals(obj);
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,10 +31,7 @@ import de.ellpeck.actuallyadditions.mod.items.lens.LensRecipeHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.lens.Lenses;
|
import de.ellpeck.actuallyadditions.mod.items.lens.Lenses;
|
||||||
import de.ellpeck.actuallyadditions.mod.material.InitArmorMaterials;
|
import de.ellpeck.actuallyadditions.mod.material.InitArmorMaterials;
|
||||||
import de.ellpeck.actuallyadditions.mod.material.InitToolMaterials;
|
import de.ellpeck.actuallyadditions.mod.material.InitToolMaterials;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.BannerHelper;
|
import de.ellpeck.actuallyadditions.mod.misc.*;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.DungeonLoot;
|
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.MethodHandler;
|
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
|
|
||||||
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.ore.InitOreDict;
|
import de.ellpeck.actuallyadditions.mod.ore.InitOreDict;
|
||||||
import de.ellpeck.actuallyadditions.mod.proxy.IProxy;
|
import de.ellpeck.actuallyadditions.mod.proxy.IProxy;
|
||||||
|
@ -79,6 +76,7 @@ public class ActuallyAdditions{
|
||||||
ModUtil.LOGGER.info("Starting PreInitialization Phase...");
|
ModUtil.LOGGER.info("Starting PreInitialization Phase...");
|
||||||
|
|
||||||
ActuallyAdditionsAPI.methodHandler = new MethodHandler();
|
ActuallyAdditionsAPI.methodHandler = new MethodHandler();
|
||||||
|
ActuallyAdditionsAPI.connectionHandler = new LaserRelayConnectionHandler();
|
||||||
Lenses.init();
|
Lenses.init();
|
||||||
InitBooklet.preInit();
|
InitBooklet.preInit();
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.data;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.data.PlayerData.PlayerSave;
|
import de.ellpeck.actuallyadditions.mod.data.PlayerData.PlayerSave;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler.Network;
|
import de.ellpeck.actuallyadditions.api.laser.Network;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||||
import io.netty.util.internal.ConcurrentSet;
|
import io.netty.util.internal.ConcurrentSet;
|
||||||
import net.minecraft.nbt.CompressedStreamTools;
|
import net.minecraft.nbt.CompressedStreamTools;
|
||||||
|
@ -27,7 +27,6 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class WorldData{
|
public class WorldData{
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.items;
|
package de.ellpeck.actuallyadditions.mod.items;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||||
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
|
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
||||||
|
@ -59,11 +60,12 @@ 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)){
|
int distanceSq = (int)savedPos.distanceSq(pos);
|
||||||
|
if(ItemPhantomConnector.getStoredWorld(stack) == world && savedTile instanceof TileEntityLaserRelay && ((TileEntityLaserRelay)savedTile).isItem == ((TileEntityLaserRelay)tile).isItem && distanceSq <= TileEntityLaserRelay.MAX_DISTANCE*TileEntityLaserRelay.MAX_DISTANCE && ActuallyAdditionsAPI.connectionHandler.addConnection(savedPos, pos, world)){
|
||||||
ItemPhantomConnector.clearStorage(stack);
|
ItemPhantomConnector.clearStorage(stack);
|
||||||
|
|
||||||
((TileEntityLaserRelay)world.getTileEntity(savedPos)).sendUpdate();
|
((TileEntityLaserRelay)savedTile).sendUpdate();
|
||||||
((TileEntityLaserRelay)world.getTileEntity(pos)).sendUpdate();
|
((TileEntityLaserRelay)tile).sendUpdate();
|
||||||
|
|
||||||
player.addChatComponentMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.connected.desc"));
|
player.addChatComponentMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.connected.desc"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,17 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.misc;
|
package de.ellpeck.actuallyadditions.mod.misc;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.api.laser.ConnectionPair;
|
||||||
|
import de.ellpeck.actuallyadditions.api.laser.ILaserRelayConnectionHandler;
|
||||||
|
import de.ellpeck.actuallyadditions.api.laser.Network;
|
||||||
import de.ellpeck.actuallyadditions.mod.data.WorldData;
|
import de.ellpeck.actuallyadditions.mod.data.WorldData;
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay;
|
|
||||||
import io.netty.util.internal.ConcurrentSet;
|
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;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public final class LaserRelayConnectionHandler{
|
public final class LaserRelayConnectionHandler implements ILaserRelayConnectionHandler{
|
||||||
|
|
||||||
public static NBTTagCompound writeNetworkToNBT(Network network){
|
public static NBTTagCompound writeNetworkToNBT(Network network){
|
||||||
NBTTagList list = new NBTTagList();
|
NBTTagList list = new NBTTagList();
|
||||||
|
@ -42,7 +44,8 @@ public final class LaserRelayConnectionHandler{
|
||||||
/**
|
/**
|
||||||
* Gets all Connections for a Relay
|
* Gets all Connections for a Relay
|
||||||
*/
|
*/
|
||||||
public static ConcurrentSet<ConnectionPair> getConnectionsFor(BlockPos relay, World world){
|
@Override
|
||||||
|
public 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,14 +60,15 @@ public final class LaserRelayConnectionHandler{
|
||||||
/**
|
/**
|
||||||
* Removes a Relay from its Network
|
* Removes a Relay from its Network
|
||||||
*/
|
*/
|
||||||
public static void removeRelayFromNetwork(BlockPos relay, World world){
|
@Override
|
||||||
Network network = getNetworkFor(relay, world);
|
public void removeRelayFromNetwork(BlockPos relay, World world){
|
||||||
|
Network network = this.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)
|
||||||
WorldData.getDataForWorld(world).laserRelayNetworks.remove(network);
|
WorldData.getDataForWorld(world).laserRelayNetworks.remove(network);
|
||||||
for(ConnectionPair pair : network.connections){
|
for(ConnectionPair pair : network.connections){
|
||||||
if(!pair.contains(relay)){
|
if(!pair.contains(relay)){
|
||||||
addConnection(pair.positions[0], pair.positions[1], world);
|
this.addConnection(pair.positions[0], pair.positions[1], world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//System.out.println("Removing a Relay from the Network!");
|
//System.out.println("Removing a Relay from the Network!");
|
||||||
|
@ -74,7 +78,8 @@ public final class LaserRelayConnectionHandler{
|
||||||
/**
|
/**
|
||||||
* Gets a Network for a Relay
|
* Gets a Network for a Relay
|
||||||
*/
|
*/
|
||||||
public static Network getNetworkFor(BlockPos relay, World world){
|
@Override
|
||||||
|
public 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,14 +94,14 @@ public final 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, World world){
|
@Override
|
||||||
int distanceSq = (int)firstRelay.distanceSq(secondRelay);
|
public boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, World world){
|
||||||
if(distanceSq > TileEntityLaserRelay.MAX_DISTANCE*TileEntityLaserRelay.MAX_DISTANCE || firstRelay.equals(secondRelay)){
|
if(firstRelay == null || secondRelay == null || firstRelay == secondRelay || firstRelay.equals(secondRelay)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Network firstNetwork = getNetworkFor(firstRelay, world);
|
Network firstNetwork = this.getNetworkFor(firstRelay, world);
|
||||||
Network secondNetwork = getNetworkFor(secondRelay, world);
|
Network secondNetwork = this.getNetworkFor(secondRelay, world);
|
||||||
|
|
||||||
//No Network exists
|
//No Network exists
|
||||||
if(firstNetwork == null && secondNetwork == null){
|
if(firstNetwork == null && secondNetwork == null){
|
||||||
|
@ -131,7 +136,7 @@ public final 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, World world){
|
private 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);
|
||||||
}
|
}
|
||||||
|
@ -139,85 +144,4 @@ public final class LaserRelayConnectionHandler{
|
||||||
//System.out.println("Merged Two Networks!");
|
//System.out.println("Merged Two Networks!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ConnectionPair{
|
|
||||||
|
|
||||||
public final BlockPos[] positions = new BlockPos[2];
|
|
||||||
|
|
||||||
public ConnectionPair(BlockPos firstRelay, BlockPos secondRelay){
|
|
||||||
this.positions[0] = firstRelay;
|
|
||||||
this.positions[1] = secondRelay;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConnectionPair readFromNBT(NBTTagCompound compound){
|
|
||||||
if(compound != null){
|
|
||||||
BlockPos[] pos = new BlockPos[2];
|
|
||||||
for(int i = 0; i < pos.length; i++){
|
|
||||||
int anX = compound.getInteger("x"+i);
|
|
||||||
int aY = compound.getInteger("y"+i);
|
|
||||||
int aZ = compound.getInteger("z"+i);
|
|
||||||
pos[i] = new BlockPos(anX, aY, aZ);
|
|
||||||
}
|
|
||||||
return new ConnectionPair(pos[0], pos[1]);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean contains(BlockPos relay){
|
|
||||||
for(BlockPos position : this.positions){
|
|
||||||
if(position != null && position.equals(relay)){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString(){
|
|
||||||
return (this.positions[0] == null ? "-" : this.positions[0].toString())+" | "+(this.positions[1] == null ? "-" : this.positions[1].toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NBTTagCompound writeToNBT(){
|
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
|
||||||
for(int i = 0; i < this.positions.length; i++){
|
|
||||||
BlockPos relay = this.positions[i];
|
|
||||||
compound.setInteger("x"+i, relay.getX());
|
|
||||||
compound.setInteger("y"+i, relay.getY());
|
|
||||||
compound.setInteger("z"+i, relay.getZ());
|
|
||||||
}
|
|
||||||
return compound;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj){
|
|
||||||
if(obj instanceof ConnectionPair){
|
|
||||||
ConnectionPair pair = (ConnectionPair)obj;
|
|
||||||
for(int i = 0; i < this.positions.length; i++){
|
|
||||||
if(this.positions[i] == pair.positions[i] || (this.positions[i] != null && this.positions[i].equals(pair.positions[i]))){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.equals(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Network{
|
|
||||||
|
|
||||||
public final ConcurrentSet<ConnectionPair> connections = new ConcurrentSet<ConnectionPair>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString(){
|
|
||||||
return this.connections.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj){
|
|
||||||
if(obj instanceof Network){
|
|
||||||
if(this.connections.equals(((Network)obj).connections)){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.equals(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||||
|
import de.ellpeck.actuallyadditions.api.laser.Network;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -44,7 +46,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
||||||
private List<GenericItemHandlerInfo> getItemHandlerInfos(){
|
private List<GenericItemHandlerInfo> getItemHandlerInfos(){
|
||||||
TileEntityLaserRelayItem relay = this.connectedRelay;
|
TileEntityLaserRelayItem relay = this.connectedRelay;
|
||||||
if(relay != null){
|
if(relay != null){
|
||||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(relay.getPos(), this.worldObj);
|
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(relay.getPos(), this.worldObj);
|
||||||
if(network != null){
|
if(network != null){
|
||||||
return relay.getItemHandlersInNetwork(network);
|
return relay.getItemHandlersInNetwork(network);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,14 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||||
|
import de.ellpeck.actuallyadditions.api.laser.Network;
|
||||||
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
||||||
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
|
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.ItemLaserWrench;
|
import de.ellpeck.actuallyadditions.mod.items.ItemLaserWrench;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.ItemLaserWrench.WrenchMode;
|
import de.ellpeck.actuallyadditions.mod.items.ItemLaserWrench.WrenchMode;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler.ConnectionPair;
|
import de.ellpeck.actuallyadditions.api.laser.ConnectionPair;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||||
import io.netty.util.internal.ConcurrentSet;
|
import io.netty.util.internal.ConcurrentSet;
|
||||||
|
@ -48,13 +50,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);
|
ActuallyAdditionsAPI.connectionHandler.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++){
|
||||||
ConnectionPair pair = ConnectionPair.readFromNBT(list.getCompoundTagAt(i));
|
ConnectionPair pair = ConnectionPair.readFromNBT(list.getCompoundTagAt(i));
|
||||||
LaserRelayConnectionHandler.addConnection(pair.positions[0], pair.positions[1], this.worldObj);
|
ActuallyAdditionsAPI.connectionHandler.addConnection(pair.positions[0], pair.positions[1], this.worldObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +69,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
NBTTagCompound compound = super.getUpdateTag();
|
NBTTagCompound compound = super.getUpdateTag();
|
||||||
NBTTagList list = new NBTTagList();
|
NBTTagList list = new NBTTagList();
|
||||||
|
|
||||||
ConcurrentSet<ConnectionPair> connections = LaserRelayConnectionHandler.getConnectionsFor(this.pos, this.worldObj);
|
ConcurrentSet<ConnectionPair> connections = ActuallyAdditionsAPI.connectionHandler.getConnectionsFor(this.pos, this.worldObj);
|
||||||
if(connections != null && !connections.isEmpty()){
|
if(connections != null && !connections.isEmpty()){
|
||||||
for(ConnectionPair pair : connections){
|
for(ConnectionPair pair : connections){
|
||||||
list.appendTag(pair.writeToNBT());
|
list.appendTag(pair.writeToNBT());
|
||||||
|
@ -104,7 +106,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
if(mode != WrenchMode.NO_PARTICLES){
|
if(mode != WrenchMode.NO_PARTICLES){
|
||||||
ItemStack stack = player.getHeldItemMainhand();
|
ItemStack stack = player.getHeldItemMainhand();
|
||||||
if(mode == WrenchMode.ALWAYS_PARTICLES || (stack != null && stack.getItem() instanceof ItemLaserWrench)){
|
if(mode == WrenchMode.ALWAYS_PARTICLES || (stack != null && stack.getItem() instanceof ItemLaserWrench)){
|
||||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(this.pos, this.worldObj);
|
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.pos, this.worldObj);
|
||||||
if(network != null){
|
if(network != null){
|
||||||
for(ConnectionPair aPair : network.connections){
|
for(ConnectionPair aPair : network.connections){
|
||||||
if(aPair.contains(this.pos) && this.pos.equals(aPair.positions[0])){
|
if(aPair.contains(this.pos) && this.pos.equals(aPair.positions[0])){
|
||||||
|
@ -123,16 +125,16 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
super.invalidate();
|
super.invalidate();
|
||||||
//This is because Minecraft randomly invalidates tiles on world join and then validates them again
|
//This is because Minecraft randomly invalidates tiles on world join and then validates them again
|
||||||
//We need to compensate for this so that connections don't get broken randomly
|
//We need to compensate for this so that connections don't get broken randomly
|
||||||
this.tempConnectionStorage = LaserRelayConnectionHandler.getConnectionsFor(this.pos, this.worldObj);
|
this.tempConnectionStorage = ActuallyAdditionsAPI.connectionHandler.getConnectionsFor(this.pos, this.worldObj);
|
||||||
|
|
||||||
LaserRelayConnectionHandler.removeRelayFromNetwork(this.pos, this.worldObj);
|
ActuallyAdditionsAPI.connectionHandler.removeRelayFromNetwork(this.pos, this.worldObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validate(){
|
public void validate(){
|
||||||
if(this.tempConnectionStorage != null){
|
if(this.tempConnectionStorage != null){
|
||||||
for(ConnectionPair pair : this.tempConnectionStorage){
|
for(ConnectionPair pair : this.tempConnectionStorage){
|
||||||
LaserRelayConnectionHandler.addConnection(pair.positions[0], pair.positions[1], this.worldObj);
|
ActuallyAdditionsAPI.connectionHandler.addConnection(pair.positions[0], pair.positions[1], this.worldObj);
|
||||||
}
|
}
|
||||||
this.tempConnectionStorage = null;
|
this.tempConnectionStorage = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
import cofh.api.energy.IEnergyReceiver;
|
import cofh.api.energy.IEnergyReceiver;
|
||||||
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||||
|
import de.ellpeck.actuallyadditions.api.laser.ConnectionPair;
|
||||||
|
import de.ellpeck.actuallyadditions.api.laser.Network;
|
||||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
||||||
|
@ -57,7 +60,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
|
||||||
public int transmitEnergy(EnumFacing from, int maxTransmit, boolean simulate){
|
public int transmitEnergy(EnumFacing from, 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);
|
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.pos, this.worldObj);
|
||||||
if(network != null){
|
if(network != null){
|
||||||
transmitted = this.transferEnergyToReceiverInNeed(from, network, maxTransmit, simulate);
|
transmitted = this.transferEnergyToReceiverInNeed(from, network, maxTransmit, simulate);
|
||||||
}
|
}
|
||||||
|
@ -85,11 +88,11 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int transferEnergyToReceiverInNeed(EnumFacing from, LaserRelayConnectionHandler.Network network, int maxTransfer, boolean simulate){
|
private int transferEnergyToReceiverInNeed(EnumFacing from, Network network, int maxTransfer, boolean simulate){
|
||||||
int transmitted = 0;
|
int transmitted = 0;
|
||||||
List<BlockPos> alreadyChecked = new ArrayList<BlockPos>();
|
List<BlockPos> alreadyChecked = new ArrayList<BlockPos>();
|
||||||
//Go through all of the connections in the network
|
//Go through all of the connections in the network
|
||||||
for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){
|
for(ConnectionPair pair : network.connections){
|
||||||
//Go through both relays in the connection
|
//Go through both relays in the connection
|
||||||
for(BlockPos relay : pair.positions){
|
for(BlockPos relay : pair.positions){
|
||||||
if(relay != null && !alreadyChecked.contains(relay)){
|
if(relay != null && !alreadyChecked.contains(relay)){
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
import de.ellpeck.actuallyadditions.api.laser.ConnectionPair;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler.Network;
|
import de.ellpeck.actuallyadditions.api.laser.Network;
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer.GenericItemHandlerInfo;
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer.GenericItemHandlerInfo;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -59,7 +59,7 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
||||||
|
|
||||||
public List<GenericItemHandlerInfo> getItemHandlersInNetwork(Network network){
|
public List<GenericItemHandlerInfo> getItemHandlersInNetwork(Network network){
|
||||||
List<GenericItemHandlerInfo> handlers = new ArrayList<GenericItemHandlerInfo>();
|
List<GenericItemHandlerInfo> handlers = new ArrayList<GenericItemHandlerInfo>();
|
||||||
for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){
|
for(ConnectionPair pair : network.connections){
|
||||||
for(BlockPos relay : pair.positions){
|
for(BlockPos relay : pair.positions){
|
||||||
if(relay != null){
|
if(relay != null){
|
||||||
TileEntity aRelayTile = this.worldObj.getTileEntity(relay);
|
TileEntity aRelayTile = this.worldObj.getTileEntity(relay);
|
||||||
|
|
Loading…
Reference in a new issue