2013-12-27 23:59:59 +01:00
|
|
|
package appeng.parts;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.io.IOException;
|
2014-01-27 05:00:36 +01:00
|
|
|
import java.util.ArrayList;
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
|
|
|
import net.minecraft.entity.Entity;
|
2013-12-28 21:54:05 +01:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-12-30 06:57:08 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.Vec3;
|
|
|
|
import net.minecraft.world.World;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2013-12-30 06:57:08 +01:00
|
|
|
import appeng.api.config.Upgrades;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.IUpgradeableHost;
|
2014-02-20 06:18:49 +01:00
|
|
|
import appeng.api.implementations.items.IMemoryCard;
|
|
|
|
import appeng.api.implementations.items.MemoryCardMessages;
|
|
|
|
import appeng.api.implementations.tiles.ISegmentedInventory;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.IGridNode;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.networking.security.IActionHost;
|
2014-01-30 19:54:09 +01:00
|
|
|
import appeng.api.parts.BusSupport;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.parts.IPart;
|
|
|
|
import appeng.api.parts.IPartCollsionHelper;
|
|
|
|
import appeng.api.parts.IPartHost;
|
|
|
|
import appeng.api.parts.IPartRenderHelper;
|
2014-02-15 07:30:06 +01:00
|
|
|
import appeng.api.parts.ISimplifiedBundle;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.parts.PartItemStack;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.util.AECableType;
|
|
|
|
import appeng.api.util.AEColor;
|
|
|
|
import appeng.api.util.DimensionalCoord;
|
2013-12-30 06:57:08 +01:00
|
|
|
import appeng.api.util.IConfigManager;
|
2014-02-20 06:18:49 +01:00
|
|
|
import appeng.api.util.IConfigureableObject;
|
|
|
|
import appeng.helpers.IPriorityHost;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.me.helpers.AENetworkProxy;
|
|
|
|
import appeng.me.helpers.IGridProxyable;
|
|
|
|
import appeng.parts.networking.PartCable;
|
2014-02-20 06:18:49 +01:00
|
|
|
import appeng.tile.inventory.AppEngInternalAEInventory;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.util.Platform;
|
2014-02-20 06:18:49 +01:00
|
|
|
import appeng.util.SettingsFrom;
|
2014-02-07 06:51:19 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
public class AEBasePart implements IPart, IGridProxyable, IActionHost, IUpgradeableHost
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2014-02-15 07:30:06 +01:00
|
|
|
protected ISimplifiedBundle renderCache = null;
|
|
|
|
|
2014-01-23 17:28:12 +01:00
|
|
|
protected AENetworkProxy proxy;
|
2013-12-27 23:59:59 +01:00
|
|
|
protected TileEntity tile = null;
|
|
|
|
protected IPartHost host = null;
|
|
|
|
protected ForgeDirection side = null;
|
|
|
|
|
|
|
|
protected final ItemStack is;
|
|
|
|
|
|
|
|
public AEBasePart(Class c, ItemStack is) {
|
|
|
|
this.is = is;
|
2014-01-23 17:28:12 +01:00
|
|
|
proxy = new AENetworkProxy( this, "part", is, this instanceof PartCable );
|
2013-12-27 23:59:59 +01:00
|
|
|
proxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-07 06:51:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-27 23:59:59 +01:00
|
|
|
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
|
|
|
{
|
|
|
|
rh.setBounds( 1, 1, 1, 15, 15, 15 );
|
|
|
|
rh.renderInventoryBox( renderer );
|
|
|
|
|
|
|
|
rh.setBounds( 1, 1, 1, 15, 15, 15 );
|
|
|
|
rh.renderInventoryBox( renderer );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-07 06:51:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-27 23:59:59 +01:00
|
|
|
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
|
|
|
{
|
|
|
|
rh.setBounds( 1, 1, 1, 15, 15, 15 );
|
|
|
|
rh.renderBlock( x, y, z, renderer );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-07 06:51:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-27 23:59:59 +01:00
|
|
|
public void renderDynamic(double x, double y, double z, IPartRenderHelper rh, RenderBlocks renderer)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public ItemStack getItemStack(PartItemStack type)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return is;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isSolid()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNeighborChanged()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canConnectRedstone()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-05 09:46:54 +01:00
|
|
|
public void readFromNBT(NBTTagCompound data)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-05 09:46:54 +01:00
|
|
|
proxy.readFromNBT( data );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-05 09:46:54 +01:00
|
|
|
public void writeToNBT(NBTTagCompound data)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-05 09:46:54 +01:00
|
|
|
proxy.writeToNBT( data );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int isProvidingStrongPower()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int isProvidingWeakPower()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void writeToStream(ByteBuf data) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public boolean readFromStream(ByteBuf data) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGridNode getGridNode()
|
|
|
|
{
|
|
|
|
return proxy.getNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEntityCollision(Entity entity)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removeFromWorld()
|
|
|
|
{
|
|
|
|
proxy.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addToWorld()
|
|
|
|
{
|
|
|
|
proxy.onReady();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setPartHostInfo(ForgeDirection side, IPartHost host, TileEntity tile)
|
|
|
|
{
|
|
|
|
this.side = side;
|
|
|
|
this.tile = tile;
|
|
|
|
this.host = host;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IPartHost getHost()
|
|
|
|
{
|
|
|
|
return host;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGridNode getExternalFacingNode()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGridNode getGridNode(ForgeDirection dir)
|
|
|
|
{
|
|
|
|
return proxy.getNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected AEColor getColor()
|
|
|
|
{
|
|
|
|
if ( getHost() == null )
|
|
|
|
return AEColor.Transparent;
|
|
|
|
return getHost().getColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DimensionalCoord getLocation()
|
|
|
|
{
|
|
|
|
return new DimensionalCoord( tile );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void getBoxes(IPartCollsionHelper bch)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-07 06:51:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-27 23:59:59 +01:00
|
|
|
public void randomDisplayTick(World world, int x, int y, int z, Random r)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getLightLevel()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AECableType getCableConnectionType(ForgeDirection dir)
|
|
|
|
{
|
|
|
|
return AECableType.GLASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void getDrops(List<ItemStack> drops, boolean wrenched)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int cableConnectionRenderTo()
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void gridChanged()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-28 21:54:05 +01:00
|
|
|
@Override
|
|
|
|
public boolean isLadder(EntityLivingBase entity)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-30 06:57:08 +01:00
|
|
|
@Override
|
|
|
|
public IConfigManager getConfigManager()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getInventoryByName(String name)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInstalledUpgrades(Upgrades u)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-20 06:18:49 +01:00
|
|
|
/**
|
|
|
|
* depending on the from, diffrent settings will be accepted, don't call this with null
|
|
|
|
*
|
|
|
|
* @param from
|
|
|
|
* @param compound
|
|
|
|
*/
|
|
|
|
public void uploadSettings(SettingsFrom from, NBTTagCompound compound)
|
|
|
|
{
|
|
|
|
if ( compound != null && this instanceof IConfigureableObject )
|
|
|
|
{
|
|
|
|
IConfigManager cm = ((IConfigureableObject) this).getConfigManager();
|
|
|
|
if ( cm != null )
|
|
|
|
cm.readFromNBT( compound );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this instanceof IPriorityHost )
|
|
|
|
{
|
|
|
|
IPriorityHost pHost = (IPriorityHost) this;
|
|
|
|
pHost.setPriority( compound.getInteger( "priority" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this instanceof ISegmentedInventory )
|
|
|
|
{
|
|
|
|
IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" );
|
|
|
|
if ( inv != null && inv instanceof AppEngInternalAEInventory )
|
|
|
|
{
|
|
|
|
AppEngInternalAEInventory target = (AppEngInternalAEInventory) inv;
|
|
|
|
AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSizeInventory() );
|
|
|
|
tmp.readFromNBT( compound, "config" );
|
|
|
|
for (int x = 0; x < tmp.getSizeInventory(); x++)
|
|
|
|
target.setInventorySlotContents( x, tmp.getStackInSlot( x ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* null means nothing to store...
|
|
|
|
*
|
|
|
|
* @param from
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public NBTTagCompound downloadSettings(SettingsFrom from)
|
|
|
|
{
|
|
|
|
NBTTagCompound output = new NBTTagCompound();
|
|
|
|
|
|
|
|
if ( this instanceof IConfigureableObject )
|
|
|
|
{
|
|
|
|
IConfigManager cm = this.getConfigManager();
|
|
|
|
if ( cm != null )
|
|
|
|
cm.writeToNBT( output );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this instanceof IPriorityHost )
|
|
|
|
{
|
|
|
|
IPriorityHost pHost = (IPriorityHost) this;
|
|
|
|
output.setInteger( "priority", pHost.getPriority() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this instanceof ISegmentedInventory )
|
|
|
|
{
|
|
|
|
IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" );
|
|
|
|
if ( inv != null && inv instanceof AppEngInternalAEInventory )
|
|
|
|
{
|
|
|
|
((AppEngInternalAEInventory) inv).writeToNBT( output, "config" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return output.hasNoTags() ? null : output;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean useStandardMemoryCard()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean useMemoryCard(EntityPlayer player)
|
|
|
|
{
|
|
|
|
ItemStack memCardIS = player.inventory.getCurrentItem();
|
|
|
|
|
|
|
|
if ( memCardIS != null && useStandardMemoryCard() && memCardIS.getItem() instanceof IMemoryCard )
|
|
|
|
{
|
|
|
|
IMemoryCard memc = (IMemoryCard) memCardIS.getItem();
|
|
|
|
String name = getItemStack( PartItemStack.Network ).getUnlocalizedName();
|
|
|
|
|
|
|
|
if ( player.isSneaking() )
|
|
|
|
{
|
|
|
|
NBTTagCompound data = downloadSettings( SettingsFrom.MEMORY_CARD );
|
|
|
|
if ( data != null )
|
|
|
|
{
|
|
|
|
memc.setMemoryCardContents( memCardIS, name, data );
|
|
|
|
memc.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
String stordName = memc.getSettingsName( memCardIS );
|
|
|
|
NBTTagCompound data = memc.getData( memCardIS );
|
|
|
|
if ( name.equals( stordName ) )
|
|
|
|
{
|
|
|
|
uploadSettings( SettingsFrom.MEMORY_CARD, data );
|
|
|
|
memc.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
memc.notifyUser( player, MemoryCardMessages.INVALID_MACHINE );
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
@Override
|
2014-02-20 06:18:49 +01:00
|
|
|
final public boolean onActivate(EntityPlayer player, Vec3 pos)
|
|
|
|
{
|
|
|
|
if ( useMemoryCard( player ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return onPartActivate( player, pos );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
final public boolean onShiftActivate(EntityPlayer player, Vec3 pos)
|
|
|
|
{
|
|
|
|
if ( useMemoryCard( player ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return onPartShiftActivate( player, pos );
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onPartShiftActivate(EntityPlayer player, Vec3 pos)
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
|
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
proxy.setOwner( player );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
2014-01-23 17:28:12 +01:00
|
|
|
@Override
|
|
|
|
public TileEntity getTile()
|
|
|
|
{
|
|
|
|
return tile;
|
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
@Override
|
|
|
|
public void securityBreak()
|
|
|
|
{
|
|
|
|
if ( is.stackSize > 0 )
|
|
|
|
{
|
|
|
|
List<ItemStack> items = new ArrayList();
|
|
|
|
items.add( is.copy() );
|
|
|
|
host.removePart( side, false );
|
2014-02-09 02:34:52 +01:00
|
|
|
Platform.spawnDrops( tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, items );
|
2014-01-27 05:00:36 +01:00
|
|
|
is.stackSize = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AENetworkProxy getProxy()
|
|
|
|
{
|
|
|
|
return proxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IGridNode getActionableNode()
|
|
|
|
{
|
|
|
|
return proxy.getNode();
|
|
|
|
}
|
|
|
|
|
2014-01-30 19:54:09 +01:00
|
|
|
@Override
|
|
|
|
public boolean canBePlacedOn(BusSupport what)
|
|
|
|
{
|
|
|
|
return what == BusSupport.CABLE;
|
|
|
|
}
|
|
|
|
|
2014-01-31 01:50:11 +01:00
|
|
|
public void saveChanges()
|
|
|
|
{
|
|
|
|
host.markForSave();
|
|
|
|
}
|
2014-02-06 05:36:10 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean requireDynamicRender()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|