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-03-07 04:02:15 +01:00
|
|
|
package appeng.container.implementations;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-03-07 04:02:15 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-03-07 04:02:15 +01:00
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.container.AEBaseContainer;
|
|
|
|
import appeng.container.slot.QuartzKnifeOutput;
|
|
|
|
import appeng.container.slot.SlotRestrictedInput;
|
|
|
|
import appeng.items.contents.QuartzKnifeObj;
|
|
|
|
import appeng.tile.inventory.AppEngInternalInventory;
|
|
|
|
import appeng.tile.inventory.IAEAppEngInventory;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-03-07 04:02:15 +01:00
|
|
|
public class ContainerQuartzKnife extends AEBaseContainer implements IAEAppEngInventory, IInventory
|
|
|
|
{
|
|
|
|
|
2014-09-29 09:54:34 +02:00
|
|
|
final QuartzKnifeObj toolInv;
|
2014-03-07 04:02:15 +01:00
|
|
|
|
2014-09-29 09:54:34 +02:00
|
|
|
final AppEngInternalInventory inSlot = new AppEngInternalInventory( this, 1 );
|
|
|
|
final SlotRestrictedInput metals;
|
|
|
|
final QuartzKnifeOutput output;
|
2014-03-07 04:02:15 +01:00
|
|
|
String myName = "";
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public ContainerQuartzKnife( InventoryPlayer ip, QuartzKnifeObj te )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
|
|
|
super( ip, null, null );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.toolInv = te;
|
2014-03-07 04:02:15 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.addSlotToContainer( this.metals = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.METAL_INGOTS, this.inSlot, 0, 94, 44, ip ) );
|
|
|
|
this.addSlotToContainer( this.output = new QuartzKnifeOutput( this, 0, 134, 44, -1 ) );
|
2014-03-07 04:02:15 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.lockPlayerInventorySlot( ip.currentItem );
|
2014-03-07 04:02:15 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.bindPlayerInventory( ip, 0, 184 - /* height of player inventory */82 );
|
2014-03-07 04:02:15 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public void setName( String value )
|
|
|
|
{
|
|
|
|
this.myName = value;
|
|
|
|
}
|
|
|
|
|
2014-03-07 04:02:15 +01:00
|
|
|
@Override
|
|
|
|
public void detectAndSendChanges()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ItemStack currentItem = this.getPlayerInv().getCurrentItem();
|
2014-03-07 04:02:15 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( currentItem != this.toolInv.getItemStack() )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( currentItem != null )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.isSameItem( this.toolInv.getItemStack(), currentItem ) )
|
2014-12-29 15:13:47 +01:00
|
|
|
this.getPlayerInv().setInventorySlotContents( this.getPlayerInv().currentItem, this.toolInv.getItemStack() );
|
2014-03-07 04:02:15 +01:00
|
|
|
else
|
2014-12-29 15:13:47 +01:00
|
|
|
this.isContainerValid = false;
|
2014-03-07 04:02:15 +01:00
|
|
|
}
|
|
|
|
else
|
2014-12-29 15:13:47 +01:00
|
|
|
this.isContainerValid = false;
|
2014-03-07 04:02:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
super.detectAndSendChanges();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void onContainerClosed( EntityPlayer par1EntityPlayer )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.inSlot.getStackInSlot( 0 ) != null )
|
2014-12-29 15:13:47 +01:00
|
|
|
par1EntityPlayer.dropPlayerItemWithRandomChoice( this.inSlot.getStackInSlot( 0 ), false );
|
2014-03-07 04:02:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void saveChanges()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSizeInventory()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public ItemStack getStackInSlot( int var1 )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ItemStack input = this.inSlot.getStackInSlot( 0 );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( input == null )
|
2014-03-07 04:02:15 +01:00
|
|
|
return null;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( SlotRestrictedInput.isMetalIngot( input ) )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.myName.length() > 0 )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack namePressStack : AEApi.instance().definitions().materials().namePress().maybeStack( 1 ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
final NBTTagCompound compound = Platform.openNbtData( namePressStack );
|
|
|
|
compound.setString( "InscribeName", this.myName );
|
|
|
|
|
|
|
|
return namePressStack;
|
|
|
|
}
|
2014-03-07 04:02:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public ItemStack decrStackSize( int var1, int var2 )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ItemStack is = this.getStackInSlot( 0 );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is != null )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.makePlate() )
|
2014-03-07 04:02:15 +01:00
|
|
|
return is;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean makePlate()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.inSlot.decrStackSize( 0, 1 ) != null )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ItemStack item = this.toolInv.getItemStack();
|
|
|
|
item.damageItem( 1, this.getPlayerInv().player );
|
2014-03-07 04:02:15 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( item.stackSize == 0 )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.getPlayerInv().mainInventory[this.getPlayerInv().currentItem] = null;
|
|
|
|
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( this.getPlayerInv().player, item ) );
|
2014-03-07 04:02:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public ItemStack getStackInSlotOnClosing( int var1 )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void setInventorySlotContents( int var1, ItemStack var2 )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( var2 == null && Platform.isServer() )
|
2014-12-29 15:13:47 +01:00
|
|
|
this.makePlate();
|
2014-03-07 04:02:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getInventoryName()
|
|
|
|
{
|
|
|
|
return "Quartz Knife Output";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasCustomInventoryName()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInventoryStackLimit()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markDirty()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean isUseableByPlayer( EntityPlayer var1 )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void openInventory()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void closeInventory()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean isItemValidForSlot( int var1, ItemStack var2 )
|
2014-03-07 04:02:15 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|