2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs.containers;
|
|
|
|
|
|
2023-01-12 21:33:06 -05:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.entity.IMerchant;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.inventory.ICrafting;
|
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
|
import net.minecraft.inventory.InventoryBasic;
|
|
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public class ContainerMerchantAdd extends ContainerNpcInterface {
|
|
|
|
|
/**
|
|
|
|
|
* Instance of Merchant.
|
|
|
|
|
*/
|
2018-09-13 12:03:28 -04:00
|
|
|
private IMerchant theMerchant;
|
|
|
|
|
private InventoryBasic merchantInventory;
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
/**
|
|
|
|
|
* Instance of World.
|
|
|
|
|
*/
|
2018-09-13 12:03:28 -04:00
|
|
|
private final World theWorld;
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public ContainerMerchantAdd(EntityPlayer player, IMerchant par2IMerchant, World par3World) {
|
|
|
|
|
super(player);
|
2018-09-13 12:03:28 -04:00
|
|
|
this.theMerchant = par2IMerchant;
|
|
|
|
|
this.theWorld = par3World;
|
2025-03-13 17:14:45 -04:00
|
|
|
this.merchantInventory = new InventoryBasic("", false, 3);
|
2018-09-13 12:03:28 -04:00
|
|
|
this.addSlotToContainer(new Slot(this.merchantInventory, 0, 36, 53));
|
|
|
|
|
this.addSlotToContainer(new Slot(this.merchantInventory, 1, 62, 53));
|
|
|
|
|
this.addSlotToContainer(new Slot(this.merchantInventory, 2, 120, 53));
|
|
|
|
|
int i;
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
for (i = 0; i < 3; ++i) {
|
|
|
|
|
for (int j = 0; j < 9; ++j) {
|
2018-09-13 12:03:28 -04:00
|
|
|
this.addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
for (i = 0; i < 9; ++i) {
|
2018-09-13 12:03:28 -04:00
|
|
|
this.addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 142));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public void addCraftingToCrafters(ICrafting par1ICrafting) {
|
2018-09-13 12:03:28 -04:00
|
|
|
super.addCraftingToCrafters(par1ICrafting);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Looks for changes made in the container, sends them to every listener.
|
|
|
|
|
*/
|
2025-03-13 17:14:45 -04:00
|
|
|
public void detectAndSendChanges() {
|
2018-09-13 12:03:28 -04:00
|
|
|
super.detectAndSendChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Callback for when the crafting matrix is changed.
|
|
|
|
|
*/
|
2025-03-13 17:14:45 -04:00
|
|
|
public void onCraftMatrixChanged(IInventory par1IInventory) {
|
2018-09-13 12:03:28 -04:00
|
|
|
//this.merchantInventory.resetRecipeAndSlots();
|
|
|
|
|
super.onCraftMatrixChanged(par1IInventory);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public void setCurrentRecipeIndex(int par1) {
|
2018-09-13 12:03:28 -04:00
|
|
|
//this.merchantInventory.setCurrentRecipeIndex(par1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2025-03-13 17:14:45 -04:00
|
|
|
public void updateProgressBar(int par1, int par2) {
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
|
|
|
|
|
*/
|
2025-03-13 17:14:45 -04:00
|
|
|
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
|
2018-09-13 12:03:28 -04:00
|
|
|
ItemStack itemstack = null;
|
2025-03-13 17:14:45 -04:00
|
|
|
Slot slot = (Slot) this.inventorySlots.get(par2);
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (slot != null && slot.getHasStack()) {
|
2018-09-13 12:03:28 -04:00
|
|
|
ItemStack itemstack1 = slot.getStack();
|
|
|
|
|
itemstack = itemstack1.copy();
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (par2 != 0 && par2 != 1 && par2 != 2) {
|
|
|
|
|
if (par2 >= 3 && par2 < 30) {
|
|
|
|
|
if (!this.mergeItemStack(itemstack1, 30, 39, false)) {
|
2018-09-13 12:03:28 -04:00
|
|
|
return null;
|
|
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
} else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false)) {
|
2018-09-13 12:03:28 -04:00
|
|
|
return null;
|
|
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
} else if (!this.mergeItemStack(itemstack1, 3, 39, false)) {
|
2018-09-13 12:03:28 -04:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (itemstack1.stackSize == 0) {
|
|
|
|
|
slot.putStack((ItemStack) null);
|
|
|
|
|
} else {
|
2018-09-13 12:03:28 -04:00
|
|
|
slot.onSlotChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (itemstack1.stackSize == itemstack.stackSize) {
|
2018-09-13 12:03:28 -04:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return itemstack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when the container is closed.
|
|
|
|
|
*/
|
2025-03-13 17:14:45 -04:00
|
|
|
public void onContainerClosed(EntityPlayer par1EntityPlayer) {
|
2018-09-13 12:03:28 -04:00
|
|
|
super.onContainerClosed(par1EntityPlayer);
|
2025-03-13 17:14:45 -04:00
|
|
|
this.theMerchant.setCustomer((EntityPlayer) null);
|
2018-09-13 12:03:28 -04:00
|
|
|
super.onContainerClosed(par1EntityPlayer);
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (!this.theWorld.isRemote) {
|
2018-09-13 12:03:28 -04:00
|
|
|
ItemStack itemstack = this.merchantInventory.getStackInSlotOnClosing(0);
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (itemstack != null) {
|
2018-09-13 12:03:28 -04:00
|
|
|
par1EntityPlayer.dropPlayerItemWithRandomChoice(itemstack, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
itemstack = this.merchantInventory.getStackInSlotOnClosing(1);
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (itemstack != null) {
|
2018-09-13 12:03:28 -04:00
|
|
|
par1EntityPlayer.dropPlayerItemWithRandomChoice(itemstack, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|