Skip to content

Instantly share code, notes, and snippets.

Created July 6, 2014 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c1e8a7fcc68d4ccf81bc to your computer and use it in GitHub Desktop.
Save anonymous/c1e8a7fcc68d4ccf81bc to your computer and use it in GitHub Desktop.
Container problems...
package com.kwibble.dendri.inventory.dendrikbelt;
import com.kwibble.dendri.entity.player.PlayerInformation;
import com.kwibble.dendri.inventory.SlotDendrikBelt;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* Created by Kwibble on 2/07/14.
*/
public class ContainerTabMain extends Container
{
private static final int INV_START = 5, INV_END = INV_START+26,
HOTBAR_START = INV_END+1, HOTBAR_END = HOTBAR_START+8;
public ContainerTabMain(EntityPlayer player, final InventoryPlayer playerInventory)
{
PlayerInformation playerinfo = PlayerInformation.forPlayer(player);
playerinfo.setInventoryDendrikBelt(new InventoryDendrikBelt(player));
InventoryDendrikBelt beltInventory = playerinfo.getInventoryDendrikBelt();
int i, j;
this.addSlotToContainer(new SlotDendrikBelt(beltInventory, 0, 62, 8)).putStack(new ItemStack(playerinfo.getCurrentDendrikBelt()));
for (i = 0; i < beltInventory.INV_SIZE; ++i)
{
int x = 27;
int y = 0;
if (i > 0)
{
x = 28;
y = 1;
}
this.addSlotToContainer(new SlotMistBottle(beltInventory, 1 + i, 68 + (i * x) - y, 45));
}
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(playerInventory, (j + (i + 1) * 9), 8 + j * 18, 84 + i * 18));
}
}
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(playerInventory, i, 8 + i * 18, 142));
}
}
@Override
public boolean canInteractWith(EntityPlayer var1)
{
return true;
}
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slot_position)
{
// Setup Variables
ItemStack stack_return = null;
// Get Current Slot
Slot slot = (Slot)this.inventorySlots.get(slot_position);
// Check to see if slot exists and if it has an item
if (slot != null && slot.getHasStack())
{
// Get Current itemstack
ItemStack stack_active = slot.getStack();
// Put is stack memory
stack_return = stack_active.copy();
// if (stack_return.getItem() instanceof ItemDendrikBelt && !( (Slot) this.inventorySlots.get(0) ).getHasStack())
// {
// // Check for spot
// if (!this.mergeItemStack(stack_active, 0, 1, false))
// {
// return null;
// }
//// // Test for mist bottles
// } else if (stack_return.getItem() instanceof ItemMistBottle && slot_position >= 1 && slot_position < INV_START) {
// // Check for spot
// if (!this.mergeItemStack(stack_active, 1, 5, false))
// {
// return null;
// }
// // Test for main inventory
if (slot_position >= INV_START && slot_position < INV_END + 1) {
if (!this.mergeItemStack(stack_active, HOTBAR_START, HOTBAR_END, false)) {
return null;
}
// Test for main bar
}
else if (slot_position >= HOTBAR_START && slot_position < HOTBAR_END + 1) {
if (!this.mergeItemStack(stack_active, INV_START, INV_END, false)) {
return null;
}
// Try and just combine in inventory
} else if (!this.mergeItemStack(stack_active, INV_START, HOTBAR_END, false)) {
return null;
}
// Check for zero size
if (stack_active.stackSize == 0) {
// Correct it to null
slot.putStack(null);
} else {
// Notify of Change
slot.onSlotChanged();
}
// Check for no change
if (stack_active.stackSize == stack_return.stackSize) {
return null;
}
// Notify that picking it up
slot.onPickupFromSlot(par1EntityPlayer, stack_active);
}
// Return what is left
return stack_return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment