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.tile.storage;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-02-28 09:12:00 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-03-14 03:59:37 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-02-28 09:12:00 +01:00
|
|
|
import appeng.tile.AEBaseInvTile;
|
2014-08-28 09:39:52 +02:00
|
|
|
import appeng.tile.TileEvent;
|
2014-02-28 09:12:00 +01:00
|
|
|
import appeng.tile.events.TileEventType;
|
|
|
|
import appeng.tile.inventory.AppEngInternalInventory;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-02-28 09:12:00 +01:00
|
|
|
public class TileSkyChest extends AEBaseInvTile
|
|
|
|
{
|
|
|
|
|
2015-01-01 21:15:03 +01:00
|
|
|
final int[] sides = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 };
|
2014-02-28 09:12:00 +01:00
|
|
|
final AppEngInternalInventory inv = new AppEngInternalInventory( this, 9 * 4 );
|
2015-04-03 08:54:31 +02:00
|
|
|
// server
|
|
|
|
public int playerOpen;
|
|
|
|
// client..
|
|
|
|
public long lastEvent;
|
|
|
|
public float lidAngle;
|
2014-02-28 09:12:00 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@TileEvent( TileEventType.NETWORK_WRITE )
|
|
|
|
public void writeToStream_TileSkyChest( ByteBuf data )
|
2014-02-28 09:12:00 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
data.writeBoolean( this.playerOpen > 0 );
|
2014-08-28 09:39:52 +02:00
|
|
|
}
|
2014-02-28 09:12:00 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@TileEvent( TileEventType.NETWORK_READ )
|
|
|
|
public boolean readFromStream_TileSkyChest( ByteBuf data )
|
2014-08-28 09:39:52 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
int wasOpen = this.playerOpen;
|
|
|
|
this.playerOpen = data.readBoolean() ? 1 : 0;
|
2014-02-28 09:12:00 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( wasOpen != this.playerOpen )
|
2014-12-29 15:13:47 +01:00
|
|
|
this.lastEvent = System.currentTimeMillis();
|
2014-02-28 09:12:00 +01:00
|
|
|
|
2014-08-28 09:39:52 +02:00
|
|
|
return false; // TESR yo!
|
2014-02-28 09:12:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean requiresTESR()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getInternalInventory()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.inv;
|
2014-02-28 09:12:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void openInventory()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.isClient() )
|
2014-02-28 09:12:00 +01:00
|
|
|
return;
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.playerOpen++;
|
2014-02-28 09:12:00 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.playerOpen == 1 )
|
2014-02-28 09:12:00 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.getWorldObj().playSoundEffect( this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D, "random.chestopen", 0.5F, this.getWorldObj().rand.nextFloat() * 0.1F + 0.9F );
|
|
|
|
this.markForUpdate();
|
2014-02-28 09:12:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void closeInventory()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.isClient() )
|
2014-02-28 09:12:00 +01:00
|
|
|
return;
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.playerOpen--;
|
2014-02-28 09:12:00 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.playerOpen < 0 )
|
2014-12-29 15:13:47 +01:00
|
|
|
this.playerOpen = 0;
|
2014-02-28 09:12:00 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.playerOpen == 0 )
|
2014-03-01 04:45:30 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.getWorldObj().playSoundEffect( this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D, "random.chestclosed", 0.5F, this.getWorldObj().rand.nextFloat() * 0.1F + 0.9F );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.markForUpdate();
|
2014-03-01 04:45:30 +01:00
|
|
|
}
|
2014-02-28 09:12:00 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int[] getAccessibleSlotsBySide( ForgeDirection side )
|
|
|
|
{
|
|
|
|
return this.sides;
|
|
|
|
}
|
2014-02-28 09:12:00 +01:00
|
|
|
}
|