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>.
|
|
|
|
*/
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
package appeng.block.storage;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-06-16 02:44:59 +02:00
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.EnumWorldBlockLayer;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.storage.ICellHandler;
|
2015-06-16 02:44:59 +02:00
|
|
|
import appeng.api.util.AEPartLocation;
|
2015-05-09 12:18:43 +02:00
|
|
|
import appeng.block.AEBaseTileBlock;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.client.render.BaseBlockRender;
|
|
|
|
import appeng.client.render.blocks.RenderMEChest;
|
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.core.localization.PlayerMessages;
|
|
|
|
import appeng.core.sync.GuiBridge;
|
|
|
|
import appeng.tile.storage.TileChest;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-05-09 12:18:43 +02:00
|
|
|
public class BlockChest extends AEBaseTileBlock
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-12-24 02:03:16 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public BlockChest()
|
|
|
|
{
|
2015-04-04 00:42:19 +02:00
|
|
|
super( Material.iron );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setTileEntity( TileChest.class );
|
2015-04-04 01:26:35 +02:00
|
|
|
this.setFeature( EnumSet.of( AEFeature.StorageCells, AEFeature.MEChest ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
@Override
|
|
|
|
public EnumWorldBlockLayer getBlockLayer()
|
|
|
|
{
|
|
|
|
return EnumWorldBlockLayer.CUTOUT;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
protected Class<? extends BaseBlockRender> getRenderer()
|
|
|
|
{
|
|
|
|
return RenderMEChest.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-16 02:44:59 +02:00
|
|
|
public boolean onActivated(
|
2015-09-30 14:24:40 +02:00
|
|
|
final World w,
|
|
|
|
final BlockPos pos,
|
|
|
|
final EntityPlayer p,
|
|
|
|
final EnumFacing side,
|
|
|
|
final float hitX,
|
|
|
|
final float hitY,
|
|
|
|
final float hitZ )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final TileChest tg = this.getTileEntity( w, pos );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tg != null && !p.isSneaking() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.isClient() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
if( side != tg.getUp() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
Platform.openGUI( p, tg, AEPartLocation.fromFacing( side ), GuiBridge.GUI_CHEST );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-03-28 05:31:06 +01:00
|
|
|
else
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final ItemStack cell = tg.getStackInSlot( 1 );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( cell != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final ICellHandler ch = AEApi.instance().registries().cell().getHandler( cell );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-03-02 09:35:11 +01:00
|
|
|
tg.openGui( p, ch, cell, side );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-03-05 08:27:42 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-03-05 08:27:42 +01:00
|
|
|
p.addChatMessage( PlayerMessages.ChestCannotReadStorageCell.get() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|