2016-05-16 22:52:27 +02:00
|
|
|
/*
|
|
|
|
* This file ("TileEntityLaserRelayItem.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
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2016-05-16 22:52:27 +02:00
|
|
|
*/
|
|
|
|
|
2016-05-14 17:50:10 +02:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
|
|
|
|
|
|
|
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
2016-06-11 15:33:44 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler.Network;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer.GenericItemHandlerInfo;
|
2016-05-14 17:50:10 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraftforge.items.CapabilityItemHandler;
|
|
|
|
import net.minecraftforge.items.IItemHandler;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
|
|
|
|
2016-06-11 15:33:44 +02:00
|
|
|
public List<IItemHandler> handlersAround = new ArrayList<IItemHandler>();
|
|
|
|
|
2016-05-14 17:50:10 +02:00
|
|
|
public TileEntityLaserRelayItem(String name){
|
|
|
|
super(name, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public TileEntityLaserRelayItem(){
|
|
|
|
this("laserRelayItem");
|
|
|
|
}
|
|
|
|
|
2016-06-06 17:59:01 +02:00
|
|
|
public boolean isWhitelisted(ItemStack stack, boolean output){
|
2016-05-14 17:50:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-11 15:33:44 +02:00
|
|
|
@Override
|
|
|
|
public void saveAllHandlersAround(){
|
|
|
|
this.handlersAround.clear();
|
|
|
|
|
2016-05-14 17:50:10 +02:00
|
|
|
for(int i = 0; i <= 5; i++){
|
|
|
|
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i);
|
|
|
|
BlockPos pos = WorldUtil.getCoordsFromSide(side, this.getPos(), 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){
|
2016-06-11 15:33:44 +02:00
|
|
|
this.handlersAround.add(handler);
|
2016-05-14 17:50:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-11 15:33:44 +02:00
|
|
|
public List<GenericItemHandlerInfo> getItemHandlersInNetwork(Network network){
|
|
|
|
List<GenericItemHandlerInfo> handlers = new ArrayList<GenericItemHandlerInfo>();
|
2016-05-14 17:50:10 +02:00
|
|
|
for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){
|
2016-06-05 14:33:53 +02:00
|
|
|
for(BlockPos relay : pair.positions){
|
2016-05-14 17:50:10 +02:00
|
|
|
if(relay != null){
|
|
|
|
TileEntity aRelayTile = this.worldObj.getTileEntity(relay);
|
2016-06-11 15:33:44 +02:00
|
|
|
if(aRelayTile instanceof TileEntityLaserRelayItem){
|
|
|
|
TileEntityLaserRelayItem relayTile = (TileEntityLaserRelayItem)aRelayTile;
|
|
|
|
if(!GenericItemHandlerInfo.containsTile(handlers, relayTile)){
|
|
|
|
GenericItemHandlerInfo info = new GenericItemHandlerInfo(relayTile);
|
2016-05-14 17:50:10 +02:00
|
|
|
|
2016-06-11 15:33:44 +02:00
|
|
|
List<IItemHandler> handlersAroundTile = relayTile.handlersAround;
|
2016-05-14 17:50:10 +02:00
|
|
|
for(IItemHandler handler : handlersAroundTile){
|
2016-06-11 15:33:44 +02:00
|
|
|
if(!GenericItemHandlerInfo.containsHandler(handlers, handler)){
|
2016-05-14 17:50:10 +02:00
|
|
|
info.handlers.add(handler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handlers.add(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return handlers;
|
|
|
|
}
|
|
|
|
}
|