2013-12-27 23:59:59 +01:00
|
|
|
package appeng.block;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.client.MinecraftForgeClient;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.util.IOrientable;
|
|
|
|
import appeng.api.util.IOrientableBlock;
|
2014-03-02 09:35:11 +01:00
|
|
|
import appeng.block.misc.BlockSkyCompass;
|
2014-02-02 08:32:10 +01:00
|
|
|
import appeng.block.networking.BlockWireless;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.client.render.ItemRenderer;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.me.helpers.IGridProxyable;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.tile.AEBaseTile;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
|
|
|
public class AEBaseItemBlock extends ItemBlock
|
|
|
|
{
|
|
|
|
|
|
|
|
final AEBaseBlock blockType;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
public AEBaseItemBlock(Block id) {
|
2013-12-27 23:59:59 +01:00
|
|
|
super( id );
|
2014-02-09 02:34:52 +01:00
|
|
|
blockType = (AEBaseBlock) id;
|
2014-03-01 04:45:30 +01:00
|
|
|
hasSubtypes = blockType.hasSubtypes;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( Platform.isClient() )
|
2014-02-09 02:34:52 +01:00
|
|
|
MinecraftForgeClient.registerItemRenderer( this, ItemRenderer.instance );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-28 20:13:43 +01:00
|
|
|
@Override
|
2014-03-01 04:45:30 +01:00
|
|
|
public int getMetadata(int dmg)
|
|
|
|
{
|
|
|
|
if ( hasSubtypes )
|
|
|
|
return dmg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUnlocalizedName(ItemStack is)
|
|
|
|
{
|
|
|
|
return blockType.getUnlocalizedName( is );
|
|
|
|
}
|
2014-02-28 20:13:43 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public void addInformation(ItemStack is, EntityPlayer player, List lines, boolean advancedItemTooltips)
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
blockType.addInformation( is, player, lines, advancedItemTooltips );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
|
|
|
|
{
|
|
|
|
ForgeDirection up = ForgeDirection.UNKNOWN;
|
|
|
|
ForgeDirection forward = ForgeDirection.UNKNOWN;
|
|
|
|
|
|
|
|
IOrientable ori = null;
|
|
|
|
|
|
|
|
if ( blockType.hasBlockTileEntity() )
|
|
|
|
{
|
2014-03-02 09:35:11 +01:00
|
|
|
if ( blockType instanceof BlockWireless || blockType instanceof BlockSkyCompass )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-02 08:32:10 +01:00
|
|
|
forward = ForgeDirection.getOrientation( side );
|
|
|
|
if ( forward == ForgeDirection.UP || forward == ForgeDirection.DOWN )
|
|
|
|
up = ForgeDirection.SOUTH;
|
|
|
|
else
|
|
|
|
up = ForgeDirection.UP;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-02-02 08:32:10 +01:00
|
|
|
else
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-02 08:32:10 +01:00
|
|
|
up = ForgeDirection.UP;
|
|
|
|
|
|
|
|
byte rotation = (byte) (MathHelper.floor_double( (double) ((player.rotationYaw * 4F) / 360F) + 2.5D ) & 3);
|
|
|
|
|
|
|
|
switch (rotation)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
forward = ForgeDirection.SOUTH;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
forward = ForgeDirection.WEST;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
forward = ForgeDirection.NORTH;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
forward = ForgeDirection.EAST;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( player.rotationPitch > 65 )
|
|
|
|
{
|
|
|
|
up = forward.getOpposite();
|
|
|
|
forward = ForgeDirection.UP;
|
|
|
|
}
|
|
|
|
else if ( player.rotationPitch < -65 )
|
|
|
|
{
|
|
|
|
up = forward.getOpposite();
|
|
|
|
forward = ForgeDirection.DOWN;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( blockType instanceof IOrientableBlock )
|
|
|
|
{
|
|
|
|
ori = ((IOrientableBlock) blockType).getOrientable( w, x, y, z );
|
|
|
|
up = ForgeDirection.getOrientation( side );
|
|
|
|
forward = ForgeDirection.SOUTH;
|
|
|
|
if ( up.offsetY == 0 )
|
|
|
|
forward = ForgeDirection.UP;
|
|
|
|
|
|
|
|
ori.setOrientation( forward, up );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !blockType.isValidOrientation( w, x, y, z, forward, up ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( super.placeBlockAt( stack, player, w, x, y, z, side, hitX, hitY, hitZ, metadata ) )
|
|
|
|
{
|
2014-03-20 04:28:53 +01:00
|
|
|
if ( blockType.hasBlockTileEntity() && !blockType.hasCustomRotation() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
AEBaseTile tile = blockType.getTileEntity( w, x, y, z );
|
|
|
|
ori = tile;
|
|
|
|
|
|
|
|
if ( tile == null )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if ( ori.canBeRotated() )
|
|
|
|
{
|
|
|
|
if ( ori.getForward() == null || ori.getUp() == null || // null
|
|
|
|
tile.getForward() == ForgeDirection.UNKNOWN || ori.getUp() == ForgeDirection.UNKNOWN )
|
|
|
|
ori.setOrientation( forward, up );
|
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
if ( tile instanceof IGridProxyable )
|
|
|
|
{
|
|
|
|
((IGridProxyable) tile).getProxy().setOwner( player );
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
tile.onPlacement( stack, player, side );
|
|
|
|
}
|
|
|
|
else if ( blockType instanceof IOrientableBlock )
|
|
|
|
{
|
|
|
|
ori.setOrientation( forward, up );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isBookEnchantable(ItemStack itemstack1, ItemStack itemstack2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|