public ContainerAmadron(EntityPlayer player) { super(null); for (int y = 0; y < ROWS; y++) { for (int x = 0; x < 2; x++) { addSlotToContainer(new SlotUntouchable(inv, y * 4 + x * 2, x * 73 + 12, y * 35 + 70)); addSlotToContainer(new SlotUntouchable(inv, y * 4 + x * 2 + 1, x * 73 + 57, y * 35 + 70)); } } addSyncedFields(this); Arrays.fill(shoppingItems, -1); if (!player.worldObj.isRemote) { IInventory inv = ItemAmadronTablet.getItemProvider(player.getCurrentEquippedItem()); IFluidHandler fluidHandler = ItemAmadronTablet.getLiquidProvider(player.getCurrentEquippedItem()); for (int i = 0; i < offers.size(); i++) { int amount = capShoppingAmount(i, 1, inv, fluidHandler); buyableOffers[i] = amount > 0; } problemState = EnumProblemState.NO_PROBLEMS; Map<AmadronOffer, Integer> shoppingCart = ItemAmadronTablet.getShoppingCart(player.getCurrentEquippedItem()); for (Map.Entry<AmadronOffer, Integer> cartItem : shoppingCart.entrySet()) { int offerId = offers.indexOf(cartItem.getKey()); if (offerId >= 0) { int index = getCartSlot(offerId); if (index >= 0) { shoppingItems[index] = offerId; shoppingAmounts[index] = cartItem.getValue(); } } } } }
@Override public void onContainerClosed(EntityPlayer player) { super.onContainerClosed(player); if (!player.worldObj.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Itemss.amadronTablet) { Map<AmadronOffer, Integer> shoppingCart = new HashMap<AmadronOffer, Integer>(); for (int i = 0; i < shoppingItems.length; i++) { if (shoppingItems[i] >= 0) { shoppingCart.put(offers.get(shoppingItems[i]), shoppingAmounts[i]); } } ItemAmadronTablet.setShoppingCart(player.getCurrentEquippedItem(), shoppingCart); } }
public int capShoppingAmount(int offerId, int wantedAmount, EntityPlayer player) { IInventory inv = ItemAmadronTablet.getItemProvider(player.getCurrentEquippedItem()); IFluidHandler fluidHandler = ItemAmadronTablet.getLiquidProvider(player.getCurrentEquippedItem()); return capShoppingAmount(offerId, wantedAmount, inv, fluidHandler); }
@Override public void handleGUIButtonPress(int guiID, EntityPlayer player) { super.handleGUIButtonPress(guiID, player); if (guiID == 1) { for (int i = 0; i < shoppingItems.length; i++) { if (shoppingItems[i] >= 0) { AmadronOffer offer = offers.get(shoppingItems[i]); if (offer.getInput() instanceof ItemStack) { ItemStack queryingItems = (ItemStack) offer.getInput(); int amount = queryingItems.stackSize * shoppingAmounts[i]; List<ItemStack> stacks = new ArrayList<ItemStack>(); while (amount > 0) { ItemStack stack = queryingItems.copy(); stack.stackSize = Math.min(amount, stack.getMaxStackSize()); stacks.add(stack); amount -= stack.stackSize; } ChunkPosition pos = ItemAmadronTablet.getItemProvidingLocation(player.getCurrentEquippedItem()); World world = null; if (pos == null) { pos = new ChunkPosition((int) player.posX, (int) player.posY, (int) player.posZ); world = player.worldObj; } else { world = ItemAmadronTablet.getWorldForDimension( ItemAmadronTablet.getItemProvidingDimension(player.getCurrentEquippedItem())); } EntityDrone drone = (EntityDrone) PneumaticRegistry.getInstance() .retrieveItemsAmazonStyle( world, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, stacks.toArray(new ItemStack[stacks.size()])); drone.setHandlingOffer(offer, shoppingAmounts[i], player.getCurrentEquippedItem()); } else { FluidStack queryingFluid = ((FluidStack) offer.getInput()).copy(); queryingFluid.amount *= shoppingAmounts[i]; ChunkPosition pos = ItemAmadronTablet.getLiquidProvidingLocation(player.getCurrentEquippedItem()); if (pos != null) { World world = ItemAmadronTablet.getWorldForDimension( ItemAmadronTablet.getLiquidProvidingDimension( player.getCurrentEquippedItem())); EntityDrone drone = (EntityDrone) PneumaticRegistry.getInstance() .retrieveFluidAmazonStyle( world, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, queryingFluid); drone.setHandlingOffer(offer, shoppingAmounts[i], player.getCurrentEquippedItem()); } } } } Arrays.fill(shoppingAmounts, 0); Arrays.fill(shoppingItems, -1); } else if (guiID == 2) { player.openGui( PneumaticCraft.instance, CommonProxy.EnumGuiId.AMADRON_ADD_TRADE.ordinal(), player.worldObj, 0, 0, 0); } }