Unified inventory interaction actions

This commit is contained in:
Calclavia 2014-01-17 20:19:52 +08:00
parent 3a04133f96
commit f18837cb9f
4 changed files with 42 additions and 73 deletions

View file

@ -2,14 +2,14 @@ package resonantinduction.archaic;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import resonantinduction.archaic.blocks.BlockFirebox;
import resonantinduction.archaic.blocks.BlockTurntable;
import resonantinduction.archaic.blocks.TileFirebox;
import resonantinduction.archaic.crate.BlockCrate;
import resonantinduction.archaic.crate.ItemBlockCrate;
import resonantinduction.archaic.crate.TileCrate;
import resonantinduction.archaic.engineering.BlockEngineeringTable;
import resonantinduction.archaic.engineering.TileEngineeringTable;
import resonantinduction.archaic.firebox.BlockFirebox;
import resonantinduction.archaic.firebox.TileFirebox;
import resonantinduction.archaic.imprint.BlockImprinter;
import resonantinduction.archaic.imprint.ItemBlockImprint;
import resonantinduction.archaic.imprint.TileImprinter;

View file

@ -132,55 +132,7 @@ public class BlockEngineeringTable extends BlockRI
if (check.distance(hitVector) < regionLength)
{
int slotID = j * 3 + k;
boolean didInsert = false;
ItemStack checkStack = tile.craftingMatrix[slotID];
if (current != null)
{
if (checkStack == null || checkStack.isItemEqual(current))
{
if (ControlKeyModifer.isControlDown(player))
{
if (checkStack == null)
{
tile.craftingMatrix[slotID] = current;
}
else
{
tile.craftingMatrix[slotID].stackSize += current.stackSize;
current.stackSize = 0;
}
current = null;
}
else
{
if (checkStack == null)
{
tile.craftingMatrix[slotID] = current.splitStack(1);
}
else
{
tile.craftingMatrix[slotID].stackSize++;
current.stackSize--;
}
}
if (current == null || current.stackSize <= 0)
{
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
didInsert = true;
}
}
if (!didInsert && checkStack != null)
{
InventoryUtility.dropItemStack(world, new Vector3(player), checkStack, 0);
tile.craftingMatrix[slotID] = null;
}
interactCurrentItem(tile, slotID, player);
break matrix;
}
}
@ -252,6 +204,12 @@ public class BlockEngineeringTable extends BlockRI
this.iconFront = par1IconRegister.registerIcon(this.getTextureName() + "_front");
}
@Override
public boolean isControlDown(EntityPlayer player)
{
return ControlKeyModifer.isControlDown(player);
}
@Override
public TileEntity createNewTileEntity(World world)
{

View file

@ -1,7 +1,8 @@
package resonantinduction.archaic.blocks;
package resonantinduction.archaic.firebox;
import java.util.Random;
import codechicken.multipart.ControlKeyModifer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
@ -37,29 +38,26 @@ public class BlockFirebox extends BlockRI
}
@Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileFirebox)
{
TileFirebox tile = (TileFirebox) tileEntity;
extractItem(tile, 0, player);
}
}
if (tile.getStackInSlot(0) == null)
{
if (tile.canBurn(entityPlayer.inventory.getCurrentItem()))
{
tile.setInventorySlotContents(0, entityPlayer.inventory.getCurrentItem());
entityPlayer.inventory.setInventorySlotContents(entityPlayer.inventory.currentItem, null);
return true;
}
}
else
{
InventoryUtility.dropItemStack(world, new Vector3(entityPlayer), tile.getStackInSlot(0));
tile.setInventorySlotContents(0, null);
return true;
}
@Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileFirebox)
{
TileFirebox tile = (TileFirebox) tileEntity;
return interactCurrentItem(tile, 0, player);
}
return false;
@ -128,6 +126,12 @@ public class BlockFirebox extends BlockRI
}
}
@Override
public boolean isControlDown(EntityPlayer player)
{
return ControlKeyModifer.isControlDown(player);
}
@Override
public TileEntity createNewTileEntity(World world)
{

View file

@ -1,4 +1,4 @@
package resonantinduction.archaic.blocks;
package resonantinduction.archaic.firebox;
import java.util.ArrayList;
@ -51,13 +51,14 @@ public class TileFirebox extends TileExternalInventory implements IPacketSender,
if (burnTime-- == 0)
{
if (blockID == Block.fire.blockID)
{
worldObj.setBlock(xCoord, yCoord + 1, zCoord, 0);
}
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
else if (blockID == Block.fire.blockID)
{
worldObj.setBlock(xCoord, yCoord + 1, zCoord, 0);
}
if (canBurn(this.getStackInSlot(0)))
{
@ -81,6 +82,12 @@ public class TileFirebox extends TileExternalInventory implements IPacketSender,
return burnTime > 0;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemStack)
{
return i == 0 && canBurn(itemStack);
}
@Override
public Packet getDescriptionPacket()
{