2014-11-04 02:35:31 +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-03-26 04:06:54 +01:00
|
|
|
package appeng.block.crafting;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-03-26 04:06:54 +01:00
|
|
|
import java.util.EnumSet;
|
2014-05-10 07:00:02 +02:00
|
|
|
import java.util.List;
|
2014-03-26 04:06:54 +01:00
|
|
|
|
2014-05-14 04:42:14 +02:00
|
|
|
import net.minecraft.block.Block;
|
2014-03-26 04:06:54 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
2014-05-10 07:00:02 +02:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2014-06-26 03:49:37 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-05-10 07:00:02 +02:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-05-15 16:34:38 +02:00
|
|
|
import net.minecraft.util.IIcon;
|
2014-05-10 07:00:02 +02:00
|
|
|
import net.minecraft.world.World;
|
2014-06-26 03:49:37 +02:00
|
|
|
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-03-26 04:06:54 +01:00
|
|
|
import appeng.block.AEBaseBlock;
|
2014-05-14 04:42:14 +02:00
|
|
|
import appeng.client.render.BaseBlockRender;
|
2014-07-11 06:46:51 +02:00
|
|
|
import appeng.client.render.blocks.RenderBlockCraftingCPU;
|
2014-05-26 03:58:44 +02:00
|
|
|
import appeng.client.texture.ExtraBlockTextures;
|
2014-03-26 04:06:54 +01:00
|
|
|
import appeng.core.features.AEFeature;
|
2014-06-26 03:49:37 +02:00
|
|
|
import appeng.core.sync.GuiBridge;
|
2014-05-09 06:10:12 +02:00
|
|
|
import appeng.tile.crafting.TileCraftingTile;
|
2014-06-26 03:49:37 +02:00
|
|
|
import appeng.util.Platform;
|
2014-03-26 04:06:54 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-03-26 04:06:54 +01:00
|
|
|
public class BlockCraftingUnit extends AEBaseBlock
|
|
|
|
{
|
2014-05-18 05:19:23 +02:00
|
|
|
public static final int FLAG_FORMED = 8;
|
2014-05-10 07:00:02 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public BlockCraftingUnit()
|
|
|
|
{
|
|
|
|
this( BlockCraftingUnit.class );
|
|
|
|
|
|
|
|
this.setTileEntity( TileCraftingTile.class );
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockCraftingUnit( Class<? extends BlockCraftingUnit> childClass )
|
2014-11-04 02:35:31 +01:00
|
|
|
{
|
2014-05-18 05:19:23 +02:00
|
|
|
super( childClass, Material.iron );
|
2014-11-04 02:35:31 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.hasSubtypes = true;
|
|
|
|
this.setFeature( EnumSet.of( AEFeature.CraftingCPU ) );
|
2014-05-14 04:42:14 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
protected Class<? extends BaseBlockRender> getRenderer()
|
2014-11-04 02:35:31 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return RenderBlockCraftingCPU.class;
|
|
|
|
}
|
2014-11-04 02:35:31 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public IIcon getIcon( int direction, int metadata )
|
|
|
|
{
|
|
|
|
switch( metadata )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
return super.getIcon( 0, 0 );
|
|
|
|
case 1:
|
|
|
|
return ExtraBlockTextures.BlockCraftingAccelerator.getIcon();
|
|
|
|
case FLAG_FORMED:
|
|
|
|
return ExtraBlockTextures.BlockCraftingUnitFit.getIcon();
|
|
|
|
case 1 | FLAG_FORMED:
|
|
|
|
return ExtraBlockTextures.BlockCraftingAcceleratorFit.getIcon();
|
|
|
|
}
|
2014-03-26 04:06:54 +01:00
|
|
|
}
|
|
|
|
|
2014-06-26 03:49:37 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean onActivated( World w, int x, int y, int z, EntityPlayer p, int side, float hitX, float hitY, float hitZ )
|
2014-06-26 03:49:37 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
TileCraftingTile tg = this.getTileEntity( w, x, y, z );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tg != null && !p.isSneaking() && tg.isFormed() && tg.isActive() )
|
2014-06-26 03:49:37 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.isClient() )
|
2014-07-13 01:59:15 +02:00
|
|
|
return true;
|
|
|
|
|
2014-06-26 03:49:37 +02:00
|
|
|
Platform.openGUI( p, tg, ForgeDirection.getOrientation( side ), GuiBridge.GUI_CRAFTING_CPU );
|
|
|
|
return true;
|
|
|
|
}
|
2014-07-13 01:59:15 +02:00
|
|
|
|
2014-06-26 03:49:37 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-18 05:19:23 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
public void getCheckedSubBlocks( Item item, CreativeTabs tabs, List<ItemStack> itemStacks )
|
2014-05-18 05:19:23 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
itemStacks.add( new ItemStack( this, 1, 0 ) );
|
|
|
|
itemStacks.add( new ItemStack( this, 1, 1 ) );
|
2014-07-11 22:06:42 +02:00
|
|
|
}
|
2014-07-13 01:59:15 +02:00
|
|
|
|
2014-07-11 22:06:42 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void setRenderStateByMeta( int itemDamage )
|
2014-07-11 22:06:42 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
IIcon front = this.getIcon( ForgeDirection.SOUTH.ordinal(), itemDamage );
|
|
|
|
IIcon other = this.getIcon( ForgeDirection.NORTH.ordinal(), itemDamage );
|
|
|
|
this.getRendererInstance().setTemporaryRenderIcons( other, other, front, other, other, other );
|
2014-05-18 05:19:23 +02:00
|
|
|
}
|
2014-07-13 01:59:15 +02:00
|
|
|
|
2014-05-23 04:39:21 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void breakBlock( World w, int x, int y, int z, Block a, int b )
|
2014-05-23 04:39:21 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
TileCraftingTile cp = this.getTileEntity( w, x, y, z );
|
|
|
|
if( cp != null )
|
|
|
|
cp.breakCluster();
|
2014-05-23 04:39:21 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
super.breakBlock( w, x, y, z, a, b );
|
2014-05-23 04:39:21 +02:00
|
|
|
}
|
|
|
|
|
2014-07-11 06:46:51 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public String getUnlocalizedName( ItemStack is )
|
2014-07-11 06:46:51 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is.getItemDamage() == 1 )
|
|
|
|
return "tile.appliedenergistics2.BlockCraftingAccelerator";
|
2014-07-11 06:46:51 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.getItemUnlocalizedName( is );
|
2014-05-15 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
protected String getItemUnlocalizedName( ItemStack is )
|
2014-05-14 04:42:14 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return super.getUnlocalizedName( is );
|
2014-05-14 04:42:14 +02:00
|
|
|
}
|
|
|
|
|
2014-07-02 07:05:21 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void onNeighborBlockChange( World w, int x, int y, int z, Block junk )
|
2014-07-02 07:05:21 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
TileCraftingTile cp = this.getTileEntity( w, x, y, z );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( cp != null )
|
|
|
|
cp.updateMultiBlock();
|
2014-07-02 07:05:21 +02:00
|
|
|
}
|
|
|
|
|
2014-05-14 04:42:14 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public int damageDropped( int meta )
|
2014-05-14 04:42:14 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return meta & 3;
|
2014-05-14 04:42:14 +02:00
|
|
|
}
|
|
|
|
|
2014-05-10 07:00:02 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public int getDamageValue( World w, int x, int y, int z )
|
2014-05-10 07:00:02 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
int meta = w.getBlockMetadata( x, y, z );
|
|
|
|
return this.damageDropped( meta );
|
2014-05-10 07:00:02 +02:00
|
|
|
}
|
2014-03-26 04:06:54 +01:00
|
|
|
}
|