Applied-Energistics-2-tiler.../src/main/java/appeng/facade/FacadePart.java
2016-09-10 00:56:28 +02:00

174 lines
4.1 KiB
Java

/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, 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>.
*/
package appeng.facade;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.AxisAlignedBB;
import appeng.api.AEApi;
import appeng.api.parts.IBoxProvider;
import appeng.api.parts.IFacadePart;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.util.AEPartLocation;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IBuildCraftTransport;
import appeng.util.Platform;
public class FacadePart implements IFacadePart, IBoxProvider
{
private final ItemStack facade;
private final AEPartLocation side;
private int thickness = 2;
public FacadePart( final ItemStack facade, final AEPartLocation side )
{
if( facade == null )
{
throw new IllegalArgumentException( "Facade Part constructed on null item." );
}
this.facade = facade.copy();
this.facade.stackSize = 1;
this.side = side;
}
public static boolean isFacade( final ItemStack is )
{
return is.getItem() instanceof IFacadeItem;
}
@Override
public ItemStack getItemStack()
{
return this.facade;
}
@Override
public void getBoxes( final IPartCollisionHelper ch, final Entity e )
{
if( e instanceof EntityLivingBase )
{
// prevent weird snag behavior
ch.addBox( 0.0, 0.0, 14, 16.0, 16.0, 16.0 );
}
else
{
// the box is 15.9 for transition planes to pick up collision events.
ch.addBox( 0.0, 0.0, 14, 16.0, 16.0, 15.9 );
}
}
@Override
public AEPartLocation getSide()
{
return this.side;
}
@Override
public AxisAlignedBB getPrimaryBox()
{
return Platform.getPrimaryBox( this.side, this.thickness );
}
@Override
public Item getItem()
{
final ItemStack is = this.getTexture();
if( is == null )
{
return null;
}
return is.getItem();
}
@Override
public int getItemDamage()
{
final ItemStack is = this.getTexture();
if( is == null )
{
return 0;
}
return is.getItemDamage();
}
@Override
public boolean notAEFacade()
{
return !( this.facade.getItem() instanceof IFacadeItem );
}
@Override
public void setThinFacades( final boolean useThinFacades )
{
this.thickness = useThinFacades ? 1 : 2;
}
@Override
public boolean isTransparent()
{
if( AEApi.instance().partHelper().getCableRenderMode().transparentFacades )
{
return true;
}
final ItemStack is = this.getTexture();
final Block blk = Block.getBlockFromItem( is.getItem() );
return !blk.isOpaqueCube( blk.getDefaultState() );
}
@Nullable
private ItemStack getTexture()
{
final Item maybeFacade = this.facade.getItem();
// AE Facade
if( maybeFacade instanceof IFacadeItem )
{
final IFacadeItem facade = (IFacadeItem) maybeFacade;
return facade.getTextureItem( this.facade );
}
else if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.BuildCraftTransport ) )
{
final IBuildCraftTransport bc = (IBuildCraftTransport) IntegrationRegistry.INSTANCE.getInstance( IntegrationType.BuildCraftTransport );
return bc.getTextureForFacade( this.facade );
}
return null;
}
@Override
public void getBoxes( final IPartCollisionHelper bch )
{
this.getBoxes( bch, null );
}
}