Applied-Energistics-2-tiler.../src/main/java/appeng/block/storage/BlockSkyChest.java

111 lines
3.7 KiB
Java
Raw Normal View History

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-02-28 09:12:00 +01:00
package appeng.block.storage;
import java.util.Collections;
2014-02-28 09:12:00 +01:00
import java.util.List;
import javax.annotation.Nullable;
2014-02-28 09:12:00 +01:00
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
2014-02-28 09:12:00 +01:00
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumBlockRenderType;
2015-06-16 02:44:59 +02:00
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
2014-02-28 09:12:00 +01:00
import net.minecraft.world.World;
2015-09-30 14:22:21 +02:00
2015-06-16 02:44:59 +02:00
import appeng.api.util.AEPartLocation;
import appeng.block.AEBaseTileBlock;
2014-02-28 09:12:00 +01:00
import appeng.core.sync.GuiBridge;
import appeng.helpers.ICustomCollision;
import appeng.tile.storage.TileSkyChest;
import appeng.util.Platform;
public class BlockSkyChest extends AEBaseTileBlock implements ICustomCollision
2014-02-28 09:12:00 +01:00
{
2015-12-24 02:03:16 +01:00
public enum SkyChestType
2015-06-16 02:44:59 +02:00
{
STONE, BLOCK
};
2014-02-28 09:12:00 +01:00
2015-06-16 02:44:59 +02:00
public final SkyChestType type;
2015-12-24 02:03:16 +01:00
2015-09-30 14:24:40 +02:00
public BlockSkyChest( final SkyChestType type )
{
super( Material.ROCK );
2014-12-29 15:13:47 +01:00
this.setTileEntity( TileSkyChest.class );
this.setOpaque( this.setFullSize( false ) );
2014-12-29 15:13:47 +01:00
this.lightOpacity = 0;
2015-12-24 02:05:39 +01:00
this.setHasSubtypes( true );
2014-12-29 15:13:47 +01:00
this.setHardness( 50 );
this.blockResistance = 150.0f;
2015-06-16 02:44:59 +02:00
this.type = type;
2014-02-28 09:12:00 +01:00
}
@Override
public EnumBlockRenderType getRenderType( IBlockState state )
{
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
}
@Override
public boolean onActivated( final World w, final BlockPos pos, final EntityPlayer player, final EnumHand hand, final @Nullable ItemStack heldItem, final EnumFacing side, final float hitX, final float hitY, final float hitZ )
{
if( Platform.isServer() )
2015-04-29 02:30:53 +02:00
{
2015-06-16 02:44:59 +02:00
Platform.openGUI( player, this.getTileEntity( w, pos ), AEPartLocation.fromFacing( side ), GuiBridge.GUI_SKYCHEST );
2015-04-29 02:30:53 +02:00
}
return true;
}
2015-12-24 02:03:16 +01:00
2014-02-28 09:12:00 +01:00
@Override
public Iterable<AxisAlignedBB> getSelectedBoundingBoxesFromPool( final World w, final BlockPos pos, final Entity thePlayer, final boolean b )
2014-02-28 09:12:00 +01:00
{
2015-09-30 14:24:40 +02:00
final TileSkyChest sk = this.getTileEntity( w, pos );
2015-06-16 02:44:59 +02:00
EnumFacing o = EnumFacing.UP;
2014-03-27 04:57:38 +01:00
if( sk != null )
2015-04-29 02:30:53 +02:00
{
2014-03-27 04:57:38 +01:00
o = sk.getUp();
2015-04-29 02:30:53 +02:00
}
2014-03-27 04:57:38 +01:00
2015-09-30 14:24:40 +02:00
final double offsetX = o.getFrontOffsetX() == 0 ? 0.06 : 0.0;
final double offsetY = o.getFrontOffsetY() == 0 ? 0.06 : 0.0;
final double offsetZ = o.getFrontOffsetZ() == 0 ? 0.06 : 0.0;
2014-03-27 04:57:38 +01:00
2015-09-30 14:24:40 +02:00
final double sc = 0.06;
return Collections.singletonList( new AxisAlignedBB( Math.max( 0.0, offsetX - o.getFrontOffsetX() * sc ), Math.max( 0.0, offsetY - o.getFrontOffsetY() * sc ), Math.max( 0.0, offsetZ - o.getFrontOffsetZ() * sc ), Math.min( 1.0, ( 1.0 - offsetX ) - o.getFrontOffsetX() * sc ), Math.min( 1.0, ( 1.0 - offsetY ) - o.getFrontOffsetY() * sc ), Math.min( 1.0, ( 1.0 - offsetZ ) - o.getFrontOffsetZ() * sc ) ) );
2014-02-28 09:12:00 +01:00
}
2015-12-24 02:03:16 +01:00
2014-02-28 09:12:00 +01:00
@Override
public void addCollidingBlockToList( final World w, final BlockPos pos, final AxisAlignedBB bb, final List<AxisAlignedBB> out, final Entity e )
2014-02-28 09:12:00 +01:00
{
out.add( new AxisAlignedBB( 0.05, 0.05, 0.05, 0.95, 0.95, 0.95 ) );
2014-02-28 09:12:00 +01:00
}
}