2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-07-26 03:16:00 +02:00
|
|
|
package appeng.fmp;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-07-26 03:16:00 +02:00
|
|
|
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;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
|
|
|
import codechicken.lib.vec.BlockCoord;
|
|
|
|
import codechicken.multipart.TMultiPart;
|
|
|
|
import codechicken.multipart.TileMultipart;
|
|
|
|
|
2014-07-26 03:16:00 +02:00
|
|
|
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;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-07-26 03:16:00 +02:00
|
|
|
public class FMPPlacementHelper implements IPartHost
|
|
|
|
{
|
|
|
|
|
2015-04-06 00:35:42 +02:00
|
|
|
private static final CableBusStorage NULL_STORAGE = new NullStorage();
|
2015-04-03 08:54:31 +02:00
|
|
|
private boolean hasPart = false;
|
|
|
|
private TileMultipart myMP;
|
|
|
|
private CableBusPart myPart;
|
2014-08-27 07:57:37 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public FMPPlacementHelper( TileMultipart mp )
|
|
|
|
{
|
|
|
|
this.myMP = mp;
|
|
|
|
}
|
2014-08-27 07:57:37 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public IFacadeContainer getFacadeContainer()
|
|
|
|
{
|
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return new FacadeContainer( NULL_STORAGE );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.myPart.getFacadeContainer();
|
|
|
|
}
|
2014-08-27 07:57:37 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public boolean canAddPart( ItemStack part, ForgeDirection side )
|
|
|
|
{
|
|
|
|
CableBusPart myPart = this.getPart();
|
2014-08-27 07:57:37 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
boolean returnValue = this.hasPart && myPart.canAddPart( part, side );
|
2014-08-27 07:57:37 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
this.removePart();
|
2014-08-27 07:57:37 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
return returnValue;
|
|
|
|
}
|
2014-07-26 03:16:00 +02:00
|
|
|
|
|
|
|
private CableBusPart getPart()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
scala.collection.Iterator<TMultiPart> i = this.myMP.partList().iterator();
|
2015-04-03 08:54:31 +02:00
|
|
|
while( i.hasNext() )
|
2014-08-08 08:42:23 +02:00
|
|
|
{
|
|
|
|
TMultiPart p = i.next();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( p instanceof CableBusPart )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myPart = (CableBusPart) p;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-08 08:42:23 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myPart = (CableBusPart) PartRegistry.CableBusPart.construct( 0 );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-26 03:16:00 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
BlockCoord loc = new BlockCoord( this.myMP.xCoord, this.myMP.yCoord, this.myMP.zCoord );
|
2014-07-26 03:16:00 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myMP.canAddPart( this.myPart ) && Platform.isServer() )
|
2014-07-26 03:16:00 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myMP = TileMultipart.addPart( this.myMP.getWorldObj(), loc, this.myPart );
|
|
|
|
this.hasPart = true;
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.myPart;
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void removePart()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart.isEmpty() )
|
2014-07-26 03:16:00 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
scala.collection.Iterator<TMultiPart> i = this.myMP.partList().iterator();
|
2015-04-03 08:54:31 +02:00
|
|
|
while( i.hasNext() )
|
2014-07-26 03:16:00 +02:00
|
|
|
{
|
2014-07-26 23:34:26 +02:00
|
|
|
TMultiPart p = i.next();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( p == this.myPart )
|
2014-07-26 23:34:26 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myMP = this.myMP.remPart( this.myPart );
|
2014-07-26 23:34:26 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
this.hasPart = false;
|
|
|
|
this.myPart = null;
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public ForgeDirection addPart( ItemStack is, ForgeDirection side, EntityPlayer owner )
|
2014-07-26 03:16:00 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
CableBusPart myPart = this.getPart();
|
2014-07-26 03:16:00 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
ForgeDirection returnValue = this.hasPart ? myPart.addPart( is, side, owner ) : null;
|
2014-07-26 03:16:00 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.removePart();
|
2014-07-26 03:16:00 +02:00
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public IPart getPart( ForgeDirection side )
|
2014-07-26 03:16:00 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-26 03:16:00 +02:00
|
|
|
return null;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.myPart.getPart( side );
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void removePart( ForgeDirection side, boolean suppressUpdate )
|
2014-07-26 03:16:00 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-26 03:16:00 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myPart.removePart( side, suppressUpdate );
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markForUpdate()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-26 03:16:00 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myPart.markForUpdate();
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DimensionalCoord getLocation()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return new DimensionalCoord( this.myMP );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.myPart.getLocation();
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TileEntity getTile()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.myMP;
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AEColor getColor()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-26 03:16:00 +02:00
|
|
|
return AEColor.Transparent;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.myPart.getColor();
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clearContainer()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-26 03:16:00 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myPart.clearContainer();
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean isBlocked( ForgeDirection side )
|
2014-07-26 03:16:00 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.getPart();
|
2014-07-26 03:16:00 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
boolean returnValue = this.myPart.isBlocked( side );
|
2014-07-26 03:16:00 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.removePart();
|
2014-07-26 03:16:00 +02:00
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public SelectedPart selectPart( Vec3 pos )
|
2014-07-26 03:16:00 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-26 03:16:00 +02:00
|
|
|
return new SelectedPart();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.myPart.selectPart( pos );
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markForSave()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-26 03:16:00 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myPart.markForSave();
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void partChanged()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-26 03:16:00 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myPart.partChanged();
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean hasRedstone( ForgeDirection side )
|
2014-07-26 03:16:00 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-26 03:16:00 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.myPart.hasRedstone( side );
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEmpty()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-26 03:16:00 +02:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.myPart.isEmpty();
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Set<LayerFlags> getLayerFlags()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-26 03:16:00 +02:00
|
|
|
return EnumSet.noneOf( LayerFlags.class );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.myPart.getLayerFlags();
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void cleanup()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-26 03:16:00 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myPart.cleanup();
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyNeighbors()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-26 03:16:00 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myPart.notifyNeighbors();
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isInWorld()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myPart == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.myMP.getWorldObj() != null;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.myPart.isInWorld();
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
static class NullStorage extends CableBusStorage
|
|
|
|
{
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IFacadePart getFacade( int x )
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFacade( int x, IFacadePart facade )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2014-07-26 03:16:00 +02:00
|
|
|
}
|