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-09-24 02:26:27 +02:00
|
|
|
package appeng.parts;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
2015-05-27 16:54:04 +02:00
|
|
|
import com.google.common.base.Preconditions;
|
|
|
|
|
2014-12-29 21:59:05 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
|
|
|
import net.minecraft.crash.CrashReportCategory;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.IIcon;
|
|
|
|
import net.minecraft.util.Vec3;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.config.Upgrades;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.definitions.IDefinitions;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.implementations.IUpgradeableHost;
|
|
|
|
import appeng.api.implementations.items.IMemoryCard;
|
|
|
|
import appeng.api.implementations.items.MemoryCardMessages;
|
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.networking.security.IActionHost;
|
|
|
|
import appeng.api.parts.BusSupport;
|
|
|
|
import appeng.api.parts.IPart;
|
|
|
|
import appeng.api.parts.IPartCollisionHelper;
|
|
|
|
import appeng.api.parts.IPartHost;
|
|
|
|
import appeng.api.parts.IPartRenderHelper;
|
|
|
|
import appeng.api.parts.ISimplifiedBundle;
|
|
|
|
import appeng.api.parts.PartItemStack;
|
|
|
|
import appeng.api.util.AECableType;
|
|
|
|
import appeng.api.util.AEColor;
|
|
|
|
import appeng.api.util.DimensionalCoord;
|
|
|
|
import appeng.api.util.IConfigManager;
|
|
|
|
import appeng.helpers.ICustomNameObject;
|
|
|
|
import appeng.helpers.IPriorityHost;
|
|
|
|
import appeng.me.helpers.AENetworkProxy;
|
|
|
|
import appeng.me.helpers.IGridProxyable;
|
|
|
|
import appeng.parts.networking.PartCable;
|
|
|
|
import appeng.tile.inventory.AppEngInternalAEInventory;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
import appeng.util.SettingsFrom;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost, IUpgradeableHost, ICustomNameObject
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
private final AENetworkProxy proxy;
|
|
|
|
private final ItemStack is;
|
|
|
|
private ISimplifiedBundle renderCache = null;
|
|
|
|
private TileEntity tile = null;
|
|
|
|
private IPartHost host = null;
|
|
|
|
private ForgeDirection side = null;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public AEBasePart( final ItemStack is )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-05-27 16:54:04 +02:00
|
|
|
Preconditions.checkNotNull( is );
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
this.is = is;
|
2014-12-29 15:13:47 +01:00
|
|
|
this.proxy = new AENetworkProxy( this, "part", is, this instanceof PartCable );
|
|
|
|
this.proxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public IPartHost getHost()
|
|
|
|
{
|
|
|
|
return this.host;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public IGridNode getGridNode( final ForgeDirection dir )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
return this.proxy.getNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public AECableType getCableConnectionType( final ForgeDirection dir )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
return AECableType.GLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void securityBreak()
|
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
if( this.getItemStack().stackSize > 0 )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final List<ItemStack> items = new ArrayList<ItemStack>();
|
2015-10-08 15:42:42 +02:00
|
|
|
items.add( this.getItemStack().copy() );
|
|
|
|
this.host.removePart( this.getSide(), false );
|
2015-04-03 08:54:31 +02:00
|
|
|
Platform.spawnDrops( this.tile.getWorldObj(), this.tile.xCoord, this.tile.yCoord, this.tile.zCoord, items );
|
2015-10-08 15:42:42 +02:00
|
|
|
this.getItemStack().stackSize = 0;
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected AEColor getColor()
|
|
|
|
{
|
|
|
|
if( this.host == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return AEColor.Transparent;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.host.getColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void getBoxes( final IPartCollisionHelper bch )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public int getInstalledUpgrades( final Upgrades u )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
return 0;
|
2015-05-27 16:54:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
@SideOnly( Side.CLIENT )
|
2015-09-25 23:10:56 +02:00
|
|
|
public void renderInventory( final IPartRenderHelper rh, final RenderBlocks renderer )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
rh.setBounds( 1, 1, 1, 15, 15, 15 );
|
|
|
|
rh.renderInventoryBox( renderer );
|
|
|
|
|
|
|
|
rh.setBounds( 1, 1, 1, 15, 15, 15 );
|
|
|
|
rh.renderInventoryBox( renderer );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public TileEntity getTile()
|
|
|
|
{
|
|
|
|
return this.tile;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AENetworkProxy getProxy()
|
|
|
|
{
|
|
|
|
return this.proxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DimensionalCoord getLocation()
|
|
|
|
{
|
|
|
|
return new DimensionalCoord( this.tile );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void gridChanged()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGridNode getActionableNode()
|
|
|
|
{
|
|
|
|
return this.proxy.getNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void saveChanges()
|
|
|
|
{
|
|
|
|
this.host.markForSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getCustomName()
|
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getItemStack().getDisplayName();
|
2015-05-27 16:54:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
@SideOnly( Side.CLIENT )
|
2015-09-25 23:10:56 +02:00
|
|
|
public void renderStatic( final int x, final int y, final int z, final IPartRenderHelper rh, final RenderBlocks renderer )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
rh.setBounds( 1, 1, 1, 15, 15, 15 );
|
|
|
|
rh.renderBlock( x, y, z, renderer );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean hasCustomName()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return this.getItemStack().hasDisplayName();
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public void addEntityCrashInfo( final CrashReportCategory crashreportcategory )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
crashreportcategory.addCrashSection( "Part Side", this.getSide() );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
@SideOnly( Side.CLIENT )
|
2015-09-25 23:10:56 +02:00
|
|
|
public void renderDynamic( final double x, final double y, final double z, final IPartRenderHelper rh, final RenderBlocks renderer )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public ItemStack getItemStack( final PartItemStack type )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
if( type == PartItemStack.Network )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final ItemStack copy = this.is.copy();
|
2014-09-24 02:26:27 +02:00
|
|
|
copy.setTagCompound( null );
|
|
|
|
return copy;
|
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.is;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isSolid()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNeighborChanged()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canConnectRedstone()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void readFromNBT( final NBTTagCompound data )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.proxy.readFromNBT( data );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void writeToNBT( final NBTTagCompound data )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.proxy.writeToNBT( data );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int isProvidingStrongPower()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int isProvidingWeakPower()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void writeToStream( final ByteBuf data ) throws IOException
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean readFromStream( final ByteBuf data ) throws IOException
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGridNode getGridNode()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.proxy.getNode();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void onEntityCollision( final Entity entity )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removeFromWorld()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.proxy.invalidate();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addToWorld()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.proxy.onReady();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void setPartHostInfo( final ForgeDirection side, final IPartHost host, final TileEntity tile )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setSide( side );
|
2014-09-24 02:26:27 +02:00
|
|
|
this.tile = tile;
|
|
|
|
this.host = host;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGridNode getExternalFacingNode()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
@SideOnly( Side.CLIENT )
|
2015-09-25 23:10:56 +02:00
|
|
|
public void randomDisplayTick( final World world, final int x, final int y, final int z, final Random r )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getLightLevel()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void getDrops( final List<ItemStack> drops, final boolean wrenched )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int cableConnectionRenderTo()
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean isLadder( final EntityLivingBase entity )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IConfigManager getConfigManager()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public IInventory getInventoryByName( final String name )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* depending on the from, different settings will be accepted, don't call this with null
|
2015-02-03 12:04:13 +01:00
|
|
|
*
|
2015-05-27 16:54:04 +02:00
|
|
|
* @param from source of settings
|
2014-09-27 23:17:47 +02:00
|
|
|
* @param compound compound of source
|
2014-09-24 02:26:27 +02:00
|
|
|
*/
|
2015-10-08 15:42:42 +02:00
|
|
|
private void uploadSettings( final SettingsFrom from, final NBTTagCompound compound )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( compound != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final IConfigManager cm = this.getConfigManager();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( cm != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
cm.readFromNBT( compound );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this instanceof IPriorityHost )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final IPriorityHost pHost = (IPriorityHost) this;
|
2014-09-24 02:26:27 +02:00
|
|
|
pHost.setPriority( compound.getInteger( "priority" ) );
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final IInventory inv = this.getInventoryByName( "config" );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( inv instanceof AppEngInternalAEInventory )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final AppEngInternalAEInventory target = (AppEngInternalAEInventory) inv;
|
|
|
|
final AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSizeInventory() );
|
2014-09-28 20:55:09 +02:00
|
|
|
tmp.readFromNBT( compound, "config" );
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < tmp.getSizeInventory(); x++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-28 20:55:09 +02:00
|
|
|
target.setInventorySlotContents( x, tmp.getStackInSlot( x ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* null means nothing to store...
|
2015-02-03 12:04:13 +01:00
|
|
|
*
|
2014-09-27 23:17:47 +02:00
|
|
|
* @param from source of settings
|
2015-04-03 08:54:31 +02:00
|
|
|
*
|
2014-09-27 23:17:47 +02:00
|
|
|
* @return compound of source
|
2014-09-24 02:26:27 +02:00
|
|
|
*/
|
2015-10-08 15:42:42 +02:00
|
|
|
private NBTTagCompound downloadSettings( final SettingsFrom from )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final NBTTagCompound output = new NBTTagCompound();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final IConfigManager cm = this.getConfigManager();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( cm != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-28 20:55:09 +02:00
|
|
|
cm.writeToNBT( output );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this instanceof IPriorityHost )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final IPriorityHost pHost = (IPriorityHost) this;
|
2014-09-24 02:26:27 +02:00
|
|
|
output.setInteger( "priority", pHost.getPriority() );
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final IInventory inv = this.getInventoryByName( "config" );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( inv instanceof AppEngInternalAEInventory )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
( (AppEngInternalAEInventory) inv ).writeToNBT( output, "config" );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return output.hasNoTags() ? null : output;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean useStandardMemoryCard()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
private boolean useMemoryCard( final EntityPlayer player )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final ItemStack memCardIS = player.inventory.getCurrentItem();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( memCardIS != null && this.useStandardMemoryCard() && memCardIS.getItem() instanceof IMemoryCard )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final IMemoryCard memoryCard = (IMemoryCard) memCardIS.getItem();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
ItemStack is = this.getItemStack( PartItemStack.Network );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
// Blocks and parts share the same soul!
|
2015-01-03 02:53:14 +01:00
|
|
|
final IDefinitions definitions = AEApi.instance().definitions();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( definitions.parts().iface().isSameAs( is ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final ItemStack iface : definitions.blocks().iface().maybeStack( 1 ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
is = iface;
|
|
|
|
}
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final String name = is.getUnlocalizedName();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( player.isSneaking() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final NBTTagCompound data = this.downloadSettings( SettingsFrom.MEMORY_CARD );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( data != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
memoryCard.setMemoryCardContents( memCardIS, name, data );
|
|
|
|
memoryCard.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final String storedName = memoryCard.getSettingsName( memCardIS );
|
|
|
|
final NBTTagCompound data = memoryCard.getData( memCardIS );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( name.equals( storedName ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.uploadSettings( SettingsFrom.MEMORY_CARD, data );
|
2014-09-28 11:47:17 +02:00
|
|
|
memoryCard.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
memoryCard.notifyUser( player, MemoryCardMessages.INVALID_MACHINE );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public final boolean onActivate( final EntityPlayer player, final Vec3 pos )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.useMemoryCard( player ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.onPartActivate( player, pos );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public final boolean onShiftActivate( final EntityPlayer player, final Vec3 pos )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.useMemoryCard( player ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.onPartShiftActivate( player, pos );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean onPartActivate( final EntityPlayer player, final Vec3 pos )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean onPartShiftActivate( final EntityPlayer player, final Vec3 pos )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void onPlacement( final EntityPlayer player, final ItemStack held, final ForgeDirection side )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.proxy.setOwner( player );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean canBePlacedOn( final BusSupport what )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return what == BusSupport.CABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean requireDynamicRender()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
@SideOnly( Side.CLIENT )
|
2014-09-24 02:26:27 +02:00
|
|
|
public IIcon getBreakingTexture()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2015-10-08 15:42:42 +02:00
|
|
|
|
|
|
|
public ForgeDirection getSide()
|
|
|
|
{
|
|
|
|
return this.side;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setSide( final ForgeDirection side )
|
|
|
|
{
|
|
|
|
this.side = side;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack getItemStack()
|
|
|
|
{
|
|
|
|
return this.is;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ISimplifiedBundle getRenderCache()
|
|
|
|
{
|
|
|
|
return this.renderCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setRenderCache( final ISimplifiedBundle renderCache )
|
|
|
|
{
|
|
|
|
this.renderCache = renderCache;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|