2015-10-18 19:21:32 +02:00
|
|
|
/*
|
|
|
|
* This file ("TileEntityLaserRelay.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
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-10-18 19:21:32 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 2016 Ellpeck
|
2015-10-18 19:21:32 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-10-18 19:21:32 +02:00
|
|
|
|
|
|
|
import cofh.api.energy.IEnergyReceiver;
|
2016-01-23 11:02:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.network.PacketParticle;
|
2016-05-10 22:19:15 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
2016-05-09 19:05:20 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer.GenericItemHandlerInfo;
|
2016-01-08 13:31:58 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
|
2016-05-10 22:19:15 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
2015-10-29 17:36:30 +01:00
|
|
|
import io.netty.util.internal.ConcurrentSet;
|
2016-05-10 22:19:15 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-10-18 19:21:32 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-10-29 17:36:30 +01:00
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2016-05-08 21:09:58 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-01-07 23:42:42 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-05-10 22:19:15 +02:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
|
|
|
import net.minecraft.util.text.TextComponentString;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2016-05-08 21:09:58 +02:00
|
|
|
import net.minecraftforge.items.CapabilityItemHandler;
|
|
|
|
import net.minecraftforge.items.IItemHandler;
|
2015-10-18 19:21:32 +02:00
|
|
|
|
2016-05-08 21:09:58 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public abstract class TileEntityLaserRelay extends TileEntityBase{
|
2015-10-18 19:21:32 +02:00
|
|
|
|
2015-11-28 19:02:01 +01:00
|
|
|
public static final int MAX_DISTANCE = 15;
|
2015-12-16 20:40:52 +01:00
|
|
|
private static final float[] COLOR = new float[]{1F, 0F, 0F};
|
2016-05-08 21:09:58 +02:00
|
|
|
private static final float[] COLOR_ITEM = new float[]{139F/255F, 94F/255F, 1F};
|
|
|
|
|
|
|
|
public boolean isItem;
|
2015-11-28 19:02:01 +01:00
|
|
|
|
2016-05-08 21:09:58 +02:00
|
|
|
public TileEntityLaserRelay(String name, boolean isItem){
|
|
|
|
super(name);
|
|
|
|
this.isItem = isItem;
|
2016-05-06 23:23:29 +02:00
|
|
|
}
|
|
|
|
|
2015-10-23 16:54:33 +02:00
|
|
|
@Override
|
2016-02-01 17:49:55 +01:00
|
|
|
public void receiveSyncCompound(NBTTagCompound compound){
|
|
|
|
BlockPos thisPos = this.pos;
|
|
|
|
if(compound != null){
|
|
|
|
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(thisPos);
|
2015-10-27 23:09:23 +01:00
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
NBTTagList list = compound.getTagList("Connections", 10);
|
|
|
|
for(int i = 0; i < list.tagCount(); i++){
|
|
|
|
LaserRelayConnectionHandler.ConnectionPair pair = LaserRelayConnectionHandler.ConnectionPair.readFromNBT(list.getCompoundTagAt(i));
|
|
|
|
LaserRelayConnectionHandler.getInstance().addConnection(pair.firstRelay, pair.secondRelay);
|
2015-10-26 22:28:49 +01:00
|
|
|
}
|
|
|
|
}
|
2016-02-01 17:49:55 +01:00
|
|
|
else{
|
|
|
|
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(thisPos);
|
|
|
|
}
|
2016-05-10 22:19:15 +02:00
|
|
|
|
|
|
|
super.receiveSyncCompound(compound);
|
2015-10-23 16:54:33 +02:00
|
|
|
}
|
|
|
|
|
2015-10-18 19:21:32 +02:00
|
|
|
@Override
|
2016-01-17 20:46:51 +01:00
|
|
|
public NBTTagCompound getSyncCompound(){
|
2016-05-10 22:19:15 +02:00
|
|
|
NBTTagCompound compound = super.getSyncCompound();
|
2015-10-18 19:21:32 +02:00
|
|
|
|
2016-01-08 13:31:58 +01:00
|
|
|
BlockPos thisPos = this.pos;
|
2015-10-29 17:36:30 +01:00
|
|
|
ConcurrentSet<LaserRelayConnectionHandler.ConnectionPair> connections = LaserRelayConnectionHandler.getInstance().getConnectionsFor(thisPos);
|
2015-10-21 00:22:50 +02:00
|
|
|
|
|
|
|
if(connections != null){
|
2015-10-29 17:36:30 +01:00
|
|
|
NBTTagList list = new NBTTagList();
|
|
|
|
for(LaserRelayConnectionHandler.ConnectionPair pair : connections){
|
|
|
|
list.appendTag(pair.writeToNBT());
|
2015-10-21 00:22:50 +02:00
|
|
|
}
|
2015-10-29 17:36:30 +01:00
|
|
|
compound.setTag("Connections", list);
|
2015-10-21 00:22:50 +02:00
|
|
|
}
|
2016-05-10 22:19:15 +02:00
|
|
|
return compound;
|
2015-10-18 19:21:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-02-01 17:49:55 +01:00
|
|
|
public void updateEntity(){
|
|
|
|
super.updateEntity();
|
|
|
|
if(this.worldObj.isRemote){
|
|
|
|
this.renderParticles();
|
|
|
|
}
|
|
|
|
}
|
2015-10-21 00:22:50 +02:00
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void renderParticles(){
|
2016-05-01 22:30:54 +02:00
|
|
|
if(Util.RANDOM.nextInt(ConfigValues.lessParticles ? 8 : 3) == 0){
|
2016-02-01 17:49:55 +01:00
|
|
|
BlockPos thisPos = this.pos;
|
|
|
|
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getInstance().getNetworkFor(thisPos);
|
|
|
|
if(network != null){
|
|
|
|
for(LaserRelayConnectionHandler.ConnectionPair aPair : network.connections){
|
|
|
|
if(aPair.contains(thisPos) && PosUtil.areSamePos(thisPos, aPair.firstRelay)){
|
2016-05-08 21:09:58 +02:00
|
|
|
PacketParticle.renderParticlesFromAToB(aPair.firstRelay.getX(), aPair.firstRelay.getY(), aPair.firstRelay.getZ(), aPair.secondRelay.getX(), aPair.secondRelay.getY(), aPair.secondRelay.getZ(), ConfigValues.lessParticles ? 2 : Util.RANDOM.nextInt(6)+1, 0.6F, this.isItem ? COLOR_ITEM : COLOR, 1F);
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
}
|
2015-10-31 14:42:51 +01:00
|
|
|
}
|
2015-10-21 00:22:50 +02:00
|
|
|
}
|
2015-10-18 19:21:32 +02:00
|
|
|
}
|
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@Override
|
|
|
|
public void invalidate(){
|
|
|
|
super.invalidate();
|
2016-01-08 13:31:58 +01:00
|
|
|
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(this.pos);
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
2016-05-08 21:09:58 +02:00
|
|
|
public static class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
2015-10-18 19:21:32 +02:00
|
|
|
|
2016-05-10 22:19:15 +02:00
|
|
|
public TileEntityLaserRelayItem(String name){
|
|
|
|
super(name, true);
|
|
|
|
}
|
|
|
|
|
2016-05-08 21:09:58 +02:00
|
|
|
public TileEntityLaserRelayItem(){
|
2016-05-10 22:19:15 +02:00
|
|
|
this("laserRelayItem");
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isWhitelisted(ItemStack stack){
|
|
|
|
return true;
|
2016-05-08 21:09:58 +02:00
|
|
|
}
|
2015-10-18 19:21:32 +02:00
|
|
|
|
2016-05-09 19:05:20 +02:00
|
|
|
public List<GenericItemHandlerInfo> getItemHandlersInNetwork(LaserRelayConnectionHandler.Network network){
|
|
|
|
List<GenericItemHandlerInfo> handlers = new ArrayList<GenericItemHandlerInfo>();
|
2016-05-08 21:09:58 +02:00
|
|
|
for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){
|
|
|
|
BlockPos[] relays = new BlockPos[]{pair.firstRelay, pair.secondRelay};
|
|
|
|
for(BlockPos relay : relays){
|
|
|
|
if(relay != null){
|
2016-05-09 19:05:20 +02:00
|
|
|
TileEntity aRelayTile = this.worldObj.getTileEntity(relay);
|
|
|
|
if(aRelayTile instanceof TileEntityLaserRelayItem){
|
|
|
|
TileEntityLaserRelayItem relayTile = (TileEntityLaserRelayItem)aRelayTile;
|
|
|
|
if(!GenericItemHandlerInfo.containsTile(handlers, relayTile)){
|
|
|
|
GenericItemHandlerInfo info = new GenericItemHandlerInfo(relayTile);
|
|
|
|
for(int i = 0; i <= 5; i++){
|
|
|
|
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i);
|
|
|
|
BlockPos pos = WorldUtil.getCoordsFromSide(side, relay, 0);
|
|
|
|
TileEntity tile = this.worldObj.getTileEntity(pos);
|
|
|
|
if(tile != null && !(tile instanceof TileEntityItemViewer)){
|
|
|
|
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite());
|
|
|
|
if(handler != null && !GenericItemHandlerInfo.containsHandler(handlers, handler)){
|
|
|
|
info.handlers.add(handler);
|
|
|
|
}
|
|
|
|
}
|
2016-05-08 21:09:58 +02:00
|
|
|
}
|
2016-05-09 19:05:20 +02:00
|
|
|
handlers.add(info);
|
2016-05-08 21:09:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return handlers;
|
|
|
|
}
|
2015-10-18 19:21:32 +02:00
|
|
|
}
|
|
|
|
|
2016-05-10 22:19:15 +02:00
|
|
|
public static class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem implements IButtonReactor{
|
|
|
|
|
|
|
|
private ItemStack[] slots = new ItemStack[24];
|
|
|
|
|
|
|
|
public IInventory filterInventory;
|
|
|
|
|
|
|
|
public boolean isLeftWhitelist;
|
|
|
|
public boolean isRightWhitelist;
|
|
|
|
|
|
|
|
private boolean lastLeftWhitelist;
|
|
|
|
private boolean lastRightWhitelist;
|
|
|
|
|
|
|
|
public TileEntityLaserRelayItemWhitelist(){
|
|
|
|
super("laserRelayItemWhitelist");
|
|
|
|
|
|
|
|
this.filterInventory = new IInventory(){
|
|
|
|
|
|
|
|
private TileEntityLaserRelayItemWhitelist tile;
|
|
|
|
|
|
|
|
private IInventory setTile(TileEntityLaserRelayItemWhitelist tile){
|
|
|
|
this.tile = tile;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName(){
|
|
|
|
return this.tile.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInventoryStackLimit(){
|
|
|
|
return 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markDirty(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isUseableByPlayer(EntityPlayer player){
|
|
|
|
return this.tile.canPlayerUse(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void openInventory(EntityPlayer player){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void closeInventory(EntityPlayer player){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getField(int id){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setField(int id, int value){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getFieldCount(){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clear(){
|
|
|
|
int length = this.tile.slots.length;
|
|
|
|
this.tile.slots = new ItemStack[length];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInventorySlotContents(int i, ItemStack stack){
|
|
|
|
this.tile.slots[i] = stack;
|
|
|
|
this.markDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSizeInventory(){
|
|
|
|
return this.tile.slots.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlot(int i){
|
|
|
|
if(i < this.getSizeInventory()){
|
|
|
|
return this.tile.slots[i];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack decrStackSize(int i, int j){
|
|
|
|
if(this.tile.slots[i] != null){
|
|
|
|
ItemStack stackAt;
|
|
|
|
if(this.tile.slots[i].stackSize <= j){
|
|
|
|
stackAt = this.tile.slots[i];
|
|
|
|
this.tile.slots[i] = null;
|
|
|
|
this.markDirty();
|
|
|
|
return stackAt;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
stackAt = this.tile.slots[i].splitStack(j);
|
|
|
|
if(this.tile.slots[i].stackSize <= 0){
|
|
|
|
this.tile.slots[i] = null;
|
|
|
|
}
|
|
|
|
this.markDirty();
|
|
|
|
return stackAt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack removeStackFromSlot(int index){
|
|
|
|
ItemStack stack = this.tile.slots[index];
|
|
|
|
this.tile.slots[index] = null;
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasCustomName(){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ITextComponent getDisplayName(){
|
|
|
|
return new TextComponentString(StringUtil.localize(this.getName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValidForSlot(int index, ItemStack stack){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}.setTile(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isWhitelisted(ItemStack stack){
|
|
|
|
return this.checkFilter(stack, true, this.isLeftWhitelist) || this.checkFilter(stack, false, this.isRightWhitelist);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean checkFilter(ItemStack stack, boolean left, boolean isWhitelist){
|
|
|
|
int slotStart = left ? 0 : 12;
|
|
|
|
int slotStop = slotStart+12;
|
|
|
|
|
|
|
|
for(int i = slotStart; i < slotStop; i++){
|
|
|
|
if(this.slots[i] != null && this.slots[i].isItemEqual(stack)){
|
|
|
|
return isWhitelist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return !isWhitelist;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, boolean isForSync){
|
|
|
|
super.writeSyncableNBT(compound, isForSync);
|
|
|
|
if(!isForSync){
|
|
|
|
TileEntityInventoryBase.saveSlots(this.slots, compound);
|
|
|
|
}
|
|
|
|
compound.setBoolean("LeftWhitelist", this.isLeftWhitelist);
|
|
|
|
compound.setBoolean("RightWhitelist", this.isRightWhitelist);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){
|
|
|
|
super.readSyncableNBT(compound, isForSync);
|
|
|
|
if(!isForSync){
|
|
|
|
TileEntityInventoryBase.loadSlots(this.slots, compound);
|
|
|
|
}
|
|
|
|
this.isLeftWhitelist = compound.getBoolean("LeftWhitelist");
|
|
|
|
this.isRightWhitelist = compound.getBoolean("RightWhitelist");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onButtonPressed(int buttonID, EntityPlayer player){
|
|
|
|
if(buttonID == 0){
|
|
|
|
this.isLeftWhitelist = !this.isLeftWhitelist;
|
|
|
|
}
|
|
|
|
else if(buttonID == 1){
|
|
|
|
this.isRightWhitelist = !this.isRightWhitelist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
|
|
|
super.updateEntity();
|
|
|
|
|
2016-05-13 16:58:16 +02:00
|
|
|
if(!this.worldObj.isRemote){
|
|
|
|
if((this.isLeftWhitelist != this.lastLeftWhitelist || this.isRightWhitelist != this.lastRightWhitelist) && this.sendUpdateWithInterval()){
|
|
|
|
this.lastLeftWhitelist = this.isLeftWhitelist;
|
|
|
|
this.lastRightWhitelist = this.isRightWhitelist;
|
|
|
|
}
|
2016-05-10 22:19:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-08 21:09:58 +02:00
|
|
|
public static class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements IEnergyReceiver{
|
|
|
|
|
|
|
|
public TileEntityLaserRelayEnergy(){
|
|
|
|
super("laserRelay", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate){
|
|
|
|
return this.transmitEnergy(WorldUtil.getCoordsFromSide(from, this.pos, 0), maxReceive, simulate);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEnergyStored(EnumFacing from){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxEnergyStored(EnumFacing from){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int transmitEnergy(BlockPos blockFrom, int maxTransmit, boolean simulate){
|
|
|
|
int transmitted = 0;
|
|
|
|
if(maxTransmit > 0){
|
|
|
|
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getInstance().getNetworkFor(this.pos);
|
|
|
|
if(network != null){
|
|
|
|
transmitted = this.transferEnergyToReceiverInNeed(blockFrom, network, Math.min(ConfigIntValues.LASER_RELAY_MAX_TRANSFER.getValue(), maxTransmit), simulate);
|
|
|
|
}
|
2015-10-20 00:22:36 +02:00
|
|
|
}
|
2016-05-08 21:09:58 +02:00
|
|
|
return transmitted;
|
2015-10-20 00:22:36 +02:00
|
|
|
}
|
2015-10-23 16:54:33 +02:00
|
|
|
|
2016-05-08 21:09:58 +02:00
|
|
|
@Override
|
|
|
|
public boolean canConnectEnergy(EnumFacing from){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int transferEnergyToReceiverInNeed(BlockPos energyGottenFrom, LaserRelayConnectionHandler.Network network, int maxTransfer, boolean simulate){
|
|
|
|
int transmitted = 0;
|
|
|
|
List<BlockPos> alreadyChecked = new ArrayList<BlockPos>();
|
|
|
|
//Go through all of the connections in the network
|
|
|
|
for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){
|
|
|
|
BlockPos[] relays = new BlockPos[]{pair.firstRelay, pair.secondRelay};
|
|
|
|
//Go through both relays in the connection
|
|
|
|
for(BlockPos relay : relays){
|
|
|
|
if(relay != null && !alreadyChecked.contains(relay)){
|
|
|
|
alreadyChecked.add(relay);
|
|
|
|
//Get every side of the relay
|
|
|
|
for(int i = 0; i <= 5; i++){
|
|
|
|
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i);
|
|
|
|
//Get the Position at the side
|
|
|
|
BlockPos pos = WorldUtil.getCoordsFromSide(side, relay, 0);
|
|
|
|
if(!PosUtil.areSamePos(pos, energyGottenFrom)){
|
|
|
|
TileEntity tile = this.worldObj.getTileEntity(pos);
|
|
|
|
if(tile instanceof IEnergyReceiver && !(tile instanceof TileEntityLaserRelay)){
|
|
|
|
IEnergyReceiver receiver = (IEnergyReceiver)tile;
|
|
|
|
if(receiver.canConnectEnergy(side.getOpposite())){
|
|
|
|
//Transfer the energy (with the energy loss!)
|
|
|
|
int theoreticalReceived = ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), maxTransfer-transmitted, true);
|
|
|
|
//The amount of energy lost during a transfer
|
|
|
|
int deduct = (int)(theoreticalReceived*((double)ConfigIntValues.LASER_RELAY_LOSS.getValue()/100));
|
|
|
|
|
|
|
|
transmitted += ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), theoreticalReceived-deduct, simulate);
|
|
|
|
transmitted += deduct;
|
|
|
|
|
|
|
|
//If everything that could be transmitted was transmitted
|
|
|
|
if(transmitted >= maxTransfer){
|
|
|
|
return transmitted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return transmitted;
|
|
|
|
}
|
2015-10-23 16:54:33 +02:00
|
|
|
}
|
2015-10-18 19:21:32 +02:00
|
|
|
}
|