Shift clicking work for all existing and implemented container inventories
This commit is contained in:
parent
59929c9c82
commit
3e65a04f1e
10 changed files with 131 additions and 68 deletions
|
@ -79,15 +79,15 @@ public class BlockGlassBell extends BlockEE {
|
|||
return false;
|
||||
else {
|
||||
if (!world.isRemote) {
|
||||
TileGlassBell tileGlassBell = (TileGlassBell) world.getBlockTileEntity(x, y, z);
|
||||
TileAludel tileAludel = (TileAludel) world.getBlockTileEntity(x, y - 1, z);
|
||||
TileEntity tileEntityGlassBell = world.getBlockTileEntity(x, y, z);
|
||||
TileEntity tileEntityAludel = world.getBlockTileEntity(x, y - 1, z);
|
||||
|
||||
if (tileAludel != null && tileGlassBell != null) {
|
||||
if (tileEntityAludel instanceof TileAludel && tileEntityGlassBell instanceof TileGlassBell) {
|
||||
player.openGui(EquivalentExchange3.instance, GuiIds.ALUDEL, world, x, y - 1, z);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (tileGlassBell != null) {
|
||||
if (tileEntityGlassBell != null) {
|
||||
player.openGui(EquivalentExchange3.instance, GuiIds.GLASS_BELL, world, x, y, z);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class TileEntityAludelRenderer extends TileEntitySpecialRenderer {
|
|||
|
||||
TileEntity tileGlassBell = tileAludel.worldObj.getBlockTileEntity(tileAludel.xCoord, tileAludel.yCoord + 1, tileAludel.zCoord);
|
||||
|
||||
if (tileGlassBell != null && tileGlassBell instanceof TileGlassBell) {
|
||||
if (tileGlassBell instanceof TileGlassBell) {
|
||||
if (tileAludel.getStackInSlot(TileAludel.INPUT_INVENTORY_INDEX) != null) {
|
||||
|
||||
float scaleFactor = getGhostItemScaleFactor(tileAludel.getStackInSlot(TileAludel.INPUT_INVENTORY_INDEX));
|
||||
|
|
|
@ -48,7 +48,7 @@ public class TileEntityCalcinatorRenderer extends TileEntitySpecialRenderer {
|
|||
// Render
|
||||
modelCalcinator.renderPart("Calcinator");
|
||||
|
||||
if (tileCalcinator.getStackInSlot(TileCalcinator.DUST_INVENTORY_INDEX) != null) {
|
||||
if (tileCalcinator.getStackInSlot(TileCalcinator.OUTPUT_INVENTORY_INDEX) != null) {
|
||||
modelCalcinator.renderPart("Dust");
|
||||
}
|
||||
|
||||
|
|
|
@ -20,17 +20,23 @@ import com.pahimar.ee3.lib.Strings;
|
|||
*/
|
||||
public class ContainerAlchemicalBag extends Container {
|
||||
|
||||
private final int BAG_INVENTORY_ROWS = 4;
|
||||
private final int BAG_INVENTORY_COLUMNS = 13;
|
||||
|
||||
private final int PLAYER_INVENTORY_ROWS = 3;
|
||||
private final int PLAYER_INVENTORY_COLUMNS = 9;
|
||||
|
||||
public ContainerAlchemicalBag(InventoryPlayer inventoryPlayer) {
|
||||
|
||||
// Add the player's inventory slots to the container
|
||||
for (int inventoryRowIndex = 0; inventoryRowIndex < 3; ++inventoryRowIndex) {
|
||||
for (int inventoryColumnIndex = 0; inventoryColumnIndex < 9; ++inventoryColumnIndex) {
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 44 + inventoryColumnIndex * 18, 104 + inventoryRowIndex * 18));
|
||||
for (int inventoryRowIndex = 0; inventoryRowIndex < PLAYER_INVENTORY_ROWS; ++inventoryRowIndex) {
|
||||
for (int inventoryColumnIndex = 0; inventoryColumnIndex < PLAYER_INVENTORY_COLUMNS; ++inventoryColumnIndex) {
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * PLAYER_INVENTORY_COLUMNS + PLAYER_INVENTORY_COLUMNS, 44 + inventoryColumnIndex * 18, 104 + inventoryRowIndex * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// Add the player's action bar slots to the container
|
||||
for (int actionBarSlotIndex = 0; actionBarSlotIndex < 9; ++actionBarSlotIndex) {
|
||||
for (int actionBarSlotIndex = 0; actionBarSlotIndex < PLAYER_INVENTORY_COLUMNS; ++actionBarSlotIndex) {
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 44 + actionBarSlotIndex * 18, 162));
|
||||
}
|
||||
}
|
||||
|
@ -57,4 +63,32 @@ public class ContainerAlchemicalBag extends Container {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
|
||||
|
||||
ItemStack newItemStack = null;
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack itemStack = slot.getStack();
|
||||
newItemStack = itemStack.copy();
|
||||
|
||||
if (slotIndex < BAG_INVENTORY_ROWS * BAG_INVENTORY_COLUMNS) {
|
||||
if (!this.mergeItemStack(itemStack, BAG_INVENTORY_ROWS * BAG_INVENTORY_COLUMNS, inventorySlots.size(), false))
|
||||
return null;
|
||||
}
|
||||
else if (!this.mergeItemStack(itemStack, 0, BAG_INVENTORY_ROWS * BAG_INVENTORY_COLUMNS, false))
|
||||
return null;
|
||||
|
||||
if (itemStack.stackSize == 0) {
|
||||
slot.putStack((ItemStack) null);
|
||||
}
|
||||
else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return newItemStack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public class ContainerAlchemicalChest extends Container {
|
|||
newItemStack = itemStack.copy();
|
||||
|
||||
if (slotIndex < CHEST_INVENTORY_ROWS * CHEST_INVENTORY_COLUMNS) {
|
||||
if (!this.mergeItemStack(itemStack, CHEST_INVENTORY_ROWS * CHEST_INVENTORY_COLUMNS, inventorySlots.size(), true))
|
||||
if (!this.mergeItemStack(itemStack, CHEST_INVENTORY_ROWS * CHEST_INVENTORY_COLUMNS, inventorySlots.size(), false))
|
||||
return null;
|
||||
}
|
||||
else if (!this.mergeItemStack(itemStack, 0, CHEST_INVENTORY_ROWS * CHEST_INVENTORY_COLUMNS, false))
|
||||
|
|
|
@ -5,7 +5,9 @@ import net.minecraft.entity.player.InventoryPlayer;
|
|||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
|
||||
import com.pahimar.ee3.item.ItemAlchemicalDust;
|
||||
import com.pahimar.ee3.tileentity.TileAludel;
|
||||
|
||||
/**
|
||||
|
@ -24,9 +26,9 @@ public class ContainerAludel extends Container {
|
|||
|
||||
public ContainerAludel(InventoryPlayer inventoryPlayer, TileAludel tileAludel) {
|
||||
|
||||
this.addSlotToContainer(new Slot(tileAludel, TileAludel.FUEL_INVENTORY_INDEX, 44, 74));
|
||||
this.addSlotToContainer(new Slot(tileAludel, TileAludel.INPUT_INVENTORY_INDEX, 44, 18));
|
||||
this.addSlotToContainer(new Slot(tileAludel, TileAludel.DUST_INVENTORY_INDEX, 44, 39));
|
||||
this.addSlotToContainer(new Slot(tileAludel, TileAludel.FUEL_INVENTORY_INDEX, 44, 74));
|
||||
this.addSlotToContainer(new Slot(tileAludel, TileAludel.OUTPUT_INVENTORY_INDEX, 120, 39));
|
||||
|
||||
// Add the player's inventory slots to the container
|
||||
|
@ -54,22 +56,47 @@ public class ContainerAludel extends Container {
|
|||
ItemStack itemStack = null;
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
|
||||
ItemStack slotItemStack = slot.getStack();
|
||||
itemStack = slotItemStack.copy();
|
||||
|
||||
/**
|
||||
* If we are shift-clicking an item out of the Aludel's container, attempt to put it in the first available slot in the
|
||||
* player's inventory
|
||||
*/
|
||||
if (slotIndex < TileAludel.INVENTORY_SIZE) {
|
||||
|
||||
if (!this.mergeItemStack(slotItemStack, TileAludel.INVENTORY_SIZE + 1, inventorySlots.size(), true)) {
|
||||
if (!this.mergeItemStack(slotItemStack, TileAludel.INVENTORY_SIZE, inventorySlots.size(), false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* TODO: Depending on the slowItemStack, attempt to merge it into acceptable slots
|
||||
|
||||
/**
|
||||
* If the stack being shift-clicked into the Aludel's container is a fuel, first try to put it in the fuel slot.
|
||||
* If it cannot be merged into the fuel slot, try to put it in the input slot.
|
||||
*/
|
||||
if (!this.mergeItemStack(slotItemStack, 0, TileAludel.INVENTORY_SIZE - 1, false)) {
|
||||
if (TileEntityFurnace.isItemFuel(slotItemStack)) {
|
||||
if (!this.mergeItemStack(slotItemStack, TileAludel.FUEL_INVENTORY_INDEX, TileAludel.INPUT_INVENTORY_INDEX, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the stack being shift-clicked into the Aludel's container is a dust, first try to put it in the dust slot.
|
||||
* If it cannot be merged into the dust slot, try to put it in the input slot.
|
||||
*/
|
||||
else if (slotItemStack.getItem() instanceof ItemAlchemicalDust) {
|
||||
if (!this.mergeItemStack(slotItemStack, TileAludel.DUST_INVENTORY_INDEX, TileAludel.OUTPUT_INVENTORY_INDEX, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finally, attempt to put stack into the input slot
|
||||
*/
|
||||
else if (!this.mergeItemStack(slotItemStack, TileAludel.INPUT_INVENTORY_INDEX, TileAludel.DUST_INVENTORY_INDEX, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
|
||||
import com.pahimar.ee3.item.ItemAlchemicalDust;
|
||||
import com.pahimar.ee3.tileentity.TileAludel;
|
||||
import com.pahimar.ee3.tileentity.TileCalcinator;
|
||||
|
||||
/**
|
||||
|
@ -23,14 +25,14 @@ public class ContainerCalcinator extends Container {
|
|||
|
||||
public ContainerCalcinator(InventoryPlayer inventoryPlayer, TileCalcinator calcinator) {
|
||||
|
||||
// Add the calcinator "to be calcined" slot to the container
|
||||
this.addSlotToContainer(new Slot(calcinator, 0, 56, 17));
|
||||
// Add the fuel slot to the container
|
||||
this.addSlotToContainer(new Slot(calcinator, TileCalcinator.FUEL_INVENTORY_INDEX, 56, 62));
|
||||
|
||||
// Add the calcinator fuel slot to the container
|
||||
this.addSlotToContainer(new Slot(calcinator, 1, 56, 62));
|
||||
// Add the input slot to the container
|
||||
this.addSlotToContainer(new Slot(calcinator, TileCalcinator.INPUT_INVENTORY_INDEX, 56, 17));
|
||||
|
||||
// Add the calcined results slot to the container
|
||||
this.addSlotToContainer(new SlotCalcinator(calcinator, 2, 116, 35));
|
||||
// Add the output results slot to the container
|
||||
this.addSlotToContainer(new SlotCalcinator(calcinator, TileCalcinator.OUTPUT_INVENTORY_INDEX, 116, 35));
|
||||
|
||||
// Add the player's inventory slots to the container
|
||||
for (int inventoryRowIndex = 0; inventoryRowIndex < 3; ++inventoryRowIndex) {
|
||||
|
@ -51,56 +53,56 @@ public class ContainerCalcinator extends Container {
|
|||
return true;
|
||||
}
|
||||
|
||||
// TODO Write our own version - this is taken from ContainerFurnace
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
|
||||
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
|
||||
|
||||
ItemStack var3 = null;
|
||||
Slot var4 = (Slot) inventorySlots.get(par2);
|
||||
ItemStack itemStack = null;
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
|
||||
if (var4 != null && var4.getHasStack()) {
|
||||
ItemStack var5 = var4.getStack();
|
||||
var3 = var5.copy();
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
|
||||
if (par2 == 2) {
|
||||
if (!this.mergeItemStack(var5, 3, 39, true))
|
||||
ItemStack slotItemStack = slot.getStack();
|
||||
itemStack = slotItemStack.copy();
|
||||
|
||||
/**
|
||||
* If we are shift-clicking an item out of the Aludel's container, attempt to put it in the first available slot in the
|
||||
* player's inventory
|
||||
*/
|
||||
if (slotIndex < TileCalcinator.INVENTORY_SIZE) {
|
||||
|
||||
if (!this.mergeItemStack(slotItemStack, TileCalcinator.INVENTORY_SIZE, inventorySlots.size(), false)) {
|
||||
return null;
|
||||
|
||||
var4.onSlotChange(var5, var3);
|
||||
}
|
||||
else if (par2 != 1 && par2 != 0) {
|
||||
if (FurnaceRecipes.smelting().getSmeltingResult(var5) != null) {
|
||||
if (!this.mergeItemStack(var5, 0, 1, false))
|
||||
return null;
|
||||
}
|
||||
else if (TileEntityFurnace.isItemFuel(var5)) {
|
||||
if (!this.mergeItemStack(var5, 1, 2, false))
|
||||
return null;
|
||||
}
|
||||
else if (par2 >= 3 && par2 < 30) {
|
||||
if (!this.mergeItemStack(var5, 30, 39, false))
|
||||
return null;
|
||||
}
|
||||
else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(var5, 3, 30, false))
|
||||
return null;
|
||||
}
|
||||
else if (!this.mergeItemStack(var5, 3, 39, false))
|
||||
return null;
|
||||
|
||||
if (var5.stackSize == 0) {
|
||||
var4.putStack((ItemStack) null);
|
||||
}
|
||||
else {
|
||||
var4.onSlotChanged();
|
||||
|
||||
/**
|
||||
* If the stack being shift-clicked into the Aludel's container is a fuel, first try to put it in the fuel slot.
|
||||
* If it cannot be merged into the fuel slot, try to put it in the input slot.
|
||||
*/
|
||||
if (TileEntityFurnace.isItemFuel(slotItemStack)) {
|
||||
if (!this.mergeItemStack(slotItemStack, TileCalcinator.FUEL_INVENTORY_INDEX, TileCalcinator.OUTPUT_INVENTORY_INDEX, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finally, attempt to put stack into the input slot
|
||||
*/
|
||||
else if (!this.mergeItemStack(slotItemStack, TileCalcinator.INPUT_INVENTORY_INDEX, TileCalcinator.OUTPUT_INVENTORY_INDEX, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (var5.stackSize == var3.stackSize)
|
||||
return null;
|
||||
|
||||
var4.onPickupFromSlot(par1EntityPlayer, var5);
|
||||
if (slotItemStack.stackSize == 0) {
|
||||
slot.putStack((ItemStack) null);
|
||||
}
|
||||
else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return var3;
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class ContainerGlassBell extends Container {
|
|||
|
||||
public ContainerGlassBell(InventoryPlayer inventoryPlayer, TileGlassBell tileGlassBell) {
|
||||
|
||||
this.addSlotToContainer(new Slot(tileGlassBell, TileAludel.INPUT_INVENTORY_INDEX, 80, 22));
|
||||
this.addSlotToContainer(new Slot(tileGlassBell, TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX, 80, 22));
|
||||
|
||||
// Add the player's inventory slots to the container
|
||||
for (int inventoryRowIndex = 0; inventoryRowIndex < PLAYER_INVENTORY_ROWS; ++inventoryRowIndex) {
|
||||
|
|
|
@ -29,9 +29,9 @@ public class TileAludel extends TileEE implements IInventory {
|
|||
|
||||
public static final int INVENTORY_SIZE = 4;
|
||||
|
||||
public static final int INPUT_INVENTORY_INDEX = 0;
|
||||
public static final int DUST_INVENTORY_INDEX = 1;
|
||||
public static final int FUEL_INVENTORY_INDEX = 2;
|
||||
public static final int FUEL_INVENTORY_INDEX = 0;
|
||||
public static final int INPUT_INVENTORY_INDEX = 1;
|
||||
public static final int DUST_INVENTORY_INDEX = 2;
|
||||
public static final int OUTPUT_INVENTORY_INDEX = 3;
|
||||
|
||||
public TileAludel() {
|
||||
|
|
|
@ -27,7 +27,7 @@ public class TileCalcinator extends TileEE implements IInventory {
|
|||
|
||||
public static final int FUEL_INVENTORY_INDEX = 0;
|
||||
public static final int INPUT_INVENTORY_INDEX = 1;
|
||||
public static final int DUST_INVENTORY_INDEX = 2;
|
||||
public static final int OUTPUT_INVENTORY_INDEX = 2;
|
||||
|
||||
public TileCalcinator() {
|
||||
|
||||
|
|
Loading…
Reference in a new issue