2014-07-26 03:16:00 +02:00
|
|
|
package appeng.fmp;
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.Vec3;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
import appeng.api.parts.IFacadeContainer;
|
2014-08-27 07:57:37 +02:00
|
|
|
import appeng.api.parts.IFacadePart;
|
2014-07-26 03:16:00 +02:00
|
|
|
import appeng.api.parts.IPart;
|
|
|
|
import appeng.api.parts.IPartHost;
|
|
|
|
import appeng.api.parts.LayerFlags;
|
|
|
|
import appeng.api.parts.SelectedPart;
|
|
|
|
import appeng.api.util.AEColor;
|
|
|
|
import appeng.api.util.DimensionalCoord;
|
|
|
|
import appeng.facade.FacadeContainer;
|
2014-08-27 07:57:37 +02:00
|
|
|
import appeng.parts.CableBusStorage;
|
2014-07-26 03:16:00 +02:00
|
|
|
import appeng.util.Platform;
|
|
|
|
import codechicken.lib.vec.BlockCoord;
|
2014-07-26 23:34:26 +02:00
|
|
|
import codechicken.multipart.TMultiPart;
|
2014-07-26 03:16:00 +02:00
|
|
|
import codechicken.multipart.TileMultipart;
|
|
|
|
|
|
|
|
public class FMPPlacementHelper implements IPartHost
|
|
|
|
{
|
|
|
|
|
2014-08-27 07:57:37 +02:00
|
|
|
static class NullStorage extends CableBusStorage
|
|
|
|
{
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IFacadePart getFacade(int x)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFacade(int x, IFacadePart facade)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-28 00:50:06 +02:00
|
|
|
}
|
2014-08-27 07:57:37 +02:00
|
|
|
|
|
|
|
final private static CableBusStorage nullStorage = new NullStorage();
|
|
|
|
|
2014-07-26 03:16:00 +02:00
|
|
|
private boolean hasPart = false;
|
|
|
|
private TileMultipart myMP;
|
|
|
|
private CableBusPart myPart;
|
|
|
|
|
|
|
|
private CableBusPart getPart()
|
|
|
|
{
|
2014-08-08 08:42:23 +02:00
|
|
|
scala.collection.Iterator<TMultiPart> i = myMP.partList().iterator();
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
TMultiPart p = i.next();
|
|
|
|
if ( p instanceof CableBusPart )
|
|
|
|
myPart = (CableBusPart) p;
|
|
|
|
}
|
|
|
|
|
2014-07-26 03:16:00 +02:00
|
|
|
if ( myPart == null )
|
|
|
|
myPart = (CableBusPart) PartRegistry.CableBusPart.construct( 0 );
|
|
|
|
|
|
|
|
BlockCoord loc = new BlockCoord( myMP.xCoord, myMP.yCoord, myMP.zCoord );
|
|
|
|
|
|
|
|
if ( myMP.canAddPart( myPart ) && Platform.isServer() )
|
|
|
|
{
|
2014-08-08 08:42:23 +02:00
|
|
|
myMP = TileMultipart.addPart( myMP.getWorldObj(), loc, myPart );
|
2014-07-26 03:16:00 +02:00
|
|
|
hasPart = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return myPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removePart()
|
|
|
|
{
|
|
|
|
if ( myPart.isEmpty() )
|
|
|
|
{
|
2014-07-26 23:34:26 +02:00
|
|
|
scala.collection.Iterator<TMultiPart> i = myMP.partList().iterator();
|
|
|
|
while (i.hasNext())
|
2014-07-26 03:16:00 +02:00
|
|
|
{
|
2014-07-26 23:34:26 +02:00
|
|
|
TMultiPart p = i.next();
|
|
|
|
if ( p == myPart )
|
|
|
|
{
|
2014-08-08 08:42:23 +02:00
|
|
|
myMP = myMP.remPart( myPart );
|
2014-07-26 23:34:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
2014-07-26 23:34:26 +02:00
|
|
|
hasPart = false;
|
2014-07-26 03:16:00 +02:00
|
|
|
myPart = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public FMPPlacementHelper(TileMultipart mp) {
|
|
|
|
myMP = mp;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IFacadeContainer getFacadeContainer()
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
2014-08-27 07:57:37 +02:00
|
|
|
return new FacadeContainer( nullStorage );
|
2014-07-26 03:16:00 +02:00
|
|
|
return myPart.getFacadeContainer();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canAddPart(ItemStack part, ForgeDirection side)
|
|
|
|
{
|
|
|
|
CableBusPart myPart = getPart();
|
|
|
|
|
|
|
|
boolean returnValue = hasPart && myPart.canAddPart( part, side );
|
|
|
|
|
|
|
|
removePart();
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ForgeDirection addPart(ItemStack is, ForgeDirection side, EntityPlayer owner)
|
|
|
|
{
|
|
|
|
CableBusPart myPart = getPart();
|
|
|
|
|
|
|
|
ForgeDirection returnValue = hasPart ? myPart.addPart( is, side, owner ) : null;
|
|
|
|
|
|
|
|
removePart();
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IPart getPart(ForgeDirection side)
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return null;
|
|
|
|
return myPart.getPart( side );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removePart(ForgeDirection side, boolean suppressUpdate)
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return;
|
|
|
|
myPart.removePart( side, suppressUpdate );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markForUpdate()
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return;
|
|
|
|
myPart.markForUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DimensionalCoord getLocation()
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return new DimensionalCoord( myMP );
|
|
|
|
return myPart.getLocation();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TileEntity getTile()
|
|
|
|
{
|
|
|
|
return myMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AEColor getColor()
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return AEColor.Transparent;
|
|
|
|
return myPart.getColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clearContainer()
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return;
|
|
|
|
myPart.clearContainer();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isBlocked(ForgeDirection side)
|
|
|
|
{
|
|
|
|
getPart();
|
|
|
|
|
|
|
|
boolean returnValue = myPart.isBlocked( side );
|
|
|
|
|
|
|
|
removePart();
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SelectedPart selectPart(Vec3 pos)
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return new SelectedPart();
|
|
|
|
return myPart.selectPart( pos );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markForSave()
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return;
|
|
|
|
myPart.markForSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void partChanged()
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return;
|
|
|
|
myPart.partChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasRedstone(ForgeDirection side)
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return false;
|
|
|
|
return myPart.hasRedstone( side );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEmpty()
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return true;
|
|
|
|
return myPart.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Set<LayerFlags> getLayerFlags()
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return EnumSet.noneOf( LayerFlags.class );
|
|
|
|
return myPart.getLayerFlags();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void cleanup()
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return;
|
|
|
|
myPart.cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyNeighbors()
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return;
|
|
|
|
myPart.notifyNeighbors();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isInWorld()
|
|
|
|
{
|
|
|
|
if ( myPart == null )
|
|
|
|
return myMP.getWorldObj() != null;
|
|
|
|
return myPart.isInWorld();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|